mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-27 10:42:45 +03:00
Handled newsletter data for member api
refs https://github.com/TryGhost/Team/issues/1469 - Added newsletter data handling to member BREAD service - Allowed updating newsletter data for a member
This commit is contained in:
parent
437d6830aa
commit
cc7c51e140
@ -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",
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
@ -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,
|
||||
|
24
yarn.lock
24
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"
|
||||
|
Loading…
Reference in New Issue
Block a user