feat: Add account associations in mirage
This commit is contained in:
5 files changed
+15
-7
No files matched your search
@@ -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');
|
||||
|
||||
@@ -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() }),
|
||||
|
||||
});
|
||||
@@ -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')
|
||||
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user