From 252dbaa75b1d0f9fc28a4e3191f7d7620665978a Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Mon, 14 Sep 2020 15:50:29 -0400 Subject: [PATCH] feat: Add account associations in mirage --- ui/core/mirage/config.js | 4 ++-- ui/core/mirage/factories/auth-method.js | 4 ++-- ui/core/mirage/generated/factories/account.js | 1 + ui/core/mirage/models/auth-method.js | 5 +++-- ui/core/mirage/serializers/account.js | 8 +++++++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ui/core/mirage/config.js b/ui/core/mirage/config.js index 225a896ba..62cb242b7 100644 --- a/ui/core/mirage/config.js +++ b/ui/core/mirage/config.js @@ -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'); diff --git a/ui/core/mirage/factories/auth-method.js b/ui/core/mirage/factories/auth-method.js index 25cca40c1..80254614a 100644 --- a/ui/core/mirage/factories/auth-method.js +++ b/ui/core/mirage/factories/auth-method.js @@ -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 }); } }) diff --git a/ui/core/mirage/generated/factories/account.js b/ui/core/mirage/generated/factories/account.js index a53c6aefe..a66184e1f 100644 --- a/ui/core/mirage/generated/factories/account.js +++ b/ui/core/mirage/generated/factories/account.js @@ -12,5 +12,6 @@ export default Factory.extend({ created_time: () => date.recent(), updated_time: () => date.recent(), version: () => random.number(), + attributes: () => ({ login_name: random.words() }), }); diff --git a/ui/core/mirage/models/auth-method.js b/ui/core/mirage/models/auth-method.js index 08b1f5ad3..878b8bd8a 100644 --- a/ui/core/mirage/models/auth-method.js +++ b/ui/core/mirage/models/auth-method.js @@ -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') }); diff --git a/ui/core/mirage/serializers/account.js b/ui/core/mirage/serializers/account.js index 3a5f8ae35..7c6186756 100644 --- a/ui/core/mirage/serializers/account.js +++ b/ui/core/mirage/serializers/account.js @@ -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; + } });