2019-11-21 06:01:24 +03:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const supertest = require('supertest');
|
2020-04-27 14:44:00 +03:00
|
|
|
const testUtils = require('../utils');
|
|
|
|
const configUtils = require('../utils/configUtils');
|
|
|
|
const settingsCache = require('../../core/server/services/settings/cache');
|
2019-11-21 06:01:24 +03:00
|
|
|
|
2020-04-27 14:44:00 +03:00
|
|
|
// @TODO: if only this suite is run some of the tests will fail due to
|
2019-11-21 06:01:24 +03: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 14:44:00 +03:00
|
|
|
describe('Basic Members Routes', function () {
|
2019-11-21 06:01:24 +03:00
|
|
|
let request;
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
before(async function () {
|
|
|
|
await testUtils.startGhost();
|
|
|
|
request = supertest.agent(configUtils.config.get('url'));
|
2019-11-21 06:01:24 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
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('Routes', function () {
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should error serving webhook endpoint without any parameters', async function () {
|
|
|
|
await request.post('/members/webhooks/stripe')
|
2020-04-30 21:00:37 +03:00
|
|
|
.expect(400);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should error when invalid member token is passed into session', async function () {
|
|
|
|
await request.get('/members/api/session')
|
2019-11-21 06:01:24 +03:00
|
|
|
.expect(400);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should return no content when removing member sessions', async function () {
|
|
|
|
await request.del('/members/api/session')
|
2019-11-21 06:01:24 +03:00
|
|
|
.expect(204);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should error for invalid member token on member data endpoint', async function () {
|
|
|
|
await request.get('/members/api/member')
|
2020-04-30 09:52:22 +03:00
|
|
|
.expect(400);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should serve member site endpoint', async function () {
|
|
|
|
await request.get('/members/api/site')
|
2020-04-30 21:50:40 +03:00
|
|
|
.expect(200);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should error for invalid data on member magic link endpoint', async function () {
|
|
|
|
await request.post('/members/api/send-magic-link')
|
2020-04-30 21:00:37 +03:00
|
|
|
.expect(400);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should error for invalid data on members create checkout session endpoint', async function () {
|
|
|
|
await request.post('/members/api/create-stripe-checkout-session')
|
2020-04-30 21:00:37 +03:00
|
|
|
.expect(400);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should error for invalid data on members create update session endpoint', async function () {
|
|
|
|
await request.post('/members/api/create-stripe-update-session')
|
2020-04-30 21:00:37 +03:00
|
|
|
.expect(400);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should error for invalid data on members subscription endpoint', async function () {
|
|
|
|
await request.put('/members/api/subscriptions/123')
|
2019-11-21 06:01:24 +03:00
|
|
|
.expect(400);
|
|
|
|
});
|
2020-05-08 15:03:44 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should serve theme 404 on members endpoint', async function () {
|
|
|
|
await request.get('/members/')
|
2020-05-08 15:03:44 +03:00
|
|
|
.expect(404)
|
|
|
|
.expect('Content-Type', 'text/html; charset=utf-8');
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should redirect invalid token on members endpoint', async function () {
|
|
|
|
await request.get('/members/?token=abc&action=signup')
|
2020-05-08 15:03:44 +03:00
|
|
|
.expect(302)
|
|
|
|
.expect('Location', '/?action=signup&success=false');
|
|
|
|
});
|
2019-11-21 06:01:24 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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('Routes', function () {
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should not serve webhook endpoint', async function () {
|
|
|
|
await request.post('/members/webhooks/stripe')
|
2020-04-30 21:00:37 +03:00
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should not serve session endpoint', async function () {
|
|
|
|
await request.get('/members/api/session')
|
2019-11-21 06:01:24 +03:00
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should not serve session removal endpoint', async function () {
|
|
|
|
await request.del('/members/api/session')
|
2019-11-21 06:01:24 +03:00
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should not serve member data endpoint', async function () {
|
|
|
|
await request.get('/members/api/member')
|
2020-04-30 09:52:22 +03:00
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should not serve member site endpoint', async function () {
|
|
|
|
await request.get('/members/api/site')
|
2020-04-30 21:50:40 +03:00
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should not serve member magic link endpoint', async function () {
|
|
|
|
await request.post('/members/api/send-magic-link')
|
2020-04-30 21:00:37 +03:00
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should not serve members create checkout session endpoint', async function () {
|
|
|
|
await request.post('/members/api/create-stripe-checkout-session')
|
2020-04-30 21:00:37 +03:00
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should not serve members create update session endpoint', async function () {
|
|
|
|
await request.post('/members/api/create-stripe-update-session')
|
2020-04-30 21:00:37 +03:00
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should not serve members subscription endpoint', async function () {
|
|
|
|
await request.put('/members/api/subscriptions/123')
|
2019-11-21 06:01:24 +03:00
|
|
|
.expect(404);
|
|
|
|
});
|
2020-05-08 15:03:44 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should serve 404 on members endpoint', async function () {
|
|
|
|
await request.get('/members/')
|
2020-05-08 15:03:44 +03:00
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should not redirect members endpoint with token', async function () {
|
|
|
|
await request.get('/members/?token=abc&action=signup')
|
2020-05-08 15:03:44 +03:00
|
|
|
.expect(404);
|
|
|
|
});
|
2019-11-21 06:01:24 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|