open-nomad/ui/mirage/factories/deployment-task-group-summary.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

43 lines
1 KiB
JavaScript

import { Factory } from 'ember-cli-mirage';
import faker from 'nomad-ui/mirage/faker';
const REF_TIME = new Date();
export default Factory.extend({
name: '',
autoRevert: () => faker.random.boolean(),
promoted: () => faker.random.boolean(),
requiresPromotion: false,
requireProgressBy: () => faker.date.past(0.5 / 365, REF_TIME),
desiredTotal: () => faker.random.number({ min: 1, max: 10 }),
desiredCanaries() {
return faker.random.number(Math.floor(this.desiredTotal / 2));
},
// PlacedCanaries is an array of allocation IDs. Since the IDs aren't currently
// used for associating allocations, any random value will do for now.
placedCanaries() {
return Array(faker.random.number(this.desiredCanaries))
.fill(null)
.map(() => faker.random.uuid());
},
placedAllocs() {
return faker.random.number(this.desiredTotal);
},
healthyAllocs() {
return faker.random.number(this.placedAllocs);
},
unhealthyAllocs() {
return this.placedAllocs - this.healthyAllocs;
},
});