2022-04-25 22:11:27 +03:00
|
|
|
const {agentProvider, mockManager, fixtureManager, matchers} = require('../../utils/e2e-framework');
|
2023-03-10 14:53:35 +03:00
|
|
|
const {anyContentVersion, anyEtag, anyObjectId, anyUuid, anyISODateTime, anyArray} = matchers;
|
2022-04-25 22:11:27 +03:00
|
|
|
|
|
|
|
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({
|
2023-01-17 14:56:29 +03:00
|
|
|
'content-version': anyContentVersion,
|
2022-04-25 22:11:27 +03:00
|
|
|
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({
|
2023-01-17 14:56:29 +03:00
|
|
|
'content-version': anyContentVersion,
|
2022-04-25 22:11:27 +03:00
|
|
|
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({
|
2023-01-17 14:56:29 +03:00
|
|
|
'content-version': anyContentVersion,
|
2022-04-25 22:11:27 +03:00
|
|
|
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({
|
2023-01-17 14:56:29 +03:00
|
|
|
'content-version': anyContentVersion,
|
2022-04-25 22:11:27 +03:00
|
|
|
etag: anyEtag
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|