refactor: scopes prefix includes a /scopes/ part before ID
This commit is contained in:
3 files changed
+16
-16
No files matched your search
@@ -74,7 +74,7 @@ export default class ApplicationAdapter extends RESTAdapter.extend(
|
||||
let scopePath = getWithDefault(snapshot, 'adapterOptions.scopeID', '');
|
||||
// Ensure a slash is added between prefix + scope path if needed.
|
||||
if (scopePath && prefix.charAt(prefix.length - 1) !== '/') {
|
||||
scopePath = `/${scopePath}`;
|
||||
scopePath = `/scopes/${scopePath}`;
|
||||
}
|
||||
return `${prefix}${scopePath}`;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ module('Unit | Adapter | application', function (hooks) {
|
||||
adapterOptions: {scopeID}
|
||||
});
|
||||
assert.ok(config.api.namespace);
|
||||
assert.equal(prefix, `v1/${scopeID}`);
|
||||
assert.equal(prefix, `v1/scopes/${scopeID}`);
|
||||
});
|
||||
|
||||
test('it generates correct default URL suffixes', function (assert) {
|
||||
@@ -65,23 +65,23 @@ module('Unit | Adapter | application', function (hooks) {
|
||||
const adapter = this.owner.lookup('adapter:application');
|
||||
// test URL generation for each request type...
|
||||
const findRecordURL = adapter.buildURL('user', '1', mockSnapshot, 'findRecord');
|
||||
assert.equal(findRecordURL, '/v1/o_1/users/1:my-custom-method');
|
||||
assert.equal(findRecordURL, '/v1/scopes/o_1/users/1:my-custom-method');
|
||||
const findAllURL = adapter.buildURL('user', null, mockSnapshot, 'findAll');
|
||||
assert.equal(findAllURL, '/v1/o_1/users:my-custom-method');
|
||||
assert.equal(findAllURL, '/v1/scopes/o_1/users:my-custom-method');
|
||||
const findBelongsToURL = adapter.buildURL('user', '2', mockSnapshot, 'findBelongsTo');
|
||||
assert.equal(findBelongsToURL, '/v1/o_1/users/2:my-custom-method');
|
||||
assert.equal(findBelongsToURL, '/v1/scopes/o_1/users/2:my-custom-method');
|
||||
const createRecordURL = adapter.buildURL('user', null, mockSnapshot, 'createRecord');
|
||||
assert.equal(createRecordURL, '/v1/o_1/users:my-custom-method');
|
||||
assert.equal(createRecordURL, '/v1/scopes/o_1/users:my-custom-method');
|
||||
const updateRecordURL = adapter.buildURL('user', '3', mockSnapshot, 'updateRecord');
|
||||
assert.equal(updateRecordURL, '/v1/o_1/users/3:my-custom-method');
|
||||
assert.equal(updateRecordURL, '/v1/scopes/o_1/users/3:my-custom-method');
|
||||
const deleteRecordURL = adapter.buildURL('user', '4', mockSnapshot, 'deleteRecord');
|
||||
assert.equal(deleteRecordURL, '/v1/o_1/users/4:my-custom-method');
|
||||
assert.equal(deleteRecordURL, '/v1/scopes/o_1/users/4:my-custom-method');
|
||||
});
|
||||
|
||||
test('it can request records through the store from a specified scope', async function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
this.server.get('/v1/p_456/groups', () => {
|
||||
this.server.get('/v1/scopes/p_456/groups', () => {
|
||||
assert.ok(true, 'Scoped resource URL was requested.');
|
||||
return {items: []};
|
||||
});
|
||||
|
||||
@@ -97,17 +97,17 @@ module('Unit | Model | base', function (hooks) {
|
||||
assert.expect(3);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const model = store.createRecord('user', { scopeID: 'o_123' });
|
||||
this.server.post('/v1/o_123/users', () => {
|
||||
this.server.post('/v1/scopes/o_123/users', () => {
|
||||
assert.ok(true, 'Correctly scoped create record URL was requested.')
|
||||
return {};
|
||||
});
|
||||
await model.save();
|
||||
this.server.patch('/v1/o_123/users', () => {
|
||||
this.server.patch('/v1/scopes/o_123/users', () => {
|
||||
assert.ok(true, 'Correctly scoped update record URL was requested.')
|
||||
return {};
|
||||
});
|
||||
await model.save();
|
||||
this.server.delete('/v1/o_123/users', () => {
|
||||
this.server.delete('/v1/scopes/o_123/users', () => {
|
||||
assert.ok(true, 'Correctly scoped delete record URL was requested.')
|
||||
return {};
|
||||
});
|
||||
@@ -120,17 +120,17 @@ module('Unit | Model | base', function (hooks) {
|
||||
const customScopeID = 'global';
|
||||
const scope = {scope_id: 'o_123'};
|
||||
const model = store.createRecord('user', { scope });
|
||||
this.server.post('/v1/global/users', () => {
|
||||
this.server.post('/v1/scopes/global/users', () => {
|
||||
assert.ok(true, 'Correctly scoped create record URL was requested.')
|
||||
return {};
|
||||
});
|
||||
await model.save({adapterOptions: {scopeID: customScopeID}});
|
||||
this.server.patch('/v1/global/users', () => {
|
||||
this.server.patch('/v1/scopes/global/users', () => {
|
||||
assert.ok(true, 'Correctly scoped update record URL was requested.')
|
||||
return {};
|
||||
});
|
||||
await model.save({adapterOptions: {scopeID: customScopeID}});
|
||||
this.server.delete('/v1/global/users', () => {
|
||||
this.server.delete('/v1/scopes/global/users', () => {
|
||||
assert.ok(true, 'Correctly scoped delete record URL was requested.')
|
||||
return {};
|
||||
});
|
||||
@@ -143,7 +143,7 @@ module('Unit | Model | base', function (hooks) {
|
||||
const method = 'my-custom-method';
|
||||
const scope = {scope_id: 'o_123'};
|
||||
const model = store.createRecord('user', { scope });
|
||||
this.server.post(`/v1/o_123/users:${method}`, () => {
|
||||
this.server.post(`/v1/scopes/o_123/users:${method}`, () => {
|
||||
assert.ok(true, 'Correctly scoped create record URL was requested.')
|
||||
return {};
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user