mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-30 14:22:07 +03:00
238632402c
refs https://github.com/TryGhost/Team/issues/587 refse30b9735fa
- It was not possible to invite a new Contributor to a site that has reached its limit - This fix divides the resend invite action into two separate steps: 1. Deleting existing invite 2. Creating a new one for the same data - It was hitting the limit because the permissions were correctly checking for "add" action being executed when the limit of invites/staff users was already used up. By removing existing invite we mimic the behavior the server would do for us anyway (2111992dd4/core/server/services/invites/invites.js (L18-L22)
) Co-authored-by: Rish <zrishabhgarg@gmail.com>
65 lines
2.0 KiB
JavaScript
65 lines
2.0 KiB
JavaScript
import Pretender from 'pretender';
|
|
import ghostPaths from 'ghost-admin/utils/ghost-paths';
|
|
import wait from 'ember-test-helpers/wait';
|
|
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 endpoints', async function () {
|
|
let store = this.owner.lookup('service:store');
|
|
let model = store.createRecord('invite', {
|
|
id: 42
|
|
});
|
|
let role;
|
|
|
|
server.delete(`${ghostPaths().apiRoot}/invites/42`, function () {
|
|
return [204, {}, '{}'];
|
|
});
|
|
|
|
server.post(`${ghostPaths().apiRoot}/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();
|
|
});
|
|
await wait();
|
|
|
|
expect(
|
|
server.handledRequests.length,
|
|
'number of requests'
|
|
).to.equal(2);
|
|
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');
|
|
});
|
|
});
|
|
});
|