refactor: 💡 formally model scope on target mocks
This commit is contained in:
4 files changed
+21
-17
No files matched your search
@@ -183,12 +183,10 @@ export default function() {
|
||||
// target
|
||||
|
||||
this.get('/targets', function ({ targets }, { queryParams: { scope_id } }) {
|
||||
return targets.where(target => target.scope?.id === scope_id);
|
||||
return targets.where(target => target.scopeId === scope_id);
|
||||
});
|
||||
this.post('/targets', function ({ targets, scopes }) {
|
||||
this.post('/targets', function ({ targets }) {
|
||||
const attrs = this.normalizedRequestAttrs();
|
||||
const scope = scopes.findBy(scope => scope.id === attrs.scopeId);
|
||||
attrs.scope = { id: scope.id, type: scope.type };
|
||||
return targets.create(attrs);
|
||||
});
|
||||
this.get('/targets/:id');
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Model, hasMany } from 'ember-cli-mirage';
|
||||
import { Model, belongsTo, hasMany } from 'ember-cli-mirage';
|
||||
|
||||
export default Model.extend({
|
||||
|
||||
scope: belongsTo(),
|
||||
hostSets: hasMany()
|
||||
|
||||
});
|
||||
@@ -12,25 +12,20 @@ export default function(server) {
|
||||
type: 'org',
|
||||
scope: { id: globalScope.id, type: globalScope.type }
|
||||
}, 'withChildren')[0];
|
||||
const scope = { id: orgScope.id, type: orgScope.type };
|
||||
const scopePojo = { id: orgScope.id, type: orgScope.type };
|
||||
|
||||
// Auth
|
||||
|
||||
// Auth methods exist both at the global scope and the org scope.
|
||||
// For simplicity we don't scope our mock auth methods and just return the
|
||||
// same items for request at all scopes.
|
||||
server.createList('auth-method', 3, { scope });
|
||||
server.createList('auth-method', 3, { scope: scopePojo });
|
||||
|
||||
// Groups and Users
|
||||
server.createList('group', 5, { scope }, 'withMembers');
|
||||
server.createList('group', 5, { scope: scopePojo }, 'withMembers');
|
||||
// Role
|
||||
server.createList('role', 5, { scope }, 'withPrincipals');
|
||||
server.createList('role', 5, { scope: scopePojo }, 'withPrincipals');
|
||||
|
||||
// Other resources
|
||||
|
||||
server.db.scopes.where({type: 'project'}).forEach(({ id, type }) => {
|
||||
const scope = { id, type };
|
||||
server.createList('host-catalog', 2, { scope }, 'withChildren');
|
||||
server.schema.scopes.where({type: 'project'}).models.forEach(scope => {
|
||||
const scopePojo = { id: scope.id, type: scope.type };
|
||||
server.createList('host-catalog', 2, { scope: scopePojo }, 'withChildren');
|
||||
server.createList('target', 2, { scope }, 'withRandomHostSets');
|
||||
});
|
||||
|
||||
|
||||
@@ -10,6 +10,12 @@ export default ApplicationSerializer.extend({
|
||||
)}_ids`;
|
||||
},
|
||||
|
||||
keyForRelationshipId(relationshipName) {
|
||||
return `${this._container.inflector.singularize(
|
||||
underscore(relationshipName)
|
||||
)}_id`;
|
||||
},
|
||||
|
||||
_hashForModel(model) {
|
||||
const json = ApplicationSerializer.prototype._hashForModel.apply(this, arguments);
|
||||
const { hostSets } = this.schema;
|
||||
@@ -18,6 +24,10 @@ export default ApplicationSerializer.extend({
|
||||
const host_catalog_id = hostSet?.hostCatalog?.id;
|
||||
return { host_set_id, host_catalog_id };
|
||||
});
|
||||
json.scope = {
|
||||
id: model.scope.id,
|
||||
type: model.scope.type
|
||||
};
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user