mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
Added specific newsletters and attribution tests
refs https://github.com/TryGhost/Arch/issues/87 - Round 2 for the previous commit. Removes use of `anyArray` for all - Using `anyArray` in snapshot test is an anti-pattern which leads to leaking output fields unintentionally when the API changes. - Adding these fixes is fundamental work before changing the output of 'member.newsletters' property
This commit is contained in:
parent
4999523289
commit
2e84cdca36
File diff suppressed because it is too large
Load Diff
@ -147,20 +147,29 @@ const memberMatcherShallowIncludes = {
|
||||
created_at: anyISODateTime,
|
||||
updated_at: anyISODateTime,
|
||||
subscriptions: anyArray,
|
||||
labels: anyArray,
|
||||
newsletters: anyArray
|
||||
labels: anyArray
|
||||
};
|
||||
|
||||
const buildMemberMatcherShallowIncludesWithTiers = (tiersCount) => {
|
||||
let tiers = anyArray;
|
||||
if (tiersCount) {
|
||||
tiers = new Array(tiers).fill(tierMatcher);
|
||||
/**
|
||||
*
|
||||
* @param {number} tiersCount
|
||||
* @param {number} newsletterCount
|
||||
* @returns
|
||||
*/
|
||||
const buildMemberMatcherShallowIncludesWithTiers = (tiersCount, newsletterCount) => {
|
||||
const matcher = {
|
||||
...memberMatcherShallowIncludes
|
||||
};
|
||||
|
||||
if (tiersCount !== undefined) {
|
||||
matcher.tiers = new Array(tiersCount).fill(tierMatcher);
|
||||
}
|
||||
|
||||
return {
|
||||
...memberMatcherShallowIncludes,
|
||||
tiers
|
||||
};
|
||||
if (newsletterCount !== undefined) {
|
||||
matcher.newsletters = new Array(newsletterCount).fill(newsletterSnapshot);
|
||||
}
|
||||
|
||||
return matcher;
|
||||
};
|
||||
|
||||
let agent;
|
||||
@ -250,7 +259,7 @@ describe('Members API - member attribution', function () {
|
||||
.get(`/members/${member.id}/`)
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 2))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -293,7 +302,7 @@ describe('Members API - member attribution', function () {
|
||||
.get(`/members/${member.id}/`)
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 2))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -336,7 +345,7 @@ describe('Members API - member attribution', function () {
|
||||
.get(`/members/${member.id}/`)
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 2))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -379,7 +388,7 @@ describe('Members API - member attribution', function () {
|
||||
.get(`/members/${member.id}/`)
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 2))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -419,7 +428,7 @@ describe('Members API - member attribution', function () {
|
||||
.get(`/members/${member.id}/`)
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 2))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -462,7 +471,7 @@ describe('Members API - member attribution', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe.only('Members API', function () {
|
||||
describe('Members API', function () {
|
||||
let newsletters;
|
||||
let emailMockReceiver;
|
||||
|
||||
@ -490,7 +499,16 @@ describe.only('Members API', function () {
|
||||
.get('/members/')
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(8).fill(memberMatcherShallowIncludes)
|
||||
members: [
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 0),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 0),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 2),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1)
|
||||
]
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -503,7 +521,7 @@ describe.only('Members API', function () {
|
||||
.get('/members/?filter=label:label-1')
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(undefined, 1))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -516,7 +534,11 @@ describe.only('Members API', function () {
|
||||
.get('/members/?filter=signup:' + fixtureManager.get('posts', 0).id)
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(3).fill(memberMatcherShallowIncludes)
|
||||
members: [
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 0),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1)
|
||||
]
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -529,7 +551,7 @@ describe.only('Members API', function () {
|
||||
.get('/members/?filter=conversion:' + fixtureManager.get('posts', 0).id)
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(undefined, 1))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -542,7 +564,7 @@ describe.only('Members API', function () {
|
||||
.get('/members/?search=member1')
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(undefined, 1))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -555,7 +577,13 @@ describe.only('Members API', function () {
|
||||
.get('/members/?filter=status:paid')
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(5).fill(memberMatcherShallowIncludes)
|
||||
members: [
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 0),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 0),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 2),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1)
|
||||
]
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -569,7 +597,12 @@ describe.only('Members API', function () {
|
||||
.get(`/members/?filter=tier_id:[${products.toJSON().id}]`)
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(4).fill(memberMatcherShallowIncludes)
|
||||
members: [
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 0),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 2),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1)
|
||||
]
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -582,7 +615,7 @@ describe.only('Members API', function () {
|
||||
.get(`/members/?filter=name:~'Venkman'`)
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(undefined, 0))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -595,7 +628,13 @@ describe.only('Members API', function () {
|
||||
.get('/members/?filter=status:paid&include=emailRecipients')
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(5).fill(memberMatcherShallowIncludes)
|
||||
members: [
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 0),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 0),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 2),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1)
|
||||
]
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -613,7 +652,16 @@ describe.only('Members API', function () {
|
||||
'content-version': anyContentVersion
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
members: new Array(8).fill(memberMatcherShallowIncludes)
|
||||
members: [
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 2),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 0),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 0)
|
||||
]
|
||||
})
|
||||
.expect(({body}) => {
|
||||
const {members} = body;
|
||||
@ -629,7 +677,16 @@ describe.only('Members API', function () {
|
||||
'content-version': anyContentVersion
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
members: new Array(8).fill(memberMatcherShallowIncludes)
|
||||
members: [
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 2),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 0),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 0)
|
||||
]
|
||||
})
|
||||
.expect(({body}) => {
|
||||
const {members} = body;
|
||||
@ -642,7 +699,7 @@ describe.only('Members API', function () {
|
||||
.get('members/?search=egg')
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: [memberMatcherShallowIncludes]
|
||||
members: [buildMemberMatcherShallowIncludesWithTiers(undefined, 1)]
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -655,7 +712,7 @@ describe.only('Members API', function () {
|
||||
.get('members/?search=MEMBER2')
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: [memberMatcherShallowIncludes]
|
||||
members: [buildMemberMatcherShallowIncludesWithTiers(undefined, 1)]
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -668,7 +725,7 @@ describe.only('Members API', function () {
|
||||
.get('members/?search=egon&paid=true')
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: [memberMatcherShallowIncludes]
|
||||
members: [buildMemberMatcherShallowIncludesWithTiers(undefined, 1)]
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -696,7 +753,7 @@ describe.only('Members API', function () {
|
||||
.get(`/members/${testUtils.DataGenerator.Content.members[0].id}/`)
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 1))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -709,7 +766,7 @@ describe.only('Members API', function () {
|
||||
.get(`/members/${testUtils.DataGenerator.Content.members[0].id}/?include=email_recipients`)
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 1))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -722,7 +779,7 @@ describe.only('Members API', function () {
|
||||
.get(`/members/${testUtils.DataGenerator.Content.members[0].id}/?include=tiers`)
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers())
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 1))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -746,7 +803,7 @@ describe.only('Members API', function () {
|
||||
.body({members: [member]})
|
||||
.expectStatus(201)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 0))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -796,7 +853,7 @@ describe.only('Members API', function () {
|
||||
.body({members: [member]})
|
||||
.expectStatus(201)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 2))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -818,7 +875,7 @@ describe.only('Members API', function () {
|
||||
.body({members: [memberFailLimit]})
|
||||
.expectStatus(201)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 2))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -1034,7 +1091,7 @@ describe.only('Members API', function () {
|
||||
.body({members: [initialMember]})
|
||||
.expectStatus(201)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 1))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -1049,7 +1106,7 @@ describe.only('Members API', function () {
|
||||
.body({members: [compedPayload]})
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(1))
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(1, 1))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -1696,7 +1753,7 @@ describe.only('Members API', function () {
|
||||
.body({members: [memberToChange]})
|
||||
.expectStatus(201)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 1))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -1728,7 +1785,7 @@ describe.only('Members API', function () {
|
||||
.body({members: [memberChanged]})
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 0))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -1827,7 +1884,7 @@ describe.only('Members API', function () {
|
||||
.body({members: [memberToChange]})
|
||||
.expectStatus(201)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 1))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -1860,7 +1917,7 @@ describe.only('Members API', function () {
|
||||
.body({members: [memberChanged]})
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 1))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -1961,7 +2018,7 @@ describe.only('Members API', function () {
|
||||
.body({members: [memberToCreate]})
|
||||
.expectStatus(201)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 2))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -2056,7 +2113,7 @@ describe.only('Members API', function () {
|
||||
.body({members: [member]})
|
||||
.expectStatus(201)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(1).fill(memberMatcherShallowIncludes)
|
||||
members: new Array(1).fill(buildMemberMatcherShallowIncludesWithTiers(0, 2))
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -2263,7 +2320,11 @@ describe.only('Members API', function () {
|
||||
.get('/members/?filter=newsletters:weekly-newsletter')
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(3).fill(memberMatcherShallowIncludes)
|
||||
members: [
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 2),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(undefined, 2)
|
||||
]
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
@ -2276,7 +2337,16 @@ describe.only('Members API', function () {
|
||||
.get('/members/?include=tiers&filter=tier:default-product')
|
||||
.expectStatus(200)
|
||||
.matchBodySnapshot({
|
||||
members: new Array(8).fill(buildMemberMatcherShallowIncludesWithTiers())
|
||||
members: [
|
||||
buildMemberMatcherShallowIncludesWithTiers(1, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(1, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(1, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(1, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(1, 1),
|
||||
buildMemberMatcherShallowIncludesWithTiers(1, 0),
|
||||
buildMemberMatcherShallowIncludesWithTiers(1, 2),
|
||||
buildMemberMatcherShallowIncludesWithTiers(1, 1)
|
||||
]
|
||||
})
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
|
Loading…
Reference in New Issue
Block a user