2019-11-21 10:01:24 +07:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const supertest = require('supertest');
|
2020-04-27 12:44:00 +01:00
|
|
|
const testUtils = require('../utils');
|
|
|
|
const configUtils = require('../utils/configUtils');
|
|
|
|
const settingsCache = require('../../core/server/services/settings/cache');
|
2019-11-21 10:01:24 +07:00
|
|
|
|
|
|
|
const ghost = testUtils.startGhost;
|
|
|
|
|
2020-04-27 12:44:00 +01:00
|
|
|
// @TODO: if only this suite is run some of the tests will fail due to
|
2019-11-21 10:01:24 +07:00
|
|
|
// wrong template loading issues which would need to be investigated
|
|
|
|
// As a workaround run it with some of other tests e.g. "frontend_spec"
|
2020-04-27 12:44:00 +01:00
|
|
|
describe('Basic Members Routes', function () {
|
2019-11-21 10:01:24 +07:00
|
|
|
let request;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
return ghost()
|
|
|
|
.then(function () {
|
|
|
|
request = supertest.agent(configUtils.config.get('url'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Members enabled', function () {
|
|
|
|
before(function () {
|
|
|
|
const originalSettingsCacheGetFn = settingsCache.get;
|
|
|
|
|
|
|
|
sinon.stub(settingsCache, 'get').callsFake(function (key, options) {
|
|
|
|
if (key === 'labs') {
|
|
|
|
return {members: true};
|
|
|
|
}
|
|
|
|
|
|
|
|
return originalSettingsCacheGetFn(key, options);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Static files', function () {
|
|
|
|
it('should serve members.js file', function () {
|
|
|
|
return request.get('/public/members.js')
|
|
|
|
.expect(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Routes', function () {
|
|
|
|
it('should error when invalid member token is passed in to ssr', function () {
|
|
|
|
return request.get('/members/ssr')
|
|
|
|
.expect(400);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return no content when removing member sessions', function () {
|
|
|
|
return request.del('/members/ssr')
|
|
|
|
.expect(204);
|
|
|
|
});
|
|
|
|
|
2020-04-30 07:52:22 +01:00
|
|
|
it('should error for invalid member token on member data endpoint', function () {
|
|
|
|
return request.get('/members/ssr/member')
|
|
|
|
.expect(400);
|
|
|
|
});
|
|
|
|
|
2019-11-21 10:01:24 +07:00
|
|
|
it('should error serving webhook endpoint without any parameters', function () {
|
|
|
|
return request.post('/members/webhooks/stripe')
|
|
|
|
.expect(400);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Members disabled', function () {
|
|
|
|
before(function () {
|
|
|
|
const originalSettingsCacheGetFn = settingsCache.get;
|
|
|
|
|
|
|
|
sinon.stub(settingsCache, 'get').callsFake(function (key, options) {
|
|
|
|
if (key === 'labs') {
|
|
|
|
return {members: false};
|
|
|
|
}
|
|
|
|
|
|
|
|
return originalSettingsCacheGetFn(key, options);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Static files', function () {
|
|
|
|
it('should not serve members js file', function () {
|
|
|
|
return request.get('/public/members.js')
|
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Routes', function () {
|
|
|
|
it('should not serve ssr endpoint', function () {
|
|
|
|
return request.get('/members/ssr')
|
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not serve ssr removal endpoint', function () {
|
|
|
|
return request.del('/members/ssr')
|
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
2020-04-30 07:52:22 +01:00
|
|
|
it('should not serve member data endpoint', function () {
|
|
|
|
return request.get('/members/ssr/member')
|
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
2019-11-21 10:01:24 +07:00
|
|
|
it('should not serve webhook endpoint', function () {
|
|
|
|
return request.post('/members/webhooks/stripe')
|
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|