feat: 🎸 Refactor managed-groups mirage serializer and model

Refactor managed-groups mirage serializer and model. Accomodate factory
and admin UI acceptance test.
This commit is contained in:
Carlos Alcaide Corvo committed 2021-11-05 10:42:09 -07:00
1 parent ef73f8dacd
commit 202a22a170
6 files changed
+15 -20

No files matched your search

+3 -3
View File
@@ -28,13 +28,13 @@ export default factory.extend({
withAccountsAndUsersAndManagedGroups: trait({
afterCreate(authMethod, server) {
const { scope, type } = authMethod;
console.log('This is the test');
server.createList('user', 5, { scope }).map((user) => {
const { id } = server.create('account', { scope, type, authMethod });
user.update({ accountIds: [id] });
});
// We need to get the authmethod ID
// server.createList('managed-group', 2, { scope, authMethodId: id })
server.createList('managed-group', 2, { scope, authMethod });
},
}),
});
@@ -1,6 +1,5 @@
import factory from '../generated/factories/managed-groups';
import permissions from '../helpers/permissions';
import { trait } from 'ember-cli-mirage';
export default factory.extend({
id: (i) => `managed-groups-id-${i}`,
@@ -18,15 +17,4 @@ export default factory.extend({
accounts: ['create', 'list'],
};
},
/**
* Generates some users for the same scope and assigns them to the group
* as members.
*/
withMembers: trait({
afterCreate(group, server) {
const scope = group.scope;
const members = server.createList('user', 2, { scope });
group.update({ members });
},
}),
});
+1 -1
View File
@@ -2,5 +2,5 @@ import { Model, belongsTo } from 'ember-cli-mirage';
export default Model.extend({
scope: belongsTo(),
authMethodId: belongsTo(),
authMethod: belongsTo(),
});
-2
View File
@@ -44,8 +44,6 @@ export default function (server) {
server.createList('role', 1, { scope: globalScope }, 'withPrincipals');
server.createList('role', 5, { scope: orgScope }, 'withPrincipals');
// server.createList('managed-group', 2, { scope: globalScope }, 'withMembers');
// Other resources
server.schema.scopes.where({ type: 'project' }).models.forEach((scope) => {
server.createList('host-catalog', 2, { scope }, 'withChildren');
@@ -1,5 +1,14 @@
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
modelName: 'managed-groups',
modelName: 'managed-group',
_hashForModel(model) {
const json = ApplicationSerializer.prototype._hashForModel.apply(
this,
arguments
);
json.auth_method_id = model.authMethodId;
return json;
},
});
@@ -43,7 +43,7 @@ module('Acceptance | users | accounts', function (hooks) {
{
scope: instances.scopes.org,
},
'withAccountsAndUsers'
'withAccountsAndUsersAndManagedGroups'
);
instances.user = this.server.schema.users.all().models[0];
accountsCount = instances.user.accountIds.length;