mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-03 16:38:22 +03:00
193c179110
no issue
- In order to keep site/app.js module tidy and less coupled with members module we need to extract some of the functionality where it belongs conceptually
- Added "members enabled check" middleware to stripe webhook endpoint
- Reshuffled members middleware so that siteApp is in control of mounting points. This is meant to be a more explicit way to see which endpoints are being handled by members middleware
- Extracted member-specific public file middleware
- Unified use of `labs.member` alias method. Done for code style consistency
- Added basic members' test suite. This is a base we could work from when more modifications are needed
- Removed route handler for unexisting members file "members-theme-bindings.js". Calling this route otherwise causes a 500. Looks like a leftover from 49672a1e4d
107 lines
3.4 KiB
JavaScript
107 lines
3.4 KiB
JavaScript
const should = require('should');
|
|
const sinon = require('sinon');
|
|
const supertest = require('supertest');
|
|
const testUtils = require('../../utils');
|
|
const configUtils = require('../../utils/configUtils');
|
|
const settingsCache = require('../../../server/services/settings/cache');
|
|
|
|
const ghost = testUtils.startGhost;
|
|
|
|
// NOTE: if only this suite is run some of the tests will fail due to
|
|
// wrong template loading issues which would need to be investigated
|
|
// As a workaround run it with some of other tests e.g. "frontend_spec"
|
|
describe('Integration - Web - Members', function () {
|
|
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);
|
|
});
|
|
|
|
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);
|
|
});
|
|
|
|
it('should not serve webhook endpoint', function () {
|
|
return request.post('/members/webhooks/stripe')
|
|
.expect(404);
|
|
});
|
|
});
|
|
});
|
|
});
|