open-nomad/ui/mirage/factories/deployment.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-09-26 18:47:07 +00:00
import { Factory, trait } from 'ember-cli-mirage';
import faker from 'nomad-ui/mirage/faker';
2017-09-19 14:47:10 +00:00
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),
2017-09-19 14:47:10 +00:00
statusDescription: () => faker.lorem.sentence(),
notActive: trait({
2019-09-26 18:47:07 +00:00
status: faker.helpers.randomize(DEPLOYMENT_STATUSES.without('running')),
2017-09-19 14:47:10 +00:00
}),
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,
2017-09-19 14:47:10 +00:00
})
);
deployment.update({
deploymentTaskGroupSummaryIds: groups.mapBy('id'),
});
},
});