2017-05-29 21:50:03 +03:00
|
|
|
import Pretender from 'pretender';
|
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';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {run} from '@ember/runloop';
|
2019-05-13 15:43:53 +03:00
|
|
|
import {setupTest} from 'ember-mocha';
|
2016-09-26 19:03:53 +03:00
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
describe('Unit: Model: invite', function () {
|
2019-05-13 15:43:53 +03:00
|
|
|
setupTest();
|
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 () {
|
2019-05-13 15:43:53 +03:00
|
|
|
let store = this.owner.lookup('service:store');
|
|
|
|
let model = store.createRecord('invite');
|
2016-11-24 01:50:57 +03:00
|
|
|
let role;
|
2016-09-26 19:03:53 +03:00
|
|
|
|
2018-10-05 21:46:33 +03:00
|
|
|
server.post('/ghost/api/v2/admin/invites/', function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
return [200, {}, '{}'];
|
|
|
|
});
|
2016-09-26 19:03:53 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(() => {
|
2019-05-13 15:43:53 +03:00
|
|
|
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();
|
|
|
|
});
|
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
|
|
|
});
|
|
|
|
});
|