mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Updated portal to manage single newsletter with existing UI (#14573)
refs https://github.com/TryGhost/Team/issues/1554 - bumps portal to manage single site newsletter with old subscribe UI - adds unit test for portal site endpoint
This commit is contained in:
parent
2d36e5881b
commit
05b5059918
3 changed files with 96 additions and 5 deletions
|
@ -9,7 +9,7 @@ const settingsCache = require('../../../shared/settings-cache');
|
|||
const {formattedMemberResponse} = require('./utils');
|
||||
const labsService = require('../../../shared/labs');
|
||||
const config = require('../../../shared/config');
|
||||
const getNewslettersServiceInstance = require('../newsletters');
|
||||
const newslettersService = require('../newsletters');
|
||||
|
||||
// @TODO: This piece of middleware actually belongs to the frontend, not to the member app
|
||||
// Need to figure a way to separate these things (e.g. frontend actually talks to members API)
|
||||
|
@ -136,9 +136,7 @@ const getPortalProductPrices = async function () {
|
|||
|
||||
const getSiteNewsletters = async function () {
|
||||
try {
|
||||
const newsletterService = getNewslettersServiceInstance({NewsletterModel: models.Newsletter});
|
||||
|
||||
return await newsletterService.browse({filter: 'status:active', limit: 'all'});
|
||||
return await newslettersService.browse({filter: 'status:active', limit: 'all'});
|
||||
} catch (err) {
|
||||
logging.warn('Failed to fetch site newsletters');
|
||||
logging.warn(err.message);
|
||||
|
|
|
@ -128,7 +128,7 @@
|
|||
"emailAnalytics": true
|
||||
},
|
||||
"portal": {
|
||||
"url": "https://unpkg.com/@tryghost/portal@~1.21.0/umd/portal.min.js",
|
||||
"url": "https://unpkg.com/@tryghost/portal@~1.22.0/umd/portal.min.js",
|
||||
"version": "1.20"
|
||||
},
|
||||
"tenor": {
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
const ghostVersion = require('@tryghost/version');
|
||||
|
||||
const urlUtils = require('../../../../../core/shared/url-utils');
|
||||
const membersService = require('../../../../../core/server/services/members');
|
||||
const newslettersService = require('../../../../../core/server/services/newsletters');
|
||||
const membersMiddleware = require('../../../../../core/server/services/members/middleware');
|
||||
const settingsCache = require('../../../../../core/shared/settings-cache');
|
||||
const models = require('../../../../../core/server/models');
|
||||
const config = require('../../../../../core/shared/config');
|
||||
|
||||
describe('Members Service Middleware', function () {
|
||||
describe('createSessionFromMagicLink', function () {
|
||||
|
@ -145,4 +148,94 @@ describe('Members Service Middleware', function () {
|
|||
res.redirect.firstCall.args[0].should.eql('https://custom.com/paid/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getMemberSiteData', function () {
|
||||
let req;
|
||||
let res = {};
|
||||
let next;
|
||||
|
||||
before(function () {
|
||||
models.init();
|
||||
sinon.stub(membersService, 'config').get(() => {
|
||||
return {
|
||||
isStripeConnected: () => {
|
||||
return true;
|
||||
},
|
||||
getAllowSelfSignup: () => {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
});
|
||||
sinon.stub(membersService, 'api').get(() => {
|
||||
return {
|
||||
productRepository: {
|
||||
list: () => {
|
||||
return {
|
||||
data: []
|
||||
};
|
||||
}
|
||||
},
|
||||
getAllowSelfSignup: () => {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
});
|
||||
sinon.stub(newslettersService, 'browse').returns(Promise.resolve([]));
|
||||
sinon.stub(urlUtils, 'urlFor').returns('https://example.com');
|
||||
|
||||
sinon.stub(settingsCache, 'get');
|
||||
sinon.stub(config, 'get');
|
||||
config.get.withArgs('portal:version').returns('1.22');
|
||||
settingsCache.get.withArgs('title').returns('Ghost');
|
||||
settingsCache.get.withArgs('description').returns('site description');
|
||||
settingsCache.get.withArgs('logo').returns('/content/images/site-logo.png');
|
||||
settingsCache.get.withArgs('amp').returns(true);
|
||||
settingsCache.get.returns('');
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
req = {};
|
||||
res = {
|
||||
json: sinon.spy()
|
||||
};
|
||||
next = sinon.stub();
|
||||
sinon.stub(ghostVersion, 'safe').value('4.44');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('returns site data for portal', async function () {
|
||||
await membersMiddleware.getMemberSiteData(req, res);
|
||||
res.json.calledWith({
|
||||
site: {
|
||||
title: 'Ghost',
|
||||
description: 'site description',
|
||||
logo: '/content/images/site-logo.png',
|
||||
icon: '',
|
||||
accent_color: '',
|
||||
url: 'https://example.com',
|
||||
version: '4.44',
|
||||
portal_version: '1.22',
|
||||
free_price_name: '',
|
||||
free_price_description: '',
|
||||
allow_self_signup: true,
|
||||
members_signup_access: '',
|
||||
is_stripe_configured: true,
|
||||
portal_button: '',
|
||||
portal_name: '',
|
||||
portal_plans: '',
|
||||
portal_button_icon: '',
|
||||
portal_button_signup_text: '',
|
||||
portal_button_style: '',
|
||||
firstpromoter_id: '',
|
||||
members_support_address: 'noreply@example.com',
|
||||
prices: [],
|
||||
products: [],
|
||||
portal_products: ''
|
||||
}
|
||||
}).should.be.true();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue