From 879989a127b7e9e84f89716b186061a8400e2a9c Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Mon, 14 Sep 2020 11:26:54 -0400 Subject: [PATCH] feat: Mock accounts in mirage --- ui/core/mirage/factories/account.js | 3 +++ ui/core/mirage/factories/auth-method.js | 16 +++++++++++++++- ui/core/mirage/generated/factories/account.js | 16 ++++++++++++++++ ui/core/mirage/models/account.js | 8 ++++++++ ui/core/mirage/scenarios/default.js | 2 +- ui/core/mirage/serializers/account.js | 5 +++++ 6 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 ui/core/mirage/factories/account.js create mode 100644 ui/core/mirage/generated/factories/account.js create mode 100644 ui/core/mirage/models/account.js create mode 100644 ui/core/mirage/serializers/account.js diff --git a/ui/core/mirage/factories/account.js b/ui/core/mirage/factories/account.js new file mode 100644 index 000000000..5908d0a21 --- /dev/null +++ b/ui/core/mirage/factories/account.js @@ -0,0 +1,3 @@ +import factory from '../generated/factories/account'; + +export default factory.extend(); diff --git a/ui/core/mirage/factories/auth-method.js b/ui/core/mirage/factories/auth-method.js index aa15a1103..8c75d95df 100644 --- a/ui/core/mirage/factories/auth-method.js +++ b/ui/core/mirage/factories/auth-method.js @@ -1,3 +1,17 @@ import factory from '../generated/factories/auth-method'; +import { trait } from 'ember-cli-mirage'; -export default factory.extend(); +export default factory.extend({ + id: (i) => `auth-method-id-${i}` + + /** + * Adds accounts. + */ + withAccounts: trait({ + afterCreate(authMethod, server) { + const { scope } = authMethod; + server.createList('account', 5, { scope }); + } + }) + +}); diff --git a/ui/core/mirage/generated/factories/account.js b/ui/core/mirage/generated/factories/account.js new file mode 100644 index 000000000..a53c6aefe --- /dev/null +++ b/ui/core/mirage/generated/factories/account.js @@ -0,0 +1,16 @@ +import { Factory } from 'ember-cli-mirage'; +import { random, date } from 'faker'; + +/** + * GeneratedAccountFactory + */ +export default Factory.extend({ + + type: 'password', + name: () => random.words(), + description: () => random.words(), + created_time: () => date.recent(), + updated_time: () => date.recent(), + version: () => random.number(), + +}); diff --git a/ui/core/mirage/models/account.js b/ui/core/mirage/models/account.js new file mode 100644 index 000000000..e6d3e303c --- /dev/null +++ b/ui/core/mirage/models/account.js @@ -0,0 +1,8 @@ +import { Model, belongsTo } from 'ember-cli-mirage'; + +export default Model.extend({ + + scope: belongsTo(), + authMethod: belongsTo() + +}); diff --git a/ui/core/mirage/scenarios/default.js b/ui/core/mirage/scenarios/default.js index 1524a7647..9492f92e3 100644 --- a/ui/core/mirage/scenarios/default.js +++ b/ui/core/mirage/scenarios/default.js @@ -15,7 +15,7 @@ export default function(server) { // Auth server.createList('auth-method', 3, { scope: globalScope }); - server.createList('auth-method', 3, { scope: orgScope }); + server.createList('auth-method', 3, { scope: orgScope }, 'withAccounts'); // Groups and Users server.createList('group', 5, { scope: orgScope }, 'withMembers'); diff --git a/ui/core/mirage/serializers/account.js b/ui/core/mirage/serializers/account.js new file mode 100644 index 000000000..3a5f8ae35 --- /dev/null +++ b/ui/core/mirage/serializers/account.js @@ -0,0 +1,5 @@ +import ApplicationSerializer from './application'; + +export default ApplicationSerializer.extend({ + modelName: 'account' +});