2017-05-29 21:50:03 +03:00
|
|
|
import Pretender from 'pretender';
|
2021-02-05 12:12:26 +03:00
|
|
|
import ghostPaths from 'ghost-admin/utils/ghost-paths';
|
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';
|
2022-01-21 22:25:47 +03:00
|
|
|
import {settled} from '@ember/test-helpers';
|
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
|
|
|
|
2021-04-06 06:10:03 +03:00
|
|
|
it('resend hits correct endpoints', async function () {
|
2019-05-13 15:43:53 +03:00
|
|
|
let store = this.owner.lookup('service:store');
|
2021-04-06 06:10:03 +03:00
|
|
|
let model = store.createRecord('invite', {
|
|
|
|
id: 42
|
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
let role;
|
2016-09-26 19:03:53 +03:00
|
|
|
|
2021-04-06 06:10:03 +03:00
|
|
|
server.delete(`${ghostPaths().apiRoot}/invites/42`, function () {
|
|
|
|
return [204, {}, '{}'];
|
|
|
|
});
|
|
|
|
|
2021-02-05 12:12:26 +03:00
|
|
|
server.post(`${ghostPaths().apiRoot}/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();
|
|
|
|
});
|
2022-01-21 22:25:47 +03:00
|
|
|
await settled();
|
2016-09-26 19:03:53 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(
|
|
|
|
server.handledRequests.length,
|
|
|
|
'number of requests'
|
2021-04-06 06:10:03 +03:00
|
|
|
).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-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
|
|
|
});
|
|
|
|
});
|