diff --git a/package.json b/package.json index 5b8d147caf..f820bac420 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "@tryghost/logging": "2.1.2", "@tryghost/magic-link": "1.0.21", "@tryghost/member-events": "0.4.1", - "@tryghost/members-api": "5.4.1", + "@tryghost/members-api": "5.5.0", "@tryghost/members-events-service": "0.3.2", "@tryghost/members-importer": "0.5.6", "@tryghost/members-offers": "0.10.9", diff --git a/test/unit/api/canary/utils/serializers/output/members.test.js b/test/unit/api/canary/utils/serializers/output/members.test.js new file mode 100644 index 0000000000..e5435240ca --- /dev/null +++ b/test/unit/api/canary/utils/serializers/output/members.test.js @@ -0,0 +1,80 @@ +const should = require('should'); +const sinon = require('sinon'); +const testUtils = require('../../../../../../utils'); +const labs = require('../../../../../../../core/shared/labs'); +const memberSerializer = require('../../../../../../../core/server/api/canary/utils/serializers/output/members'); + +describe('Unit: canary/utils/serializers/output/members', function () { + let memberModel; + let labsStub; + beforeEach(function () { + memberModel = (data) => { + return Object.assign(data, {toJSON: sinon.stub().returns(data)}); + }; + labsStub = sinon.stub(labs, 'isSet').returns(true); + }); + + afterEach(function () { + sinon.restore(); + }); + + it('browse: includes newsletter data when flag is enabled', function () { + const apiConfig = {docName: 'members'}; + const frame = { + options: { + context: {} + } + }; + + const ctrlResponse = memberModel(testUtils.DataGenerator.forKnex.createMemberWithNewsletter()); + memberSerializer.browse({ + data: [ctrlResponse], + meta: null + }, apiConfig, frame); + should.exist(frame.response.members[0].newsletters); + }); + + it('browse: removes newsletter data when flag is disabled', function () { + labsStub.returns(false); + const apiConfig = {docName: 'members'}; + const frame = { + options: { + context: {} + } + }; + + const ctrlResponse = memberModel(testUtils.DataGenerator.forKnex.createMemberWithNewsletter()); + memberSerializer.browse({ + data: [ctrlResponse], + meta: null + }, apiConfig, frame); + should.not.exist(frame.response.members[0].newsletters); + }); + + it('read: includes newsletter data when flag is enabled', function () { + const apiConfig = {docName: 'members'}; + const frame = { + options: { + context: {} + } + }; + + const ctrlResponse = memberModel(testUtils.DataGenerator.forKnex.createMemberWithNewsletter()); + memberSerializer.read(ctrlResponse, apiConfig, frame); + should.exist(frame.response.members[0].newsletters); + }); + + it('read: removes newsletter data when flag is disabled', function () { + labsStub.returns(false); + const apiConfig = {docName: 'members'}; + const frame = { + options: { + context: {} + } + }; + + const ctrlResponse = memberModel(testUtils.DataGenerator.forKnex.createMemberWithNewsletter()); + memberSerializer.read(ctrlResponse, apiConfig, frame); + should.not.exist(frame.response.members[0].newsletters); + }); +}); diff --git a/test/utils/fixtures/data-generator.js b/test/utils/fixtures/data-generator.js index 8513819183..1a7b4d2084 100644 --- a/test/utils/fixtures/data-generator.js +++ b/test/utils/fixtures/data-generator.js @@ -897,6 +897,18 @@ DataGenerator.forKnex = (function () { }); } + function createMemberWithNewsletter(overrides) { + const newObj = _.cloneDeep(overrides); + + return _.defaults(newObj, { + id: ObjectId().toHexString(), + email: 'member@ghost.org', + newsletters: [{ + id: 'newsletter-1' + }] + }); + } + function createLabel(overrides) { const newObj = _.cloneDeep(overrides); @@ -1346,6 +1358,7 @@ DataGenerator.forKnex = (function () { createSetting, createToken, createMember, + createMemberWithNewsletter, createLabel, createMembersLabels, createMembersStripeCustomer: createBasic, diff --git a/yarn.lock b/yarn.lock index 2978e58cf8..1324dbb8f1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2022,10 +2022,10 @@ "@tryghost/domain-events" "^0.1.9" "@tryghost/member-events" "^0.4.1" -"@tryghost/members-api@5.4.1": - version "5.4.1" - resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-5.4.1.tgz#bc9f9c4c61dee186a662050aa00969325e1d3ae5" - integrity sha512-8aUQWRc7cOrpeZELdw9T1/0vvA2BSx41yMZlKG1CsOW60zt4YnwiINSlvo0QOtC7ffu59erR40H4IdhKXsMD5w== +"@tryghost/members-api@5.5.0": + version "5.5.0" + resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-5.5.0.tgz#30bf580051f8ca69aa3c31515e83a4348af97f91" + integrity sha512-Mwlt3F/bFcGqnnJ9Y4fBkTiQS7tb1++puuO1fh35BNpOL5TuEdYF9kxjkODqnseEioaeWNxigsdx2yvvzgcwPA== dependencies: "@nexes/nql" "^0.6.0" "@tryghost/debug" "^0.1.2" @@ -2037,7 +2037,7 @@ "@tryghost/member-events" "^0.4.1" "@tryghost/members-analytics-ingress" "^0.1.12" "@tryghost/members-payments" "^0.1.11" - "@tryghost/members-stripe-service" "^0.9.2" + "@tryghost/members-stripe-service" "^0.9.3" "@tryghost/tpl" "^0.1.2" "@types/jsonwebtoken" "^8.5.1" bluebird "^3.5.4" @@ -2137,6 +2137,20 @@ lodash "^4.17.21" stripe "^8.174.0" +"@tryghost/members-stripe-service@^0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@tryghost/members-stripe-service/-/members-stripe-service-0.9.3.tgz#e5f6995f77c8bbee8ba839bc6f02298c680b8057" + integrity sha512-r8n2qrUtkGLE7xAUkVYhCwpo4cfxtiPDa/MiBg9ycvRg81Azz33i9mQpZjiKJlAVn9IzsKaEfQBKioIFun0YyQ== + dependencies: + "@tryghost/debug" "^0.1.4" + "@tryghost/domain-events" "^0.1.9" + "@tryghost/errors" "^1.2.5" + "@tryghost/logging" "^2.0.5" + "@tryghost/member-events" "^0.4.1" + leaky-bucket "^2.2.0" + lodash "^4.17.21" + stripe "^8.174.0" + "@tryghost/metrics@1.0.8": version "1.0.8" resolved "https://registry.yarnpkg.com/@tryghost/metrics/-/metrics-1.0.8.tgz#01f3b9459c5fc108f5013cbbb72860dc472cb5f4"