mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Swapped setup to use tiers API endpoint
refs: https://github.com/TryGhost/Team/issues/1145 - the products endpoint is going away in favour of tiers
This commit is contained in:
parent
b6d9389124
commit
a58ac016be
2 changed files with 19 additions and 19 deletions
|
@ -108,8 +108,8 @@ async function doSettings(data, settingsAPI) {
|
|||
}
|
||||
|
||||
// Update names for default product and newsletter to site title
|
||||
async function doProductAndNewsletter(data, api) {
|
||||
const {products: productsAPI, newsletters: newslettersAPI} = api;
|
||||
async function doTiersAndNewsletter(data, api) {
|
||||
const {tiers: tiersAPI, newsletters: newslettersAPI} = api;
|
||||
const context = {context: {user: data.user.id}};
|
||||
const user = data.user;
|
||||
const blogTitle = data.userData.blogTitle;
|
||||
|
@ -118,16 +118,16 @@ async function doProductAndNewsletter(data, api) {
|
|||
return user;
|
||||
}
|
||||
try {
|
||||
const productPage = await productsAPI.browse({limit: 'all'});
|
||||
const tierPage = await tiersAPI.browse({limit: 'all'});
|
||||
const newsletterPage = await newslettersAPI.browse({limit: 'all'});
|
||||
|
||||
const defaultProduct = productPage.products.find(p => p.slug === 'default-product');
|
||||
const defaultTier = tierPage.tiers.find(p => p.slug === 'default-product');
|
||||
const defaultNewsletter = newsletterPage.newsletters.find(p => p.slug === 'default-newsletter');
|
||||
|
||||
if (defaultProduct) {
|
||||
await productsAPI.edit({products: [{
|
||||
if (defaultTier) {
|
||||
await tiersAPI.edit({tiers: [{
|
||||
name: blogTitle.trim()
|
||||
}]}, {context: context.context, id: defaultProduct.id});
|
||||
}]}, {context: context.context, id: defaultTier.id});
|
||||
}
|
||||
|
||||
if (defaultNewsletter) {
|
||||
|
@ -231,7 +231,7 @@ module.exports = {
|
|||
assertSetupCompleted: assertSetupCompleted,
|
||||
setupUser: setupUser,
|
||||
doSettings: doSettings,
|
||||
doProductAndNewsletter: doProductAndNewsletter,
|
||||
doProductAndNewsletter: doTiersAndNewsletter,
|
||||
installTheme: installTheme,
|
||||
doFixtures: doFixtures,
|
||||
sendWelcomeEmail: sendWelcomeEmail
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const {doProductAndNewsletter} = require('../../../../../core/server/services/auth/setup');
|
||||
const {doProductAndNewsletter: doTierAndNewsletter} = require('../../../../../core/server/services/auth/setup');
|
||||
const sinon = require('sinon');
|
||||
|
||||
describe('Auth Service: setup', function () {
|
||||
|
@ -8,10 +8,10 @@ describe('Auth Service: setup', function () {
|
|||
|
||||
describe('doProductAndNewsletter', function () {
|
||||
it('updates default product and newsletter name', async function () {
|
||||
const productEditStub = sinon.stub().resolves();
|
||||
const tierEditStub = sinon.stub().resolves();
|
||||
const newsletterEditStub = sinon.stub().resolves();
|
||||
const productBrowseStub = sinon.stub().resolves({
|
||||
products: [
|
||||
const tierBrowseStub = sinon.stub().resolves({
|
||||
tiers: [
|
||||
{
|
||||
id: 'product-1',
|
||||
slug: 'free'
|
||||
|
@ -34,16 +34,16 @@ describe('Auth Service: setup', function () {
|
|||
}
|
||||
]
|
||||
});
|
||||
let productsApi = {
|
||||
browse: productBrowseStub,
|
||||
edit: productEditStub
|
||||
let tiersAPI = {
|
||||
browse: tierBrowseStub,
|
||||
edit: tierEditStub
|
||||
};
|
||||
let newslettersApi = {
|
||||
browse: newsletterBrowseStub,
|
||||
edit: newsletterEditStub
|
||||
};
|
||||
const api = {
|
||||
products: productsApi,
|
||||
tiers: tiersAPI,
|
||||
newsletters: newslettersApi
|
||||
};
|
||||
let data = {
|
||||
|
@ -54,10 +54,10 @@ describe('Auth Service: setup', function () {
|
|||
blogTitle: 'Test Blog'
|
||||
}
|
||||
};
|
||||
await doProductAndNewsletter(data, api);
|
||||
await doTierAndNewsletter(data, api);
|
||||
sinon.assert.calledOnceWithExactly(
|
||||
productEditStub,
|
||||
{products: [{name: 'Test Blog'}]},
|
||||
tierEditStub,
|
||||
{tiers: [{name: 'Test Blog'}]},
|
||||
{context: {user: 'user-1'}, id: 'product-2'}
|
||||
);
|
||||
sinon.assert.calledOnceWithExactly(
|
||||
|
|
Loading…
Add table
Reference in a new issue