open-nomad/ui/mirage/factories/deployment.js
Buck Doyle 75aa2e36ee
UI: Change factories to be more dynamic (#6387)
I noticed while working on #6166 that some of the factory properties
that used Faker’s randomisation features are using their output
rather than a function that would call the randomiser. This means that
the randomisation happens once and the value is used for every model
generated by the factory. This wraps the randomiser calls in functions
so different models can have different values.
2019-09-30 09:44:22 -05:00

41 lines
1.1 KiB
JavaScript

import { Factory, trait } from 'ember-cli-mirage';
import faker from 'faker';
import { provide } from '../utils';
const UUIDS = provide(100, faker.random.uuid.bind(faker.random));
const DEPLOYMENT_STATUSES = ['running', 'successful', 'paused', 'failed', 'cancelled'];
export default Factory.extend({
id: i => (i / 100 >= 1 ? `${UUIDS[i]}-${i}` : UUIDS[i]),
jobId: null,
versionNumber: null,
status: () => faker.helpers.randomize(DEPLOYMENT_STATUSES),
statusDescription: () => faker.lorem.sentence(),
notActive: trait({
status: faker.helpers.randomize(DEPLOYMENT_STATUSES.without('running')),
}),
active: trait({
status: 'running',
}),
afterCreate(deployment, server) {
const job = server.db.jobs.find(deployment.jobId);
const groups = job.taskGroupIds.map(id =>
server.create('deployment-task-group-summary', {
deployment,
name: server.db.taskGroups.find(id).name,
desiredCanaries: 1,
promoted: false,
})
);
deployment.update({
deploymentTaskGroupSummaryIds: groups.mapBy('id'),
});
},
});