From a58ac016be56115fd9307e6ea786fb6581b91b4a Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Thu, 12 May 2022 19:40:08 +0100 Subject: [PATCH] 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 --- core/server/services/auth/setup.js | 16 +++++++------- test/unit/server/services/auth/setup.test.js | 22 ++++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/core/server/services/auth/setup.js b/core/server/services/auth/setup.js index 1b98e81877..3da157d198 100644 --- a/core/server/services/auth/setup.js +++ b/core/server/services/auth/setup.js @@ -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 diff --git a/test/unit/server/services/auth/setup.test.js b/test/unit/server/services/auth/setup.test.js index 868c43ec37..3b101b3932 100644 --- a/test/unit/server/services/auth/setup.test.js +++ b/test/unit/server/services/auth/setup.test.js @@ -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(