0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Added test coverage for Content APIs versioning support

refs https://github.com/TryGhost/Toolbox/issues/280

- Some additional coverage showcasing the versioning support is universal across APIs
This commit is contained in:
Naz 2022-04-08 17:30:10 +08:00
parent 313ab2a13f
commit eee8f364de
2 changed files with 260 additions and 72 deletions

View file

@ -1,5 +1,164 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`API Versioning Content API responds with current content version header when requested version is BEHIND current version and CAN respond 1: [body] 1`] = `
Object {
"meta": Object {},
"settings": Object {
"accent_color": "#FF1A75",
"codeinjection_foot": null,
"codeinjection_head": null,
"cover_image": "https://static.ghost.org/v4.0.0/images/publication-cover.jpg",
"description": "Thoughts, stories and ideas",
"facebook": "ghost",
"icon": null,
"lang": "en",
"locale": "en",
"logo": null,
"members_support_address": "noreply",
"meta_description": null,
"meta_title": null,
"navigation": Array [
Object {
"label": "Home",
"url": "/",
},
Object {
"label": "About",
"url": "/about/",
},
Object {
"label": "Collection",
"url": "/tag/getting-started/",
},
Object {
"label": "Author",
"url": "/author/ghost/",
},
Object {
"label": "Portal",
"url": "/portal/",
},
],
"og_description": null,
"og_image": null,
"og_title": null,
"secondary_navigation": Array [
Object {
"label": "Data & privacy",
"url": "/privacy/",
},
Object {
"label": "Contact",
"url": "/contact/",
},
Object {
"label": "Contribute →",
"url": "/contribute/",
},
],
"timezone": "Etc/UTC",
"title": "Ghost",
"twitter": "@ghost",
"twitter_description": null,
"twitter_image": null,
"twitter_title": null,
"url": "http://127.0.0.1:2369/",
},
}
`;
exports[`API Versioning Content API responds with current content version header when requested version is BEHIND current version and CAN respond 2: [headers] 1`] = `
Object {
"access-control-allow-origin": "*",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "942",
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": "W/\\"3ae-FBGPtlUjSvGtTGLOj2sW5Rbn33s\\"",
"vary": "Accept-Encoding",
"x-powered-by": "Express",
}
`;
exports[`API Versioning Content API responds with no content version header when accept version header is NOT PRESENT 1: [body] 1`] = `
Object {
"meta": Object {},
"settings": Object {
"accent_color": "#FF1A75",
"codeinjection_foot": null,
"codeinjection_head": null,
"cover_image": "https://static.ghost.org/v4.0.0/images/publication-cover.jpg",
"description": "Thoughts, stories and ideas",
"facebook": "ghost",
"icon": null,
"lang": "en",
"locale": "en",
"logo": null,
"members_support_address": "noreply",
"meta_description": null,
"meta_title": null,
"navigation": Array [
Object {
"label": "Home",
"url": "/",
},
Object {
"label": "About",
"url": "/about/",
},
Object {
"label": "Collection",
"url": "/tag/getting-started/",
},
Object {
"label": "Author",
"url": "/author/ghost/",
},
Object {
"label": "Portal",
"url": "/portal/",
},
],
"og_description": null,
"og_image": null,
"og_title": null,
"secondary_navigation": Array [
Object {
"label": "Data & privacy",
"url": "/privacy/",
},
Object {
"label": "Contact",
"url": "/contact/",
},
Object {
"label": "Contribute →",
"url": "/contribute/",
},
],
"timezone": "Etc/UTC",
"title": "Ghost",
"twitter": "@ghost",
"twitter_description": null,
"twitter_image": null,
"twitter_title": null,
"url": "http://127.0.0.1:2369/",
},
}
`;
exports[`API Versioning Content API responds with no content version header when accept version header is NOT PRESENT 2: [headers] 1`] = `
Object {
"access-control-allow-origin": "*",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "942",
"content-type": "application/json; charset=utf-8",
"etag": "W/\\"3ae-FBGPtlUjSvGtTGLOj2sW5Rbn33s\\"",
"vary": "Accept-Encoding",
"x-powered-by": "Express",
}
`;
exports[`API Versioning responds with current content version header when requested version is AHEAD and CAN respond 1: [body] 1`] = ` exports[`API Versioning responds with current content version header when requested version is AHEAD and CAN respond 1: [body] 1`] = `
Object { Object {
"site": Object { "site": Object {

View file

@ -1,83 +1,112 @@
const {agentProvider, matchers} = require('../../utils/e2e-framework'); const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
const {anyErrorId, anyString, stringMatching} = matchers; const {anyErrorId, anyString, stringMatching} = matchers;
describe('API Versioning', function () { describe('API Versioning', function () {
let agent; describe('Admin API', function () {
let agentAdminAPI;
before(async function () { before(async function () {
agent = await agentProvider.getAdminAPIAgent(); agentAdminAPI = await agentProvider.getAdminAPIAgent();
});
it('responds with no content version header when accept version header is NOT PRESENT', async function () {
await agentAdminAPI
.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 agentAdminAPI
.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 agentAdminAPI
.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 agentAdminAPI
.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 agentAdminAPI
.get('removed_endpoint')
.header('Accept-Version', 'v3.1')
.matchHeaderSnapshot({
etag: anyString
})
.matchBodySnapshot({
errors: [{
id: anyErrorId
}]
});
});
}); });
it('responds with no content version header when accept version header is NOT PRESENT', async function () { describe('Content API', function () {
await agent let agentContentAPI;
.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 () { before(async function () {
await agent agentContentAPI = await agentProvider.getContentAPIAgent();
.get('site/') await fixtureManager.init('api_keys');
.header('Accept-Version', 'v3.0') agentContentAPI.authenticate();
.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 () { it('responds with no content version header when accept version header is NOT PRESENT', async function () {
await agent await agentContentAPI.get('settings/')
.get('site/') .expectStatus(200)
.header('Accept-Version', 'v999.5') .matchHeaderSnapshot()
.matchBodySnapshot({ .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 () { it('responds with current content version header when requested version is BEHIND current version and CAN respond', async function () {
// CASE 2: If accept-version is behind, send a 406 & tell them the client needs updating. await agentContentAPI.get('settings/')
await agent .header('Accept-Version', 'v3.0')
.get('removed_endpoint') .expectStatus(200)
.header('Accept-Version', 'v999.1') .matchHeaderSnapshot({
.matchHeaderSnapshot({ 'content-version': stringMatching(/v\d+\.\d+/)
etag: anyString })
}) .matchBodySnapshot();
.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
}]
});
}); });
}); });