Files
threshold-ui/addons/api/mirage/factories/auth-method.js
T

32 lines
879 B
JavaScript
Raw Normal View History

2020-06-18 15:51:40 -04:00
import factory from '../generated/factories/auth-method';
2020-09-14 11:26:54 -04:00
import { trait } from 'ember-cli-mirage';
2021-08-16 13:31:28 -07:00
import permissions from '../helpers/permissions';
2020-06-18 15:51:40 -04:00
2021-03-15 17:08:47 -04:00
const types = ['password', 'oidc'];
2021-01-15 11:10:33 -05:00
2020-09-14 11:26:54 -04:00
export default factory.extend({
2021-08-16 13:31:28 -07:00
authorized_actions: () =>
2021-08-17 08:47:16 -07:00
permissions.authorizedActionsFor('auth-method') || [
2021-08-16 13:31:28 -07:00
'no-op',
'read',
'update',
'delete',
],
2020-09-14 12:00:21 -04:00
id: (i) => `auth-method-id-${i}`,
2020-09-14 11:26:54 -04:00
2021-01-15 11:10:33 -05:00
// Cycle through available types
type: (i) => types[i % types.length],
2020-09-14 11:26:54 -04:00
/**
2020-09-30 10:45:39 -04:00
* Adds accounts (with associated users) to auth method.
2020-09-14 11:26:54 -04:00
*/
2020-09-30 10:45:39 -04:00
withAccountsAndUsers: trait({
2020-09-14 11:26:54 -04:00
afterCreate(authMethod, server) {
2021-06-17 14:09:31 -04:00
const { scope, type } = authMethod;
2021-03-04 15:47:38 -05:00
server.createList('user', 5, { scope }).map((user) => {
2021-06-17 14:09:31 -04:00
const { id } = server.create('account', { scope, type, authMethod });
2020-09-30 10:45:39 -04:00
user.update({ accountIds: [id] });
});
2021-03-04 15:47:38 -05:00
},
}),
2020-09-14 11:26:54 -04:00
});