From 50b0ab32b67f86e716c9f180baac303da20b04ca Mon Sep 17 00:00:00 2001 From: Devon Anderson Date: Tue, 18 Jul 2023 17:47:20 -0400 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20refactor=20mirage=20?= =?UTF-8?q?factory=20(#1787)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 💡 refactor mirage factory Refactor `LDAP/managed-groups` factory to only return specific `auth-method` type ✅ Closes: ICU-10284 * refactor: 💡 refactor default scenario Refactor default scenario to use imported `types` --------- Co-authored-by: Dharini Jeeva --- addons/api/mirage/factories/auth-method.js | 3 ++- addons/api/mirage/factories/managed-group.js | 5 +++-- addons/api/mirage/scenarios/default.js | 10 ++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/addons/api/mirage/factories/auth-method.js b/addons/api/mirage/factories/auth-method.js index dee5481a3..46ac67090 100644 --- a/addons/api/mirage/factories/auth-method.js +++ b/addons/api/mirage/factories/auth-method.js @@ -10,6 +10,7 @@ import generateId from '../helpers/id'; import { TYPE_AUTH_METHOD_OIDC, + TYPE_AUTH_METHOD_LDAP, TYPES_AUTH_METHOD, } from 'api/models/auth-method'; @@ -46,7 +47,7 @@ export default factory.extend({ user.update({ accountIds: [id] }); }); - if (type === TYPE_AUTH_METHOD_OIDC) { + if (type === TYPE_AUTH_METHOD_OIDC || type === TYPE_AUTH_METHOD_LDAP) { server .createList('managed-group', 2, { scope, authMethod }) .map((managedGroup) => { diff --git a/addons/api/mirage/factories/managed-group.js b/addons/api/mirage/factories/managed-group.js index 40db17b40..90ccfd852 100644 --- a/addons/api/mirage/factories/managed-group.js +++ b/addons/api/mirage/factories/managed-group.js @@ -10,7 +10,6 @@ import generateId from '../helpers/id'; import { TYPE_AUTH_METHOD_OIDC, TYPE_AUTH_METHOD_LDAP, - TYPES_AUTH_METHOD, } from 'api/models/auth-method'; export default factory.extend({ @@ -24,7 +23,9 @@ export default factory.extend({ id: () => generateId('mg_'), - type: (i) => TYPES_AUTH_METHOD[i % TYPES_AUTH_METHOD.length], + type() { + return this.authMethod?.type; + }, attributes() { switch (this.type) { diff --git a/addons/api/mirage/scenarios/default.js b/addons/api/mirage/scenarios/default.js index 8efe720d4..6cc62d550 100644 --- a/addons/api/mirage/scenarios/default.js +++ b/addons/api/mirage/scenarios/default.js @@ -3,6 +3,8 @@ * SPDX-License-Identifier: MPL-2.0 */ +import { TYPE_AUTH_METHOD_OIDC } from 'api/models/auth-method'; + export default function (server) { // Scope resources @@ -66,11 +68,13 @@ export default function (server) { globalScopeRoles.forEach((role) => { const { scope } = role; const oidcAuthMethod = globalAuthMethods.filter( - (auth) => auth.type === 'oidc' + (auth) => auth.type === TYPE_AUTH_METHOD_OIDC )[0]; + const { type } = oidcAuthMethod; const managedGroups = server.createList('managed-group', 2, { scope, authMethodId: oidcAuthMethod.id, + type, }); role.update({ managedGroups }); }); @@ -85,11 +89,13 @@ export default function (server) { orgScopeRoles.forEach((role) => { const { scope } = role; const oidcAuthMethod = orgAuthMethods.filter( - (auth) => auth.type === 'oidc' + (auth) => auth.type === TYPE_AUTH_METHOD_OIDC )[0]; + const { type } = oidcAuthMethod; const managedGroups = server.createList('managed-group', 2, { scope, authMethodId: oidcAuthMethod.id, + type, }); role.update({ managedGroups }); });