refactor: 💡 mirage changes to support ldap account type (#1769)

* refactor: 💡 mirage changes to support ldap account type

✅ Closes: ICU-10052

* refactor: 💡 use switch statement and use curly braces
This commit is contained in:
Lisbet Alvarez authored and GitHub committed 2023-07-13 10:28:38 -07:00
1 parent d7b6eba2af
commit 15b769bd28
2 files changed
+26 -12

No files matched your search

+25 -10
View File
@@ -11,25 +11,40 @@ import {
TYPE_AUTH_METHOD_PASSWORD,
TYPE_AUTH_METHOD_OIDC,
TYPE_AUTH_METHOD_LDAP,
TYPES_AUTH_METHOD,
} from 'api/models/auth-method';
export default factory.extend({
authorized_actions: () =>
permissions.authorizedActionsFor('account') || [
'no-op',
'read',
'update',
'delete',
'set-password',
],
authorized_actions() {
let authorizedActions = ['no-op', 'read', 'update', 'delete'];
if (this.type === TYPE_AUTH_METHOD_PASSWORD) {
authorizedActions.push('set-password');
}
return permissions.authorizedActionsFor('account') || authorizedActions;
},
id: () => generateId('acct_'),
type: (i) => TYPES_AUTH_METHOD[i % TYPES_AUTH_METHOD.length],
attributes() {
switch (this.type) {
case TYPE_AUTH_METHOD_PASSWORD:
case TYPE_AUTH_METHOD_LDAP:
return { login_name: faker.random.words() };
return { login_name: faker.internet.userName() };
case TYPE_AUTH_METHOD_LDAP: {
const groupsAmount = faker.datatype.number({ min: 1, max: 3 });
let groups = [];
for (let i = 0; i < groupsAmount; i++) {
groups.push(faker.random.word());
}
return {
login_name: faker.internet.userName(),
email: faker.internet.email(),
full_name: faker.random.words(),
dn: faker.random.words(),
member_of_groups: groups,
};
}
case TYPE_AUTH_METHOD_OIDC:
return {
issuer: faker.internet.ip(),
@@ -5,13 +5,12 @@
import { Factory } from 'miragejs';
import { faker } from '@faker-js/faker';
import { TYPE_AUTH_METHOD_PASSWORD } from 'api/models/auth-method';
/**
* GeneratedAccountFactory
*/
export default Factory.extend({
type: TYPE_AUTH_METHOD_PASSWORD,
name: () => faker.random.words(),
description: () => faker.random.words(),
created_time: () => faker.date.recent(),
updated_time: () => faker.date.recent(),