github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/ui/mirage/factories/deployment.js (about) 1 import { Factory, faker, trait } from 'ember-cli-mirage'; 2 import { provide } from '../utils'; 3 4 const UUIDS = provide(100, faker.random.uuid.bind(faker.random)); 5 const DEPLOYMENT_STATUSES = ['running', 'successful', 'paused', 'failed', 'cancelled']; 6 7 export default Factory.extend({ 8 id: i => (i / 100 >= 1 ? `${UUIDS[i]}-${i}` : UUIDS[i]), 9 10 jobId: null, 11 versionNumber: null, 12 13 status: faker.list.random(...DEPLOYMENT_STATUSES), 14 statusDescription: () => faker.lorem.sentence(), 15 16 notActive: trait({ 17 status: faker.list.random(...DEPLOYMENT_STATUSES.without('running')), 18 }), 19 20 active: trait({ 21 status: 'running', 22 }), 23 24 afterCreate(deployment, server) { 25 const job = server.db.jobs.find(deployment.jobId); 26 const groups = job.taskGroupIds.map(id => 27 server.create('deployment-task-group-summary', { 28 deployment, 29 name: server.db.taskGroups.find(id).name, 30 desiredCanaries: 1, 31 promoted: false, 32 }) 33 ); 34 35 deployment.update({ 36 deploymentTaskGroupSummaryIds: groups.mapBy('id'), 37 }); 38 }, 39 });