mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Updated tests for custom welcome page redirects (#14288)
Welcome pages are now moved as a property of individual tiers instead of global property on settings. Since we removed the alpha flag for new welcome page behavior, tests had to be updated to test the flow against new behavior.
This commit is contained in:
parent
7c105d9669
commit
9794945549
1 changed files with 34 additions and 12 deletions
|
@ -5,14 +5,20 @@ const urlUtils = require('../../../../../core/shared/url-utils');
|
|||
const membersService = require('../../../../../core/server/services/members');
|
||||
const membersMiddleware = require('../../../../../core/server/services/members/middleware');
|
||||
const settingsCache = require('../../../../../core/shared/settings-cache');
|
||||
const models = require('../../../../../core/server/models');
|
||||
|
||||
describe('Members Service Middleware', function () {
|
||||
describe('createSessionFromMagicLink', function () {
|
||||
let oldSSR;
|
||||
let oldProductModel;
|
||||
let req;
|
||||
let res;
|
||||
let next;
|
||||
|
||||
before(function () {
|
||||
models.init();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
req = {};
|
||||
res = {};
|
||||
|
@ -26,12 +32,19 @@ describe('Members Service Middleware', function () {
|
|||
exchangeTokenForSession: sinon.stub()
|
||||
};
|
||||
|
||||
// Stub the members Service, handle this in separate tests
|
||||
oldProductModel = models.Product;
|
||||
models.Product = {
|
||||
findOne: sinon.stub()
|
||||
};
|
||||
|
||||
sinon.stub(urlUtils, 'getSubdir').returns('/blah');
|
||||
sinon.stub(urlUtils, 'getSiteUrl').returns('https://site.com/blah');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
membersService.ssr = oldSSR;
|
||||
models.Product = oldProductModel;
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
|
@ -52,7 +65,14 @@ describe('Members Service Middleware', function () {
|
|||
req.query = {token: 'test', action: 'signup'};
|
||||
|
||||
// Fake token handling success
|
||||
membersService.ssr.exchangeTokenForSession.resolves();
|
||||
membersService.ssr.exchangeTokenForSession.resolves({
|
||||
subscriptions: [{
|
||||
status: 'active',
|
||||
tier: {
|
||||
welcome_page_url: ''
|
||||
}
|
||||
}]
|
||||
});
|
||||
|
||||
// Call the middleware
|
||||
await membersMiddleware.createSessionFromMagicLink(req, res, next);
|
||||
|
@ -79,17 +99,20 @@ describe('Members Service Middleware', function () {
|
|||
res.redirect.firstCall.args[0].should.eql('/blah/?action=signup&success=false');
|
||||
});
|
||||
|
||||
it('redirects to custom redirect on signup', async function () {
|
||||
it('redirects free member to custom redirect on signup', async function () {
|
||||
req.url = '/members?token=test&action=signup';
|
||||
req.query = {token: 'test', action: 'signup'};
|
||||
|
||||
sinon.stub(settingsCache, 'get')
|
||||
.withArgs('members_free_signup_redirect')
|
||||
.returns('https://custom.com/redirect');
|
||||
|
||||
// Fake token handling failure
|
||||
membersService.ssr.exchangeTokenForSession.resolves();
|
||||
|
||||
// Fake welcome page for free tier
|
||||
models.Product.findOne.resolves({
|
||||
get: () => {
|
||||
return 'https://custom.com/redirect/';
|
||||
}
|
||||
});
|
||||
|
||||
// Call the middleware
|
||||
await membersMiddleware.createSessionFromMagicLink(req, res, next);
|
||||
|
||||
|
@ -99,18 +122,17 @@ describe('Members Service Middleware', function () {
|
|||
res.redirect.firstCall.args[0].should.eql('https://custom.com/redirect/');
|
||||
});
|
||||
|
||||
it('redirects to custom redirect on signup', async function () {
|
||||
it('redirects paid member to custom redirect on signup', async function () {
|
||||
req.url = '/members?token=test&action=signup';
|
||||
req.query = {token: 'test', action: 'signup'};
|
||||
|
||||
sinon.stub(settingsCache, 'get')
|
||||
.withArgs('members_paid_signup_redirect')
|
||||
.returns('https://custom.com/paid');
|
||||
|
||||
// Fake token handling failure
|
||||
membersService.ssr.exchangeTokenForSession.resolves({
|
||||
subscriptions: [{
|
||||
status: 'active'
|
||||
status: 'active',
|
||||
tier: {
|
||||
welcome_page_url: 'https://custom.com/paid'
|
||||
}
|
||||
}]
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue