Updated version test suite to play nicely with 5.0

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

- When eventually the major will be bumped next week the returned version will become `5.0.0` which changes the `content-length` header in all of the responses using the version from package.json
- The version number is dynamic, so it's expected the content-length to float as minor and patch versions fluctuate in 1-2 digit numbers. For lon-term easy maintenance it's best to set the content-length to any number (or maybe some sort of floating range in the future?)
This commit is contained in:
Naz 2022-05-19 13:27:40 +08:00
parent f97b141a3a
commit d2e9a98846
2 changed files with 53 additions and 34 deletions

View File

@ -18,7 +18,7 @@ exports[`API Versioning Admin API Does an internal rewrite for canary URLs with
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "167",
"content-length": StringMatching /\\\\d\\+/,
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"deprecation": "version=\\"v4\\"",
@ -63,7 +63,7 @@ exports[`API Versioning Admin API Does an internal rewrite for v3 URL + POST wit
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "521",
"content-length": StringMatching /\\\\d\\+/,
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"deprecation": "version=\\"v3\\"",
@ -94,7 +94,7 @@ exports[`API Versioning Admin API allows invalid accept-version header 2: [heade
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "167",
"content-length": StringMatching /\\\\d\\+/,
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
@ -152,7 +152,7 @@ exports[`API Versioning Admin API responds with 404 error when the resource cann
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "246",
"content-length": StringMatching /\\\\d\\+/,
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
@ -182,7 +182,7 @@ Object {
exports[`API Versioning Admin API responds with 406 for an unknown version with accept-version set ahead 2: [headers] 1`] = `
Object {
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "370",
"content-length": StringMatching /\\\\d\\+/,
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
@ -212,7 +212,7 @@ Object {
exports[`API Versioning Admin API responds with 406 for an unknown version with accept-version set behind 2: [headers] 1`] = `
Object {
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "371",
"content-length": StringMatching /\\\\d\\+/,
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
@ -239,7 +239,7 @@ exports[`API Versioning Admin API responds with current content version header w
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "167",
"content-length": StringMatching /\\\\d\\+/,
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
@ -266,7 +266,7 @@ exports[`API Versioning Admin API responds with current content version header w
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "167",
"content-length": StringMatching /\\\\d\\+/,
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
@ -297,7 +297,7 @@ exports[`API Versioning Admin API responds with error and sends email ONCE when
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "371",
"content-length": StringMatching /\\\\d\\+/,
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
@ -328,7 +328,7 @@ exports[`API Versioning Admin API responds with error and sends email ONCE when
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "371",
"content-length": StringMatching /\\\\d\\+/,
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
@ -359,7 +359,7 @@ exports[`API Versioning Admin API responds with error requested version is AHEAD
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "371",
"content-length": StringMatching /\\\\d\\+/,
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
@ -390,7 +390,7 @@ exports[`API Versioning Admin API responds with error when requested version is
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "371",
"content-length": StringMatching /\\\\d\\+/,
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
@ -417,7 +417,7 @@ exports[`API Versioning Admin API responds with no content version header when a
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "167",
"content-length": StringMatching /\\\\d\\+/,
"content-type": "application/json; charset=utf-8",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"vary": "Origin, Accept-Encoding",
@ -467,7 +467,7 @@ exports[`API Versioning Content API Does an internal rewrite with accept version
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": "552",
"content-length": StringMatching /\\\\d\\+/,
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"deprecation": "version=\\"v4\\"",
@ -562,10 +562,10 @@ exports[`API Versioning Content API responds with current content version header
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": "1235",
"content-length": StringMatching /\\\\d\\+/,
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": "W/\\"4d3-mq2QrkgGnMZ8/BMmziwONEMrvLM\\"",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"vary": "Accept-Encoding",
"x-powered-by": "Express",
}
@ -655,9 +655,9 @@ exports[`API Versioning Content API responds with no content version header when
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": "1235",
"content-length": StringMatching /\\\\d\\+/,
"content-type": "application/json; charset=utf-8",
"etag": "W/\\"4d3-mq2QrkgGnMZ8/BMmziwONEMrvLM\\"",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"vary": "Accept-Encoding",
"x-powered-by": "Express",
}

View File

@ -1,5 +1,5 @@
const {agentProvider, fixtureManager, matchers, mockManager} = require('../../utils/e2e-framework');
const {anyErrorId, stringMatching, anyObjectId, anyLocationFor, anyISODateTime, anyEtag, anyString} = matchers;
const {anyErrorId, stringMatching, anyObjectId, anyLocationFor, anyISODateTime, anyEtag, anyString, anyContentLength, anyContentVersion} = matchers;
const settingsMatcher = {
settings: {
@ -35,6 +35,7 @@ describe('API Versioning', function () {
}
})
.matchHeaderSnapshot({
'content-length': anyContentLength,
etag: anyEtag
});
});
@ -51,7 +52,8 @@ describe('API Versioning', function () {
})
.matchHeaderSnapshot({
etag: anyEtag,
'content-version': stringMatching(/v\d+\.\d+/)
'content-version': anyContentVersion,
'content-length': anyContentLength
});
});
@ -67,7 +69,8 @@ describe('API Versioning', function () {
})
.matchHeaderSnapshot({
etag: anyEtag,
'content-version': stringMatching(/v\d+\.\d+/)
'content-version': anyContentVersion,
'content-length': anyContentLength
});
});
@ -83,7 +86,8 @@ describe('API Versioning', function () {
})
.matchHeaderSnapshot({
etag: anyEtag,
'content-version': stringMatching(/v\d+\.\d+/)
'content-version': anyContentVersion,
'content-length': anyContentLength
});
});
@ -95,7 +99,8 @@ describe('API Versioning', function () {
.expectStatus(406)
.matchHeaderSnapshot({
etag: anyEtag,
'content-version': stringMatching(/v\d+\.\d+/)
'content-version': anyContentVersion,
'content-length': anyContentLength
})
.matchBodySnapshot({
errors: [{
@ -114,7 +119,8 @@ describe('API Versioning', function () {
.expectStatus(406)
.matchHeaderSnapshot({
etag: anyEtag,
'content-version': stringMatching(/v\d+\.\d+/)
'content-version': anyContentVersion,
'content-length': anyContentLength
})
.matchBodySnapshot({
errors: [{
@ -138,7 +144,8 @@ describe('API Versioning', function () {
.expectStatus(406)
.matchHeaderSnapshot({
etag: anyEtag,
'content-version': stringMatching(/v\d+\.\d+/)
'content-version': anyContentVersion,
'content-length': anyContentLength
})
.matchBodySnapshot({
errors: [{
@ -160,7 +167,8 @@ describe('API Versioning', function () {
.expectStatus(406)
.matchHeaderSnapshot({
etag: anyEtag,
'content-version': stringMatching(/v\d+\.\d+/)
'content-version': anyContentVersion,
'content-length': anyContentLength
})
.matchBodySnapshot({
errors: [{
@ -179,7 +187,8 @@ describe('API Versioning', function () {
.expectStatus(404)
.matchHeaderSnapshot({
etag: anyEtag,
'content-version': stringMatching(/v\d+\.\d+/)
'content-version': anyContentVersion,
'content-length': anyContentLength
})
.matchBodySnapshot({
errors: [{
@ -194,7 +203,8 @@ describe('API Versioning', function () {
.expectStatus(200)
.matchHeaderSnapshot({
etag: anyEtag,
'content-version': stringMatching(/v\d+\.\d+/)
'content-version': anyContentVersion,
'content-length': anyContentLength
})
.matchBodySnapshot({site: {
version: stringMatching(/\d+\.\d+/)
@ -211,7 +221,8 @@ describe('API Versioning', function () {
.matchHeaderSnapshot({
etag: anyEtag,
location: anyLocationFor('tags'),
'content-version': stringMatching(/v\d+\.\d+/)
'content-version': anyContentVersion,
'content-length': anyContentLength
})
.matchBodySnapshot({
tags: [{
@ -229,7 +240,8 @@ describe('API Versioning', function () {
.expectStatus(406)
.matchHeaderSnapshot({
etag: anyEtag,
'content-version': stringMatching(/v\d+\.\d+/)
'content-version': anyContentVersion,
'content-length': anyContentLength
})
.matchBodySnapshot({errors: [{
context: stringMatching(/Provided client accept-version v99\.0 is ahead of current Ghost version v\d+\.\d+/),
@ -244,7 +256,8 @@ describe('API Versioning', function () {
.expectStatus(406)
.matchHeaderSnapshot({
etag: anyEtag,
'content-version': stringMatching(/v\d+\.\d+/)
'content-version': anyContentVersion,
'content-length': anyContentLength
})
.matchBodySnapshot({errors: [{
context: stringMatching(/Provided client accept-version v1\.0 is behind current Ghost version v\d+\.\d+/),
@ -265,7 +278,10 @@ describe('API Versioning', function () {
it('responds with no content version header when accept version header is NOT PRESENT', async function () {
await agentContentAPI.get('settings/')
.expectStatus(200)
.matchHeaderSnapshot()
.matchHeaderSnapshot({
etag: anyEtag,
'content-length': anyContentLength
})
.matchBodySnapshot(settingsMatcher);
});
@ -274,7 +290,9 @@ describe('API Versioning', function () {
.header('Accept-Version', 'v3.0')
.expectStatus(200)
.matchHeaderSnapshot({
'content-version': stringMatching(/v\d+\.\d+/)
etag: anyEtag,
'content-version': anyContentVersion,
'content-length': anyContentLength
})
.matchBodySnapshot(settingsMatcher);
});
@ -285,7 +303,8 @@ describe('API Versioning', function () {
.expectStatus(200)
.matchHeaderSnapshot({
etag: anyEtag,
'content-version': stringMatching(/v\d+\.\d+/)
'content-version': anyContentVersion,
'content-length': anyContentLength
})
.matchBodySnapshot({
tags: [{