mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
refs https://github.com/TryGhost/Toolbox/issues/280 - The Accept-Version/Content-Version header handling is shared between all APIs and should not structurally belong to any of the admin/content/members folders
83 lines
2.8 KiB
JavaScript
83 lines
2.8 KiB
JavaScript
const {agentProvider, matchers} = require('../../utils/e2e-framework');
|
|
const {anyErrorId, anyString, stringMatching} = matchers;
|
|
|
|
describe('API Versioning', function () {
|
|
let agent;
|
|
|
|
before(async function () {
|
|
agent = await agentProvider.getAdminAPIAgent();
|
|
});
|
|
|
|
it('responds with no content version header when accept version header is NOT PRESENT', async function () {
|
|
await agent
|
|
.get('site/')
|
|
.matchBodySnapshot({
|
|
site: {
|
|
version: stringMatching(/\d+\.\d+/)
|
|
}
|
|
})
|
|
.matchHeaderSnapshot({
|
|
etag: anyString
|
|
});
|
|
});
|
|
|
|
it('responds with current content version header when requested version is BEHIND current version and CAN respond', async function () {
|
|
await agent
|
|
.get('site/')
|
|
.header('Accept-Version', 'v3.0')
|
|
.matchBodySnapshot({
|
|
site: {
|
|
version: stringMatching(/\d+\.\d+/)
|
|
}
|
|
})
|
|
.matchHeaderSnapshot({
|
|
etag: anyString,
|
|
'content-version': stringMatching(/v\d+\.\d+/)
|
|
});
|
|
});
|
|
|
|
it('responds with current content version header when requested version is AHEAD and CAN respond', async function () {
|
|
await agent
|
|
.get('site/')
|
|
.header('Accept-Version', 'v999.5')
|
|
.matchBodySnapshot({
|
|
site: {
|
|
version: stringMatching(/\d+\.\d+/)
|
|
}
|
|
})
|
|
.matchHeaderSnapshot({
|
|
etag: anyString,
|
|
'content-version': stringMatching(/v\d+\.\d+/)
|
|
});
|
|
});
|
|
|
|
it('responds with error current content version header when requested version is AHEAD and CANNOT respond', async function () {
|
|
// CASE 2: If accept-version is behind, send a 406 & tell them the client needs updating.
|
|
await agent
|
|
.get('removed_endpoint')
|
|
.header('Accept-Version', 'v999.1')
|
|
.matchHeaderSnapshot({
|
|
etag: anyString
|
|
})
|
|
.matchBodySnapshot({
|
|
errors: [{
|
|
id: anyErrorId
|
|
}]
|
|
});
|
|
});
|
|
|
|
it('responds with error current content version header when requested version is BEHIND and CANNOT respond', async function () {
|
|
// CASE 2: If accept-version is behind, send a 406 & tell them the client needs updating.
|
|
await agent
|
|
.get('removed_endpoint')
|
|
.header('Accept-Version', 'v3.1')
|
|
.matchHeaderSnapshot({
|
|
etag: anyString
|
|
})
|
|
.matchBodySnapshot({
|
|
errors: [{
|
|
id: anyErrorId
|
|
}]
|
|
});
|
|
});
|
|
});
|