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

57 lines
1.7 KiB
JavaScript
Raw Normal View History

import Pretender from 'pretender';
2016-11-24 01:50:57 +03:00
import {describe, it} from 'mocha';
import {expect} from 'chai';
import {run} from '@ember/runloop';
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();
});
2016-11-24 01:50:57 +03:00
it('resend hits correct endpoint', function () {
let store = this.owner.lookup('service:store');
let model = store.createRecord('invite');
2016-11-24 01:50:57 +03:00
let role;
server.post('/ghost/api/v2/admin/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();
});
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
});
});