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 NYCPlanning / labs-zap-search / mirage / config.js View on Github external
const { me } = request.queryParams;

    if (id) {
      return schema.users.find(id); // users in the second case
    }

    // typically this check requires a cookie in the backend, but as mirage
    // is run in the browser, and we use http-only cookies, we can't simulate
    // this cookie behavior. using regular cookies makes us prone to memory
    // leak issues. http-only cookies means the server is fully responsible
    // for identity management
    if (me) {
      return schema.users.first();
    }

    return new Response(401, { some: 'header' }, { errors: ['Unauthorized'] });
  });
  this.get('/users/:id');
github NYCPlanning / labs-zap-search / mirage / config.js View on Github external
this.post('/document', function(schema, request) {
    // requestBody should be a FormData object
    const { requestBody } = request;
    const success = requestBody.get('instanceId') && requestBody.get('entityName') && requestBody.get('file');
    return success ? new Response(200) : new Response(400, {}, { errors: ['Bad Parameters'] });
  });
github TryGhost / Ghost-Admin / mirage / config / authentication.js View on Github external
server.post('/session', function () {
        // Password sign-in
        return new Response(201);
    });
github ef4 / ember-handoff / tests / dummy / mirage / config.js View on Github external
this.get(path, () => {
      return new Response(200, {'Content-Type': 'text/http'}, body);
    });
  };
github CenterForOpenScience / ember-osf-web / mirage / views / registration.ts View on Github external
export function registrationDetail(this: HandlerContext, schema: Schema, request: Request) {
    const { id } = request.params;
    const registration = schema.registrations.find(id);

    if (registration.embargoed && !registration.currentUserPermissions.length) {
        return new Response(404, {}, {
            meta: { version: '2.9' },
            errors: [{ detail: 'Not found.' }],
        });
    }

    const { data } = process(schema, request, this, [this.serialize(registration).data]);

    return { data: data[0] };
}
github CenterForOpenScience / ember-osf-web / mirage / views / institution.ts View on Github external
export function institutionDelete(this: HandlerContext, schema: Schema, request: Request) {
    const { id, parentID } = request.params;
    const node = schema.nodes.find(parentID);

    const institutionIds: Array = node.affiliatedInstitutionIds;

    try {
        institutionIds.splice(institutionIds.indexOf(id), 1);
    } catch (e) {
        return new Response(409, {}, {
            meta: { version: '2.9' },
            errors: [{ detail: 'Conflict.' }],
        });
    }
    return institutionIds;
}
github TryGhost / Ghost-Admin / app / mirage / config / users.js View on Github external
server.del('/users/:id/', function (db, request) {
        db.users.remove(request.params.id);

        return new Mirage.Response(204, {}, {});
    });
github code-corps / code-corps-ember / mirage / config.js View on Github external
this.post('/password/reset', function(schema) {
    let { password, 'password-confirmation': passwordConfirmation, token } = this.normalizedRequestAttrs();

    let [matchedUser] = schema.users.where({ token }).models;

    if (password === passwordConfirmation) {
      return new Mirage.Response(201, {}, {
        email: matchedUser.email,
        token,
        user_id: matchedUser.id
      });
    } else {
      return new Mirage.Response(422, {}, {
        errors: [
          {
            detail: 'Password confirmation passwords do not match',
            source: {
              pointer: '/data/attributes/password-confirmation'
            },
            status: '422',
            title: 'passwords do not match'
          }
        ],
github CenterForOpenScience / ember-osf-web / mirage / views / user-password.ts View on Github external
export function updatePassword(this: HandlerContext) {
    const attrs = this.normalizedRequestAttrs('user-password');
    const existingPassword = 'oldpassword';

    if (attrs.existingPassword !== undefined) {
        if (attrs.existingPassword === existingPassword) {
            return new Response(204, undefined, undefined);
        }
        return new Response(409, { 'Content-Type': 'application/vnd.api+json' }, {
            errors: [{
                status: 409,
                detail: 'Old password is invalid.',
            }],
        });
    }
    return new Response(400, { 'Content-Type': 'application/vnd.api+json' }, {
        errors: [{
            status: 400,
            detail: 'Password must not be blank.',
        }],
    });
}
github ember-cli / ember-twiddle / mirage / config.js View on Github external
this.post('/gists/:id/forks', () => {
    let gist = server.create('gist', { id: faker.random.uuid() });
    return new Mirage.Response(200, {}, gist);
  });