2017-05-29 21:50:03 +03:00
|
|
|
import Pretender from 'pretender';
|
|
|
|
import run from 'ember-runloop';
|
2016-11-24 01:50:57 +03:00
|
|
|
import {describe, it} from 'mocha';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {expect} from 'chai';
|
2016-11-24 01:50:57 +03:00
|
|
|
import {setupModelTest} from 'ember-mocha';
|
2016-09-26 19:03:53 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
describe('Unit: Model: invite', function() {
|
|
|
|
setupModelTest('invite', {
|
2016-09-26 19:03:53 +03:00
|
|
|
needs: [
|
|
|
|
'model:role',
|
|
|
|
'serializer:application',
|
|
|
|
'serializer:invite',
|
|
|
|
'transform:moment-utc',
|
|
|
|
'service:ghost-paths',
|
|
|
|
'service:ajax',
|
|
|
|
'service:session',
|
2017-06-08 18:00:10 +03:00
|
|
|
'service:feature',
|
|
|
|
'service:tour'
|
2016-09-26 19:03:53 +03:00
|
|
|
]
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2016-09-26 19:03:53 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
describe('with network', function () {
|
|
|
|
let server;
|
2016-09-26 19:03:53 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
beforeEach(function () {
|
|
|
|
server = new Pretender();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
server.shutdown();
|
|
|
|
});
|
2016-09-26 19:03:53 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('resend hits correct endpoint', function () {
|
|
|
|
let model = this.subject();
|
|
|
|
let role;
|
2016-09-26 19:03:53 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
server.post('/ghost/api/v0.1/invites/', function () {
|
|
|
|
return [200, {}, '{}'];
|
|
|
|
});
|
2016-09-26 19:03:53 +03:00
|
|
|
|
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-09-26 19:03:53 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(
|
|
|
|
server.handledRequests.length,
|
|
|
|
'number of requests'
|
|
|
|
).to.equal(1);
|
2016-09-26 19:03:53 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
let [lastRequest] = server.handledRequests;
|
|
|
|
let requestBody = JSON.parse(lastRequest.requestBody);
|
|
|
|
let [invite] = requestBody.invites;
|
2016-09-26 19:03:53 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(
|
|
|
|
requestBody.invites.length,
|
|
|
|
'number of invites in request body'
|
|
|
|
).to.equal(1);
|
2016-09-26 19:03:53 +03:00
|
|
|
|
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-09-26 19:03:53 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|