How to use ember-cli-mirage - 10 common examples

To help you get started, we’ve selected a few ember-cli-mirage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lifegadget / ui-list / tests / dummy / app / mirage / factories / appointment.js View on Github external
import Mirage, {faker} from 'ember-cli-mirage';

export default Mirage.Factory.extend({
  firstName: faker.name.firstName,       // using faker
  lastName: faker.name.lastName,
  email: function(i) {                  // and functions
    return 'person' + i + '@email.com';
  },
  when: faker.date.future,
  quantity: faker.random.number,
  avatar: faker.image.avatar,
  topic: faker.lorem.words,
  status: faker.list.random('downloaded','verifying','verified','scheduling','scheduled','preparing','executing','executed')
});
github dustinfarris / ember-cashay / tests / dummy / mirage / factories / todo.js View on Github external
import { Factory, faker } from 'ember-cli-mirage';

export default Factory.extend({
  createdAt: faker.date.past(1),  // some time in the past 1 year
  description: faker.company.bs
});
github hashicorp / levant / vendor / github.com / hashicorp / nomad / ui / mirage / factories / job.js View on Github external
// serializer update for bool vs details object
    parameterizedDetails: () => ({
      MetaOptional: null,
      MetaRequired: null,
      Payload: Math.random() > 0.5 ? 'required' : null,
    }),
  }),

  periodicChild: trait({
    // Periodic children need a parent job,
    // It is the Periodic job's responsibility to create
    // periodicChild jobs and provide a parent job.
    type: 'batch',
  }),

  parameterizedChild: trait({
    // Parameterized children need a parent job,
    // It is the Parameterized job's responsibility to create
    // parameterizedChild jobs and provide a parent job.
    type: 'batch',
    parameterized: true,
    dispatched: true,
    payload: window.btoa(faker.lorem.sentence()),
  }),

  createIndex: i => i,
  modifyIndex: () => faker.random.number({ min: 10, max: 2000 }),

  // Directive used to control sub-resources

  // When false, no allocations are made
  createAllocations: true,
github hashicorp / nomad / ui / mirage / factories / alloc-file.js View on Github external
dir: trait({
    isDir: true,
    afterCreate(allocFile, server) {
      // create files for the directory
      if (allocFile.depth > 0) {
        server.create('allocFile', 'dir', { parent: allocFile, depth: allocFile.depth - 1 });
      }

      server.createList('allocFile', faker.random.number({ min: 1, max: 3 }), 'file', {
        parent: allocFile,
      });
    },
  }),

  file: trait({
    isDir: false,
  }),
});
github hashicorp / levant / vendor / github.com / hashicorp / nomad / ui / mirage / factories / job-summary.js View on Github external
import { Factory, faker, trait } from 'ember-cli-mirage';

export default Factory.extend({
  // Hidden property used to compute the Summary hash
  groupNames: [],

  JobID: '',
  namespace: null,

  withSummary: trait({
    Summary: function() {
      return this.groupNames.reduce((summary, group) => {
        summary[group] = {
          Queued: faker.random.number(10),
          Complete: faker.random.number(10),
          Failed: faker.random.number(10),
          Running: faker.random.number(10),
          Starting: faker.random.number(10),
          Lost: faker.random.number(10),
        };
        return summary;
      }, {});
    },
  }),

  withChildren: trait({
github hashicorp / levant / vendor / github.com / hashicorp / nomad / ui / mirage / factories / node.js View on Github external
drain: true,
    schedulingEligibility: 'ineligible',
    drainStrategy: {
      Deadline: -1,
      ForceDeadline: '0001-01-01T00:00:00Z',
      IgnoreSystemJobs: faker.random.boolean(),
    },
  }),

  noDeadlineDraining: trait({
    drain: true,
    schedulingEligibility: 'ineligible',
    drainStrategy: {
      Deadline: 0,
      ForceDeadline: '0001-01-01T00:00:00Z',
      IgnoreSystemJobs: faker.random.boolean(),
    },
  }),

  drainStrategy: null,

  drivers: makeDrivers,

  resources: generateResources,

  attributes() {
    // TODO add variability to these
    return {
      'os.version': '10.12.5',
      'cpu.modelname': 'Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz',
      'nomad.revision': 'f551dcb83e3ac144c9dbb90583b6e82d234662e9',
      'driver.docker.volumes.enabled': '1',
github hashicorp / levant / vendor / github.com / hashicorp / nomad / ui / mirage / config.js View on Github external
this.post('/jobs/parse', function(schema, req) {
    const body = JSON.parse(req.requestBody);

    if (!body.JobHCL)
      return new Response(400, {}, 'JobHCL is a required field on the request payload');
    if (!body.Canonicalize) return new Response(400, {}, 'Expected Canonicalize to be true');

    // Parse the name out of the first real line of HCL to match IDs in the new job record
    // Regex expectation:
    //   in:  job "job-name" {
    //   out: job-name
    const nameFromHCLBlock = /.+?"(.+?)"/;
    const jobName = body.JobHCL.trim()
      .split('\n')[0]
      .match(nameFromHCLBlock)[1];

    const job = server.create('job', { id: jobName });
    return new Response(200, {}, this.serialize(job));
  });
github hashicorp / nomad / ui / mirage / config.js View on Github external
this.post('/jobs/parse', function(schema, req) {
    const body = JSON.parse(req.requestBody);

    if (!body.JobHCL)
      return new Response(400, {}, 'JobHCL is a required field on the request payload');
    if (!body.Canonicalize) return new Response(400, {}, 'Expected Canonicalize to be true');

    // Parse the name out of the first real line of HCL to match IDs in the new job record
    // Regex expectation:
    //   in:  job "job-name" {
    //   out: job-name
    const nameFromHCLBlock = /.+?"(.+?)"/;
    const jobName = body.JobHCL.trim()
      .split('\n')[0]
      .match(nameFromHCLBlock)[1];

    const job = server.create('job', { id: jobName });
    return new Response(200, {}, this.serialize(job));
  });
github hashicorp / nomad / ui / mirage / factories / csi-plugin.js View on Github external
import { Factory } from 'ember-cli-mirage';
import faker from 'nomad-ui/mirage/faker';
import { STORAGE_PROVIDERS } from '../common';

export default Factory.extend({
  id: () => faker.random.uuid(),

  // Topologies is currently unused by the UI. This should
  // eventually become dynamic.
  topologies: () => [{ foo: 'bar' }],

  provider: faker.helpers.randomize(STORAGE_PROVIDERS),
  version: '1.0.1',

  controllerRequired: faker.random.boolean,

  controllersHealthy() {
    if (!this.controllerRequired) return 0;
    return faker.random.number(3);
  },
  controllersExpected() {
github CenterForOpenScience / ember-osf-web / mirage / factories / node.ts View on Github external
const identifier = server.create('identifier', { referent: node });
            // eslint-disable-next-line no-param-reassign
            node.identifiers = [identifier] as unknown as Collection;
            node.save();
        },
    }),

    withLicense: trait({
        afterCreate(node, server) {
            const license = faker.random.arrayElement(server.schema.licenses.all().models);
            node.license = license; // eslint-disable-line no-param-reassign
            node.save();
        },
    }),

    withAffiliatedInstitutions: trait({
        afterCreate(node, server) {
            const affiliatedInstitutionCount = faker.random.number({ min: 4, max: 5 });
            server.createList('institution', affiliatedInstitutionCount, {
                nodes: [node],
            });
        },
    }),

    withManyAffiliatedInstitutions: trait({
        afterCreate(node, server) {
            server.createList('institution', 15, {
                nodes: [node],
            });
        },
    }),