open-nomad/ui/mirage/factories/token.js
Buck Doyle 5da134d074
UI: Change Mirage data to be stable in development (#6389)
This sets a default-but-query-configurable Faker seed in development,
via faker-seed. It also changes uses of Math.random to use Faker’s
randomness so auto-generated data remains stable in development.
2019-10-03 09:13:08 -05:00

30 lines
752 B
JavaScript

import { Factory } from 'ember-cli-mirage';
import faker from 'nomad-ui/mirage/faker';
export default Factory.extend({
id: () => faker.random.uuid(),
accessorId() {
return this.id;
},
secretId: () => faker.random.uuid(),
name: () => faker.name.findName(),
global: () => faker.random.boolean(),
type: i => (i === 0 ? 'management' : 'client'),
afterCreate(token, server) {
const policyIds = Array(faker.random.number({ min: 1, max: 5 }))
.fill(0)
.map(() => faker.hacker.verb())
.uniq();
policyIds.forEach(policy => {
const dbPolicy = server.db.policies.find(policy);
if (!dbPolicy) {
server.create('policy', { id: policy });
}
});
token.update({ policyIds });
},
});