Ghost/test/e2e-api/admin/members-newsletters.test.js
Hannah Wolfe a703185497
Fixed mockLabs disabling all other flags (#14621)
refs TryGhost/Team#1566

- Mocking a labs flag (regardless of enabled/disabled) currently has a side effect of setting any other flag to undefined.
- This meant in a test where we set a flag e.g. members-importer where we set multipleProducts, multipleNewsletters is always disabled
- This fix preserves the default state of all labs flags that are not mocked so that labs behaves how we expect
- Removed usage of GA flags in tests
- Removed tests that had GA flags disabled

Co-authored-by: Simon Backx <simon@ghost.org>
2022-04-28 10:55:20 +02:00

91 lines
2.8 KiB
JavaScript

const {agentProvider, mockManager, fixtureManager, matchers} = require('../../utils/e2e-framework');
const {anyEtag, anyObjectId, anyUuid, anyISODateTime, anyISODate, anyString, anyArray, anyLocationFor, anyErrorId} = matchers;
const memberMatcherShallowIncludesForNewsletters = {
id: anyObjectId,
uuid: anyUuid,
created_at: anyISODateTime,
updated_at: anyISODateTime,
subscriptions: anyArray,
labels: anyArray,
newsletters: anyArray
};
let agent;
describe('Members API - With Newsletters', function () {
before(async function () {
agent = await agentProvider.getAdminAPIAgent();
await fixtureManager.init('newsletters', 'members:newsletters');
await agent.loginAsOwner();
});
afterEach(function () {
mockManager.restore();
});
// List Members
it('Can fetch members who are subscribed', async function () {
await agent
.get('/members/?filter=newsletters.status:active')
.expectStatus(200)
.matchBodySnapshot({
members: new Array(6).fill(memberMatcherShallowIncludesForNewsletters)
})
.matchHeaderSnapshot({
etag: anyEtag
});
});
it('Can fetch members who are NOT subscribed', async function () {
await agent
.get('/members/?filter=newsletters.status:-active')
.expectStatus(200)
.matchBodySnapshot({
members: new Array(2).fill(memberMatcherShallowIncludesForNewsletters)
})
.matchHeaderSnapshot({
etag: anyEtag
});
});
});
describe('Members API - With Newsletters - compat mode', function () {
before(async function () {
agent = await agentProvider.getAdminAPIAgent();
await fixtureManager.init('newsletters', 'members:newsletters');
await agent.loginAsOwner();
});
afterEach(function () {
mockManager.restore();
});
// List Members
it('Can fetch members who are subscribed', async function () {
await agent
.get('/members/?filter=subscribed:true')
.expectStatus(200)
.matchBodySnapshot({
members: new Array(6).fill(memberMatcherShallowIncludesForNewsletters)
})
.matchHeaderSnapshot({
etag: anyEtag
});
});
it('Can fetch members who are NOT subscribed', async function () {
await agent
.get('/members/?filter=subscribed:false')
.expectStatus(200)
.matchBodySnapshot({
members: new Array(2).fill(memberMatcherShallowIncludesForNewsletters)
})
.matchHeaderSnapshot({
etag: anyEtag
});
});
});