How to use the ember-cli-mirage/response function in ember-cli-mirage

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 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 / config.js View on Github external
return new Response(404, {}, null);
      }
    }

    // Return the policy only if the token that matches the request header
    // includes the policy or if the token that matches the request header
    // is of type management
    if (
      tokenForSecret &&
      (tokenForSecret.policies.includes(policy) || tokenForSecret.type === 'management')
    ) {
      return this.serialize(policy);
    }

    // Return not authorized otherwise
    return new Response(403, {}, null);
  });
github algonauti / ember-active-storage / tests / dummy / mirage / config.js View on Github external
this.post('/attachments/upload', (_, request) => {
    const response = uploadResponse(request.requestBody, {
      directUploadURL: '/api/attachments/direct-upload'
    });
    return new Response(200, response.headers, response.body);
  });
github adopted-ember-addons / ember-file-upload / addon / mirage / index.js View on Github external
metadata.then((metadata) => {
            request.requestBody = Object.assign({
              [file.key]: metadata
            }, data);
            if (timedOut) {
              resolve(new Response(408));
              return;
            }

            resolve(fn.call(this, db, request));
          }).catch((error) => {
            resolve(new Response(500, {}, { error: error.message }));
github hashicorp / levant / vendor / github.com / hashicorp / nomad / ui / mirage / config.js View on Github external
this.get('/job/:id/deployment', function({ deployments }, { params }) {
    const deployment = deployments.where({ jobId: params.id }).models[0];
    return deployment ? this.serialize(deployment) : new Response(200, {}, 'null');
  });
github hashicorp / levant / vendor / github.com / hashicorp / nomad / ui / mirage / config.js View on Github external
this.get('/client/stats', function({ clientStats }, { queryParams }) {
    const seed = Math.random();
    if (seed > 0.8) {
      const stats = clientStats.find(queryParams.node_id);
      stats.update({
        timestamp: Date.now() * 1000000,
        CPUTicksConsumed: stats.CPUTicksConsumed + (Math.random() * 20 - 10),
      });
      return this.serialize(stats);
    } else {
      return new Response(500, {}, null);
    }
  });
github hashicorp / nomad / ui / mirage / config.js View on Github external
function okEmpty() {
  return new Response(200, {}, '{}');
}
github hashicorp / nomad / ui / mirage / config.js View on Github external
this.post('/job/:id/plan', function(schema, req) {
    const body = JSON.parse(req.requestBody);

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

    const FailedTGAllocs = body.Job.Unschedulable && generateFailedTGAllocs(body.Job);

    return new Response(
      200,
      {},
      JSON.stringify({ FailedTGAllocs, Diff: generateDiff(req.params.id) })
    );
  });