feat: Add account associations in mirage

This commit is contained in:
Susmitha Girumala committed 2020-09-14 15:50:29 -04:00
1 parent 85aedacde4
commit 252dbaa75b
5 files changed
+15 -7

No files matched your search

+2 -2
View File
@@ -50,8 +50,8 @@ export default function() {
this.del('/auth-methods/:id');
// Auth Method Accounts
this.get('/accounts', ({ accounts }, { queryParams: { scope_id: scopeId } }) => {
return accounts.where({ scopeId });
this.get('/accounts', ({ accounts }, { queryParams: { auth_method_id: authMethodId } }) => {
return accounts.where({ authMethodId });
});
this.post('/accounts');
this.get('/accounts/:id');
+2 -2
View File
@@ -5,12 +5,12 @@ export default factory.extend({
id: (i) => `auth-method-id-${i}`,
/**
* Adds accounts.
* Adds accounts to auth method.
*/
withAccounts: trait({
afterCreate(authMethod, server) {
const { scope } = authMethod;
server.createList('account', 5, { scope });
server.createList('account', 5, { scope, authMethod });
}
})
@@ -12,5 +12,6 @@ export default Factory.extend({
created_time: () => date.recent(),
updated_time: () => date.recent(),
version: () => random.number(),
attributes: () => ({ login_name: random.words() }),
});
+3 -2
View File
@@ -1,7 +1,8 @@
import { Model, belongsTo } from 'ember-cli-mirage';
import { Model, belongsTo, hasMany} from 'ember-cli-mirage';
export default Model.extend({
scope: belongsTo()
scope: belongsTo(),
accounts: hasMany('account')
});
+7 -1
View File
@@ -1,5 +1,11 @@
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
modelName: 'account'
modelName: 'account',
_hashForModel(model) {
const json = ApplicationSerializer.prototype._hashForModel.apply(this, arguments);
json.auth_method_id = model.authMethodId;
return json;
}
});