Files
threshold-ui/addons/api/tests/unit/mixins/adapter-build-url-test.js
T

59 lines
2.1 KiB
JavaScript
Raw Normal View History

import RESTAdapter from '@ember-data/adapter/rest';
2020-10-06 10:31:00 -04:00
/* eslint-disable-next-line ember/no-mixins */
import AdapterBuildURLMixin from 'api/mixins/adapter-build-url';
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
2020-09-16 14:29:02 -04:00
module('Unit | Mixin | build-url', function (hooks) {
setupTest(hooks);
test('it does not interfere with basic URLs', function (assert) {
assert.expect(1);
2020-10-06 10:31:00 -04:00
/* eslint-disable-next-line ember/no-new-mixins */
const Adapter = RESTAdapter.extend(AdapterBuildURLMixin);
this.owner.register('adapter:adapter', Adapter);
const adapter = this.owner.lookup('adapter:adapter');
const url = adapter._buildURL('model', 1);
assert.equal(url, '/models/1');
});
test('it does not interfere with namespaced URLs', function (assert) {
assert.expect(1);
2020-10-06 10:31:00 -04:00
/* eslint-disable-next-line ember/no-new-mixins */
const Adapter = RESTAdapter.extend(AdapterBuildURLMixin, {
2020-09-16 14:29:02 -04:00
namespace: 'api/v1',
});
this.owner.register('adapter:adapter', Adapter);
const adapter = this.owner.lookup('adapter:adapter');
const url = adapter._buildURL('model', 1);
assert.equal(url, '/api/v1/models/1');
});
test('it can prepend a prefix', function (assert) {
assert.expect(1);
2020-10-06 10:31:00 -04:00
/* eslint-disable-next-line ember/no-new-mixins */
const Adapter = RESTAdapter.extend(AdapterBuildURLMixin, {
urlPrefix() {
2020-09-16 14:29:02 -04:00
return '/foo/bars';
},
});
this.owner.register('adapter:adapter', Adapter);
const adapter = this.owner.lookup('adapter:adapter');
const url = adapter._buildURL('model', 1);
assert.equal(url, '/foo/bars/models/1');
});
test('it can append a suffix', function (assert) {
assert.expect(1);
2020-10-06 10:31:00 -04:00
/* eslint-disable-next-line ember/no-new-mixins */
const Adapter = RESTAdapter.extend(AdapterBuildURLMixin, {
urlSuffix() {
2020-09-16 14:29:02 -04:00
return ':method';
},
});
this.owner.register('adapter:adapter', Adapter);
const adapter = this.owner.lookup('adapter:adapter');
const url = adapter._buildURL('model', 1);
assert.equal(url, '/models/1:method');
});
});