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

68 lines
1.9 KiB
JavaScript
Raw Normal View History

import Pretender from 'pretender';
import run from 'ember-runloop';
2016-11-24 01:50:57 +03:00
import {describe, it} from 'mocha';
import {expect} from 'chai';
2016-11-24 01:50:57 +03:00
import {setupModelTest} from 'ember-mocha';
2016-11-24 01:50:57 +03:00
describe('Unit: Model: invite', function() {
setupModelTest('invite', {
needs: [
'model:role',
'serializer:application',
'serializer:invite',
'transform:moment-utc',
'service:ghost-paths',
'service:ajax',
'service:session',
'service:feature',
'service:tour'
]
2016-11-24 01:50:57 +03:00
});
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();
});
2016-11-24 01:50:57 +03:00
it('resend hits correct endpoint', function () {
let model = this.subject();
let role;
2016-11-24 01:50:57 +03:00
server.post('/ghost/api/v0.1/invites/', function () {
return [200, {}, '{}'];
});
2016-11-24 01:50:57 +03:00
run(() => {
role = this.store().push({data: {id: 1, type: 'role', attributes: {name: 'Editor'}}});
model.set('email', 'resend-test@example.com');
model.set('role', role);
model.resend();
});
2016-11-24 01:50:57 +03:00
expect(
server.handledRequests.length,
'number of requests'
).to.equal(1);
2016-11-24 01:50:57 +03:00
let [lastRequest] = server.handledRequests;
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
});
});