chore: rip out org and project models
This commit is contained in:
13 files changed
+44
-146
No files matched your search
@@ -1,33 +0,0 @@
|
||||
import BaseModel from '../../models/base';
|
||||
import { attr } from '@ember-data/model';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export default class GeneratedOrgModel extends BaseModel {
|
||||
|
||||
// =attributes
|
||||
|
||||
@attr('string', {
|
||||
description: 'Optional name for identification purposes',
|
||||
})
|
||||
name;
|
||||
|
||||
@attr('string', {
|
||||
description: 'Optional user-set description for identification purposes',
|
||||
})
|
||||
description;
|
||||
|
||||
@attr('date', {
|
||||
description: 'The time this resource was created\nOutput only.',
|
||||
readOnly: true,
|
||||
})
|
||||
created_time;
|
||||
|
||||
@attr('date', {
|
||||
description: 'The time this resource was last updated\nOutput only.',
|
||||
readOnly: true,
|
||||
})
|
||||
updated_time;
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
import BaseModel from '../../models/base';
|
||||
import { attr } from '@ember-data/model';
|
||||
|
||||
/**
|
||||
* Project contains all fields related to a Project resource
|
||||
*/
|
||||
export default class GeneratedProjectModel extends BaseModel {
|
||||
// =attributes
|
||||
|
||||
@attr('string', {
|
||||
description: 'Optional name for identification purposes',
|
||||
})
|
||||
name;
|
||||
|
||||
@attr('string', {
|
||||
description: 'Optional user-set description for identification purposes',
|
||||
})
|
||||
description;
|
||||
|
||||
@attr('date', {
|
||||
description: 'The time this resource was created\nOutput only.',
|
||||
readOnly: true,
|
||||
})
|
||||
created_time;
|
||||
|
||||
@attr('date', {
|
||||
description: 'The time this resource was last updated\nOutput only.',
|
||||
readOnly: true,
|
||||
})
|
||||
updated_time;
|
||||
|
||||
@attr('boolean', {
|
||||
description: 'Whether the resource is disabled',
|
||||
})
|
||||
disabled;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
import GeneratedOrgModel from '../generated/models/org';
|
||||
|
||||
export default class OrgModel extends GeneratedOrgModel {}
|
||||
@@ -1,3 +0,0 @@
|
||||
import GeneratedProjectModel from '../generated/models/project';
|
||||
|
||||
export default class ProjectModel extends GeneratedProjectModel {}
|
||||
@@ -100,7 +100,7 @@ export default class ApplicationSerializer extends RESTSerializer {
|
||||
|
||||
/**
|
||||
* In our API, singluar resources are _unrooted_, whereas Ember Data expects
|
||||
* them to be rooted under their model name, e.g. `{project: {…}}`.
|
||||
* them to be rooted under their model name, e.g. `{modelName: {…}}`.
|
||||
* This method makes this transformation to accommodate Ember Data.
|
||||
*
|
||||
* @method normalizeSingleResponse
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export { default } from 'api/models/org';
|
||||
@@ -1 +0,0 @@
|
||||
export { default } from 'api/models/project';
|
||||
@@ -2,6 +2,6 @@ import Route from '@ember/routing/route';
|
||||
|
||||
export default class ApplicationRoute extends Route {
|
||||
model() {
|
||||
this.store.findAll('project');
|
||||
this.store.findAll('scope');
|
||||
}
|
||||
}
|
||||
@@ -64,18 +64,18 @@ module('Unit | Adapter | application', function (hooks) {
|
||||
};
|
||||
const adapter = this.owner.lookup('adapter:application');
|
||||
// test URL generation for each request type...
|
||||
const findRecordURL = adapter.buildURL('project', '1', mockSnapshot, 'findRecord');
|
||||
assert.equal(findRecordURL, '/v1/o_1/projects/1:my-custom-method');
|
||||
const findAllURL = adapter.buildURL('project', null, mockSnapshot, 'findAll');
|
||||
assert.equal(findAllURL, '/v1/o_1/projects:my-custom-method');
|
||||
const findBelongsToURL = adapter.buildURL('project', '2', mockSnapshot, 'findBelongsTo');
|
||||
assert.equal(findBelongsToURL, '/v1/o_1/projects/2:my-custom-method');
|
||||
const createRecordURL = adapter.buildURL('project', null, mockSnapshot, 'createRecord');
|
||||
assert.equal(createRecordURL, '/v1/o_1/projects:my-custom-method');
|
||||
const updateRecordURL = adapter.buildURL('project', '3', mockSnapshot, 'updateRecord');
|
||||
assert.equal(updateRecordURL, '/v1/o_1/projects/3:my-custom-method');
|
||||
const deleteRecordURL = adapter.buildURL('project', '4', mockSnapshot, 'deleteRecord');
|
||||
assert.equal(deleteRecordURL, '/v1/o_1/projects/4:my-custom-method');
|
||||
const findRecordURL = adapter.buildURL('user', '1', mockSnapshot, 'findRecord');
|
||||
assert.equal(findRecordURL, '/v1/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');
|
||||
const findBelongsToURL = adapter.buildURL('user', '2', mockSnapshot, 'findBelongsTo');
|
||||
assert.equal(findBelongsToURL, '/v1/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');
|
||||
const updateRecordURL = adapter.buildURL('user', '3', mockSnapshot, 'updateRecord');
|
||||
assert.equal(updateRecordURL, '/v1/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');
|
||||
});
|
||||
|
||||
test('it can request records through the store from a specified scope', async function (assert) {
|
||||
@@ -104,8 +104,8 @@ module('Unit | Adapter | application', function (hooks) {
|
||||
assert.expect(1);
|
||||
const adapter = this.owner.lookup('adapter:application');
|
||||
const store = this.owner.lookup('service:store');
|
||||
this.server.get('/v1/projects', () => new Response({}));
|
||||
const prenormalized = await adapter.findAll(store, {modelName: 'project'}, null, []);
|
||||
this.server.get('/v1/users', () => new Response({}));
|
||||
const prenormalized = await adapter.findAll(store, {modelName: 'user'}, null, []);
|
||||
assert.deepEqual(prenormalized, {items: []});
|
||||
});
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ module('Unit | Model | base', function (hooks) {
|
||||
store.push({
|
||||
data: {
|
||||
id: '123abc',
|
||||
type: 'project',
|
||||
type: 'user',
|
||||
attributes: {},
|
||||
relationships: {
|
||||
scope: {
|
||||
@@ -38,7 +38,7 @@ module('Unit | Model | base', function (hooks) {
|
||||
}
|
||||
});
|
||||
const scope = store.peekRecord('scope', 'o_1');
|
||||
const model = store.peekRecord('project', '123abc');
|
||||
const model = store.peekRecord('user', '123abc');
|
||||
assert.equal(model.scope, scope);
|
||||
});
|
||||
|
||||
@@ -48,11 +48,11 @@ module('Unit | Model | base', function (hooks) {
|
||||
store.push({
|
||||
data: {
|
||||
id: '123abc',
|
||||
type: 'project',
|
||||
type: 'user',
|
||||
attributes: {},
|
||||
},
|
||||
});
|
||||
const model = store.peekRecord('project', '123abc');
|
||||
const model = store.peekRecord('user', '123abc');
|
||||
assert.equal(model.name, null);
|
||||
assert.equal(model.displayName, '123abc');
|
||||
model.name = 'Test';
|
||||
@@ -65,15 +65,15 @@ module('Unit | Model | base', function (hooks) {
|
||||
store.push({
|
||||
data: {
|
||||
id: '1',
|
||||
type: 'project',
|
||||
type: 'user',
|
||||
attributes: {},
|
||||
},
|
||||
});
|
||||
const model = store.peekRecord('project', '1');
|
||||
const model = store.peekRecord('user', '1');
|
||||
assert.equal(model.canSave, false);
|
||||
assert.equal(model.cannotSave, true);
|
||||
// Should be able to save if dirty
|
||||
model.name = 'Project';
|
||||
model.name = 'User';
|
||||
assert.equal(model.hasDirtyAttributes, true);
|
||||
assert.equal(model.canSave, true);
|
||||
assert.equal(model.cannotSave, false);
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Model | org', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('org', {});
|
||||
assert.ok(model);
|
||||
});
|
||||
});
|
||||
@@ -1,12 +0,0 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Model | project', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('project', {});
|
||||
assert.ok(model);
|
||||
});
|
||||
});
|
||||
@@ -15,14 +15,14 @@ module('Unit | Serializer | application', function (hooks) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const scope = store.createRecord('scope', {id: 'global'});
|
||||
const record = store.createRecord('project', {
|
||||
name: 'Project',
|
||||
const record = store.createRecord('user', {
|
||||
name: 'User',
|
||||
description: 'Description',
|
||||
scope
|
||||
});
|
||||
const serializedRecord = record.serialize();
|
||||
assert.deepEqual(serializedRecord, {
|
||||
name: 'Project',
|
||||
name: 'User',
|
||||
description: 'Description',
|
||||
scope_id: 'global'
|
||||
//disabled: false, // TODO: disabled is temporarily disabled
|
||||
@@ -32,18 +32,18 @@ module('Unit | Serializer | application', function (hooks) {
|
||||
test('it normalizes array records from an `items` root key', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('project');
|
||||
const projectModelClass = store.createRecord('project').constructor;
|
||||
const serializer = store.serializerFor('user');
|
||||
const userModelClass = store.createRecord('user').constructor;
|
||||
const payload = {
|
||||
items: [
|
||||
{ id: 1, name: 'Project 1' },
|
||||
{ id: 2, name: 'Project 2' },
|
||||
{ id: 3, name: 'Project 3' },
|
||||
{ id: 1, name: 'User 1' },
|
||||
{ id: 2, name: 'User 2' },
|
||||
{ id: 3, name: 'User 3' },
|
||||
],
|
||||
};
|
||||
const normalizedArray = serializer.normalizeArrayResponse(
|
||||
store,
|
||||
projectModelClass,
|
||||
userModelClass,
|
||||
payload
|
||||
);
|
||||
assert.deepEqual(normalizedArray, {
|
||||
@@ -51,20 +51,20 @@ module('Unit | Serializer | application', function (hooks) {
|
||||
data: [
|
||||
{
|
||||
id: '1',
|
||||
type: 'project',
|
||||
attributes: { name: 'Project 1' },
|
||||
type: 'user',
|
||||
attributes: { name: 'User 1' },
|
||||
relationships: {},
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
type: 'project',
|
||||
attributes: { name: 'Project 2' },
|
||||
type: 'user',
|
||||
attributes: { name: 'User 2' },
|
||||
relationships: {},
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
type: 'project',
|
||||
attributes: { name: 'Project 3' },
|
||||
type: 'user',
|
||||
attributes: { name: 'User 3' },
|
||||
relationships: {},
|
||||
},
|
||||
],
|
||||
@@ -74,23 +74,23 @@ module('Unit | Serializer | application', function (hooks) {
|
||||
test('it normalizes single, unrooted records', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('project');
|
||||
const projectModelClass = store.createRecord('project').constructor;
|
||||
const serializer = store.serializerFor('user');
|
||||
const userModelClass = store.createRecord('user').constructor;
|
||||
const payload = {
|
||||
id: '1',
|
||||
name: 'Project 1',
|
||||
name: 'User 1',
|
||||
};
|
||||
const normalized = serializer.normalizeSingleResponse(
|
||||
store,
|
||||
projectModelClass,
|
||||
userModelClass,
|
||||
payload
|
||||
);
|
||||
assert.deepEqual(normalized, {
|
||||
included: [],
|
||||
data: {
|
||||
id: '1',
|
||||
type: 'project',
|
||||
attributes: { name: 'Project 1' },
|
||||
type: 'user',
|
||||
attributes: { name: 'User 1' },
|
||||
relationships: {},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user