mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
467ee93b21
closes https://github.com/TryGhost/Ghost/issues/7420, requires https://github.com/TryGhost/Ghost/pull/7422 - adds a new `Invite` model with associated serializer and test setup - updates team screen to use invites rather than existing users with the "invited" property - updates signup process to work with new invite model - updates setup process to create invites instead of users - swaps usage of `gh-select-native` for `one-way-select` in the invite modal so that attributes can be set on the `select` element - updates resend invite process to account for server returning a new model - rewrites the invite management tests and fixes mirage mocks for invite endpoints - sorts invites by email address to avoid jumping invites when re-sending
88 lines
2.7 KiB
JavaScript
88 lines
2.7 KiB
JavaScript
import { expect } from 'chai';
|
|
import { describeModel, it } from 'ember-mocha';
|
|
import run from 'ember-runloop';
|
|
import Pretender from 'pretender';
|
|
|
|
describeModel(
|
|
'invite',
|
|
'Unit: Model: invite',
|
|
{
|
|
needs: [
|
|
'model:role',
|
|
'serializer:application',
|
|
'serializer:invite',
|
|
'transform:moment-utc',
|
|
'service:ghost-paths',
|
|
'service:ajax',
|
|
'service:session',
|
|
'service:feature'
|
|
]
|
|
},
|
|
function() {
|
|
it('role property returns first role in array', function () {
|
|
let model = this.subject();
|
|
|
|
run(() => {
|
|
let role = this.store().push({data: {id: 1, type: 'role', attributes: {name: 'Author'}}});
|
|
model.get('roles').pushObject(role);
|
|
});
|
|
expect(model.get('role.name')).to.equal('Author');
|
|
|
|
run(() => {
|
|
let role = this.store().push({data: {id: 1, type: 'role', attributes: {name: 'Editor'}}});
|
|
model.set('role', role);
|
|
});
|
|
expect(model.get('role.name')).to.equal('Editor');
|
|
});
|
|
|
|
describe('with network', function () {
|
|
let server;
|
|
|
|
beforeEach(function () {
|
|
server = new Pretender();
|
|
});
|
|
|
|
afterEach(function () {
|
|
server.shutdown();
|
|
});
|
|
|
|
it('resend hits correct endpoint', function () {
|
|
let model = this.subject();
|
|
let role;
|
|
|
|
server.post('/ghost/api/v0.1/invites/', function () {
|
|
return [200, {}, '{}'];
|
|
});
|
|
|
|
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();
|
|
});
|
|
|
|
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');
|
|
expect(
|
|
invite.roles.length,
|
|
'number of roles in request body'
|
|
).to.equal(1);
|
|
expect(invite.roles[0], 'role ID').to.equal('1');
|
|
});
|
|
});
|
|
}
|
|
);
|