Ghost/ghost/admin/tests/unit/models/invite-test.js
Fabien O'Carroll 3e5a62309f Use Admin API v2 with session auth (#1046)
refs #9865
- removed all `oauth2` and token-based ESA auth
- added new `cookie` authenticator which handles session creation
- updated the session store to extend from the `ephemeral` in-memory store and to restore by fetching the currently logged in user and using the success/failure state to indicate authentication state
  - ESA automatically calls this `.restore()` method on app boot
  - the `session` service caches the current-user query so there's no unnecessary requests being made for the "logged in" state
- removed the now-unnecessary token refresh and logout routines from the `application` route
- removed the now-unnecessary token refresh routines from the `ajax` service
- removed `access_token` query param from iframe file downloaders
- changed Ember Data adapters and `ghost-paths` to use the `/ghost/api/v2/admin/` namespace
2018-10-05 19:46:33 +01:00

68 lines
1.9 KiB
JavaScript

import Pretender from 'pretender';
import {describe, it} from 'mocha';
import {expect} from 'chai';
import {run} from '@ember/runloop';
import {setupModelTest} from 'ember-mocha';
describe('Unit: Model: invite', function () {
setupModelTest('invite', {
needs: [
'model:role',
'serializer:application',
'serializer:invite',
'transform:moment-utc',
'service:ghost-paths',
'service:ajax',
'service:session',
'service:feature',
'service:tour'
]
});
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/v2/admin/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');
// eslint-disable-next-line camelcase
expect(invite.role_id, 'role ID').to.equal('1');
});
});
});