Ghost/ghost/admin/tests/unit/models/invite-test.js
Kevin Ansfield 1520122483 Refactored deprecated usage of setupTest* methods
no issue

- https://github.com/emberjs/ember-mocha/blob/master/docs/migration.md#upgrading-to-the-new-testing-apis
- deleted tests files which had no specific tests
- migrated unskipped component unit tests to integration tests
2019-05-13 15:31:32 +01:00

57 lines
1.7 KiB
JavaScript

import Pretender from 'pretender';
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();
describe('with network', function () {
let server;
beforeEach(function () {
server = new Pretender();
});
afterEach(function () {
server.shutdown();
});
it('resend hits correct endpoint', function () {
let store = this.owner.lookup('service:store');
let model = store.createRecord('invite');
let role;
server.post('/ghost/api/v2/admin/invites/', function () {
return [200, {}, '{}'];
});
run(() => {
role = store.push({data: {id: 1, type: 'role', attributes: {name: 'Editor'}}});
model.set('email', 'resend-test@example.com');
model.set('role', role);
model.resend();
});
expect(
server.handledRequests.length,
'number of requests'
).to.equal(1);
let [lastRequest] = server.handledRequests;
let requestBody = JSON.parse(lastRequest.requestBody);
let [invite] = requestBody.invites;
expect(
requestBody.invites.length,
'number of invites in request body'
).to.equal(1);
expect(invite.email).to.equal('resend-test@example.com');
// eslint-disable-next-line camelcase
expect(invite.role_id, 'role ID').to.equal('1');
});
});
});