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
|
|
|
});
|
|
|
|
|
2021-01-28 21:07:45 +03:00
|
|
|
before(function () {
|
|
|
|
const originalSettingsCacheGetFn = settingsCache.get;
|
2019-11-21 06:01:24 +03:00
|
|
|
|
2021-01-28 21:07:45 +03:00
|
|
|
sinon.stub(settingsCache, 'get').callsFake(function (key, options) {
|
|
|
|
if (key === 'labs') {
|
|
|
|
return {members: true};
|
|
|
|
}
|
2019-11-21 06:01:24 +03:00
|
|
|
|
2021-01-28 21:07:45 +03:00
|
|
|
return originalSettingsCacheGetFn(key, options);
|
2019-11-21 06:01:24 +03:00
|
|
|
});
|
2021-01-28 21:07:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
2019-11-21 06:01:24 +03:00
|
|
|
|
2021-01-28 21:07:45 +03:00
|
|
|
describe('Routes', function () {
|
|
|
|
it('should error serving webhook endpoint without any parameters', async function () {
|
|
|
|
await request.post('/members/webhooks/stripe')
|
|
|
|
.expect(400);
|
2019-11-21 06:01:24 +03:00
|
|
|
});
|
|
|
|
|
2021-01-28 21:07:45 +03:00
|
|
|
it('should error when invalid member token is passed into session', async function () {
|
|
|
|
await request.get('/members/api/session')
|
|
|
|
.expect(400);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return no content when removing member sessions', async function () {
|
|
|
|
await request.del('/members/api/session')
|
|
|
|
.expect(204);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error for invalid member token on member data endpoint', async function () {
|
|
|
|
await request.get('/members/api/member')
|
2021-03-01 19:03:56 +03:00
|
|
|
.expect(401);
|
2021-01-28 21:07:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should serve member site endpoint', async function () {
|
|
|
|
await request.get('/members/api/site')
|
|
|
|
.expect(200);
|
2019-11-21 06:01:24 +03:00
|
|
|
});
|
|
|
|
|
2021-01-28 21:07:45 +03:00
|
|
|
it('should error for invalid data on member magic link endpoint', async function () {
|
|
|
|
await request.post('/members/api/send-magic-link')
|
|
|
|
.expect(400);
|
|
|
|
});
|
2019-11-21 06:01:24 +03:00
|
|
|
|
2021-01-28 21:07:45 +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')
|
|
|
|
.expect(400);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error for invalid data on members create update session endpoint', async function () {
|
|
|
|
await request.post('/members/api/create-stripe-update-session')
|
|
|
|
.expect(400);
|
|
|
|
});
|
2019-11-21 06:01:24 +03:00
|
|
|
|
2021-01-28 21:07:45 +03:00
|
|
|
it('should error for invalid data on members subscription endpoint', async function () {
|
|
|
|
await request.put('/members/api/subscriptions/123')
|
|
|
|
.expect(400);
|
2019-11-21 06:01:24 +03:00
|
|
|
});
|
|
|
|
|
2021-01-28 21:07:45 +03:00
|
|
|
it('should serve theme 404 on members endpoint', async function () {
|
|
|
|
await request.get('/members/')
|
|
|
|
.expect(404)
|
|
|
|
.expect('Content-Type', 'text/html; charset=utf-8');
|
2019-11-21 06:01:24 +03:00
|
|
|
});
|
|
|
|
|
2021-01-28 21:07:45 +03:00
|
|
|
it('should redirect invalid token on members endpoint', async function () {
|
|
|
|
await request.get('/members/?token=abc&action=signup')
|
|
|
|
.expect(302)
|
|
|
|
.expect('Location', '/?action=signup&success=false');
|
2019-11-21 06:01:24 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|