mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -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:
parent
313ab2a13f
commit
eee8f364de
2 changed files with 260 additions and 72 deletions
|
@ -1,5 +1,164 @@
|
|||
// 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`] = `
|
||||
Object {
|
||||
"site": Object {
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
const {agentProvider, matchers} = require('../../utils/e2e-framework');
|
||||
const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
|
||||
const {anyErrorId, anyString, stringMatching} = matchers;
|
||||
|
||||
describe('API Versioning', function () {
|
||||
let agent;
|
||||
describe('Admin API', function () {
|
||||
let agentAdminAPI;
|
||||
|
||||
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 agent
|
||||
await agentAdminAPI
|
||||
.get('site/')
|
||||
.matchBodySnapshot({
|
||||
site: {
|
||||
|
@ -22,7 +23,7 @@ describe('API Versioning', function () {
|
|||
});
|
||||
|
||||
it('responds with current content version header when requested version is BEHIND current version and CAN respond', async function () {
|
||||
await agent
|
||||
await agentAdminAPI
|
||||
.get('site/')
|
||||
.header('Accept-Version', 'v3.0')
|
||||
.matchBodySnapshot({
|
||||
|
@ -37,7 +38,7 @@ describe('API Versioning', function () {
|
|||
});
|
||||
|
||||
it('responds with current content version header when requested version is AHEAD and CAN respond', async function () {
|
||||
await agent
|
||||
await agentAdminAPI
|
||||
.get('site/')
|
||||
.header('Accept-Version', 'v999.5')
|
||||
.matchBodySnapshot({
|
||||
|
@ -53,7 +54,7 @@ describe('API Versioning', function () {
|
|||
|
||||
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
|
||||
await agentAdminAPI
|
||||
.get('removed_endpoint')
|
||||
.header('Accept-Version', 'v999.1')
|
||||
.matchHeaderSnapshot({
|
||||
|
@ -68,7 +69,7 @@ describe('API Versioning', function () {
|
|||
|
||||
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
|
||||
await agentAdminAPI
|
||||
.get('removed_endpoint')
|
||||
.header('Accept-Version', 'v3.1')
|
||||
.matchHeaderSnapshot({
|
||||
|
@ -81,3 +82,31 @@ describe('API Versioning', function () {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Content API', function () {
|
||||
let agentContentAPI;
|
||||
|
||||
before(async function () {
|
||||
agentContentAPI = await agentProvider.getContentAPIAgent();
|
||||
await fixtureManager.init('api_keys');
|
||||
agentContentAPI.authenticate();
|
||||
});
|
||||
|
||||
it('responds with no content version header when accept version header is NOT PRESENT', async function () {
|
||||
await agentContentAPI.get('settings/')
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot()
|
||||
.matchBodySnapshot();
|
||||
});
|
||||
|
||||
it('responds with current content version header when requested version is BEHIND current version and CAN respond', async function () {
|
||||
await agentContentAPI.get('settings/')
|
||||
.header('Accept-Version', 'v3.0')
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': stringMatching(/v\d+\.\d+/)
|
||||
})
|
||||
.matchBodySnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue