Ghost/ghost/core/test/e2e-api/admin/members-newsletters.test.js
Daniel Lockyer 9ba251238a Added Content-Version header to all API requests
refs https://github.com/TryGhost/Team/issues/2400

- we've deemed it useful to start to return `Content-Version` for all
  API requests, because it becomes useful to know which version of Ghost
  a response has come from in logs
- this should also help us detect Admin<->Ghost API mismatches, which
  was the cause of a bug recently (ref'd issue)
2023-01-18 08:38:07 +01:00

95 lines
3.0 KiB
JavaScript

const {agentProvider, mockManager, fixtureManager, matchers} = require('../../utils/e2e-framework');
const {anyContentVersion, 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({
'content-version': anyContentVersion,
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({
'content-version': anyContentVersion,
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({
'content-version': anyContentVersion,
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({
'content-version': anyContentVersion,
etag: anyEtag
});
});
});