refactor: 💡 refactor mirage factory (#1787)

* 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 <dharini@hashicorp.com>
This commit is contained in:
Devon AndersonandDharini Jeeva authored and GitHub committed 2023-07-18 17:47:20 -04:00
1 parent f5087ab4ee
commit 50b0ab32b6
3 files changed
+13 -5

No files matched your search

+2 -1
View File
@@ -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) => {
+3 -2
View File
@@ -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) {
+8 -2
View File
@@ -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 });
});