github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/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        })
    31      );
    32  
    33      deployment.update({
    34        deploymentTaskGroupSummaryIds: groups.mapBy('id'),
    35      });
    36    },
    37  });