Ghost/ghost/admin/tests/unit/models/invite-test.js

65 lines
2.0 KiB
JavaScript
Raw Normal View History

import Pretender from 'pretender';
import ghostPaths from 'ghost-admin/utils/ghost-paths';
2016-11-24 01:50:57 +03:00
import {describe, it} from 'mocha';
import {expect} from 'chai';
import {run} from '@ember/runloop';
import {settled} from '@ember/test-helpers';
import {setupTest} from 'ember-mocha';
describe('Unit: Model: invite', function () {
setupTest();
2016-11-24 01:50:57 +03:00
describe('with network', function () {
let server;
2016-11-24 01:50:57 +03:00
beforeEach(function () {
server = new Pretender();
});
afterEach(function () {
server.shutdown();
});
it('resend hits correct endpoints', async function () {
let store = this.owner.lookup('service:store');
let model = store.createRecord('invite', {
id: 42
});
2016-11-24 01:50:57 +03:00
let role;
server.delete(`${ghostPaths().apiRoot}/invites/42`, function () {
return [204, {}, '{}'];
});
server.post(`${ghostPaths().apiRoot}/invites/`, function () {
2016-11-24 01:50:57 +03:00
return [200, {}, '{}'];
});
2016-11-24 01:50:57 +03:00
run(() => {
role = store.push({data: {id: 1, type: 'role', attributes: {name: 'Editor'}}});
2016-11-24 01:50:57 +03:00
model.set('email', 'resend-test@example.com');
model.set('role', role);
model.resend();
});
await settled();
2016-11-24 01:50:57 +03:00
expect(
server.handledRequests.length,
'number of requests'
).to.equal(2);
let [, lastRequest] = server.handledRequests;
2016-11-24 01:50:57 +03:00
let requestBody = JSON.parse(lastRequest.requestBody);
let [invite] = requestBody.invites;
2016-11-24 01:50:57 +03:00
expect(
requestBody.invites.length,
'number of invites in request body'
).to.equal(1);
2016-11-24 01:50:57 +03:00
expect(invite.email).to.equal('resend-test@example.com');
// eslint-disable-next-line camelcase
expect(invite.role_id, 'role ID').to.equal('1');
});
2016-11-24 01:50:57 +03:00
});
});