refactor: 💡 implement new pathing for users

This commit is contained in:
Randall Morey committed 2020-09-09 16:53:41 -04:00
1 parent e80708eeb4
commit 4a63c6484f
17 files changed
+154 -78

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
import ApplicationAdapter from './application';
export default class UserAdapter extends ApplicationAdapter {
// =attributes
/**
* Users use the new, unprefixed pathing style.
* @override
*/
hasScopePrefix = false;
}
+13
View File
@@ -0,0 +1,13 @@
import ApplicationSerializer from './application';
export default class UserSerializer extends ApplicationSerializer {
// =attributes
/**
* Serialized the scope ID into the `scope_id` field.
* @type {boolean}
*/
serializeScopeID = true;
}
+1
View File
@@ -0,0 +1 @@
export { default } from 'api/adapters/user';
+1
View File
@@ -0,0 +1 @@
export { default } from 'api/serializers/user';
@@ -0,0 +1,12 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Adapter | user', function(hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function(assert) {
let adapter = this.owner.lookup('adapter:user');
assert.ok(adapter);
});
});
+7 -7
View File
@@ -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/scopes/o_123/users', () => {
this.server.post('/v1/users', () => {
assert.ok(true, 'Correctly scoped create record URL was requested.')
return {};
});
await model.save();
this.server.patch('/v1/scopes/o_123/users', () => {
this.server.patch('/v1/users', () => {
assert.ok(true, 'Correctly scoped update record URL was requested.')
return {};
});
await model.save();
this.server.delete('/v1/scopes/o_123/users', () => {
this.server.delete('/v1/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/scopes/global/users', () => {
this.server.post('/v1/users', () => {
assert.ok(true, 'Correctly scoped create record URL was requested.')
return {};
});
await model.save({adapterOptions: {scopeID: customScopeID}});
this.server.patch('/v1/scopes/global/users', () => {
this.server.patch('/v1/users', () => {
assert.ok(true, 'Correctly scoped update record URL was requested.')
return {};
});
await model.save({adapterOptions: {scopeID: customScopeID}});
this.server.delete('/v1/scopes/global/users', () => {
this.server.delete('/v1/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/scopes/o_123/users:${method}`, () => {
this.server.post(`/v1/users:${method}`, () => {
assert.ok(true, 'Correctly scoped create record URL was requested.')
return {};
});
@@ -25,7 +25,8 @@ module('Unit | Serializer | application', function (hooks) {
const serializedRecord = record.serialize();
assert.deepEqual(serializedRecord, {
name: 'User',
description: 'Description'
description: 'Description',
scope_id: 'global'
});
});
@@ -33,6 +34,7 @@ module('Unit | Serializer | application', function (hooks) {
assert.expect(2);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('user');
serializer.serializeScopeID = false;
const record = store.createRecord('user', {
name: 'User',
description: 'Description',
@@ -0,0 +1,23 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Serializer | user', function(hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function(assert) {
let store = this.owner.lookup('service:store');
let serializer = store.serializerFor('user');
assert.ok(serializer);
});
test('it serializes records', function(assert) {
let store = this.owner.lookup('service:store');
let record = store.createRecord('user', {});
let serializedRecord = record.serialize();
assert.ok(serializedRecord);
});
});