refactor: 💡 implement new pathing for groups
This commit is contained in:
17 files changed
+75
-36
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import ApplicationAdapter from './application';
|
||||
|
||||
export default class GroupAdapter extends ApplicationAdapter {
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Groups use the new, unprefixed pathing style.
|
||||
* @override
|
||||
*/
|
||||
hasScopePrefix = false;
|
||||
|
||||
}
|
||||
@@ -2,6 +2,14 @@ import ApplicationSerializer from './application';
|
||||
|
||||
export default class GroupSerializer extends ApplicationSerializer {
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Serialized the scope ID into the `scope_id` field.
|
||||
* @type {boolean}
|
||||
*/
|
||||
serializeScopeID = true;
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'api/adapters/group';
|
||||
@@ -93,13 +93,11 @@ module('Unit | Adapter | application', function (hooks) {
|
||||
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/scopes/p_456/groups', () => {
|
||||
assert.ok(true, 'Scoped resource URL was requested.');
|
||||
this.server.get('/v1/groups', (_, { queryParams: { scope_id }}) => {
|
||||
assert.equal(scope_id, 'p_456', 'Scoped resource URL was requested.');
|
||||
return {items: []};
|
||||
});
|
||||
await store.findAll('group', {
|
||||
adapterOptions: { scopeID: 'p_456' }
|
||||
});
|
||||
await store.query('group', { scope_id: 'p_456' });
|
||||
});
|
||||
|
||||
test('it rewrites PUT to PATCH, but leaves others unchanged', function (assert) {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Adapter | group', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
let adapter = this.owner.lookup('adapter:group');
|
||||
assert.ok(adapter);
|
||||
});
|
||||
});
|
||||
@@ -43,7 +43,7 @@ module('Unit | Model | group', function(hooks) {
|
||||
|
||||
test('it has an `addMembers` method that groups a specific POST API endpoint and serialization', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/v1/scopes/o_1/groups/123abc:add-members', (schema, request) => {
|
||||
this.server.post('/v1/groups/123abc:add-members', (schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
member_ids: ['123_abc', 'foobar'],
|
||||
@@ -73,7 +73,7 @@ module('Unit | Model | group', function(hooks) {
|
||||
|
||||
test('it has a `removeMembers` method that groups a specific POST API endpoint and serialization', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/v1/scopes/o_1/groups/123abc:remove-members', (schema, request) => {
|
||||
this.server.post('/v1/groups/123abc:remove-members', (schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
member_ids: ['1', '3'],
|
||||
@@ -103,7 +103,7 @@ module('Unit | Model | group', function(hooks) {
|
||||
|
||||
test('it has a `removeMember` method that deletes a single member set using `removeMembers` method', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/v1/scopes/o_1/groups/123abc:remove-members', (schema, request) => {
|
||||
this.server.post('/v1/groups/123abc:remove-members', (schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
member_ids: ['3'],
|
||||
|
||||
Reference in new issue
Block a user