Ghost/ghost/core/test/e2e-api/admin/stats.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

118 lines
3.6 KiB
JavaScript

const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
const {anyContentVersion, anyEtag, anyISODate, anyObjectId} = matchers;
let agent;
describe('Stats API', function () {
before(async function () {
agent = await agentProvider.getAdminAPIAgent();
await fixtureManager.init('posts', 'members');
await agent.loginAsOwner();
});
it('Can fetch member count history', async function () {
await agent
.get(`/stats/member_count`)
.expectStatus(200)
.matchBodySnapshot({
stats: [{
date: anyISODate
}]
})
.matchHeaderSnapshot({
'content-version': anyContentVersion,
etag: anyEtag
});
});
it('Can fetch MRR history', async function () {
await agent
.get(`/stats/mrr`)
.expectStatus(200)
.matchBodySnapshot({
stats: [{
date: anyISODate
}, {
date: anyISODate
}]
})
.matchHeaderSnapshot({
'content-version': anyContentVersion,
etag: anyEtag
});
});
it('Can fetch subscriptions history', async function () {
await agent
.get(`/stats/subscriptions`)
.expectStatus(200)
.matchBodySnapshot({
stats: [{
date: anyISODate,
tier: anyObjectId
}, {
date: anyISODate,
tier: anyObjectId
}],
meta: {
tiers: [anyObjectId],
totals: [{
tier: anyObjectId
}]
}
})
.matchHeaderSnapshot({
'content-version': anyContentVersion,
etag: anyEtag
});
});
describe('Post attribution stats', function () {
it('Can fetch attribution stats', async function () {
await agent
.get(`/stats/referrers/posts/${fixtureManager.get('posts', 1).id}/`)
.expectStatus(200)
.matchBodySnapshot({
stats: [
{
source: 'Direct',
signups: 2,
paid_conversions: 1
},
{
source: 'Twitter',
signups: 1,
paid_conversions: 0
}
],
meta: {}
});
});
});
describe('Referrer source history stats', function () {
it('Can fetch attribution stats', async function () {
await agent
.get(`/stats/referrers/`)
.expectStatus(200)
.matchBodySnapshot({
stats: [
{
date: anyISODate,
source: 'Direct',
signups: 4,
paid_conversions: 1
},
{
date: anyISODate,
source: 'Twitter',
signups: 4,
paid_conversions: 2
}
],
meta: {}
});
});
});
});