0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

Added expectEmptyBody assertions to e2e framework

- Updated express-test to latest version with new expectEmptyBody assertion
- Updated all the tests that used matchBodySnapshot for an empty body to use expectEmptyBody instead
- Updated all the snapshots that were affected manually, and verified running the tests works as expected
This commit is contained in:
Hannah Wolfe 2022-03-31 18:55:46 +01:00
parent 759e362a30
commit c222d1f64e
No known key found for this signature in database
GPG key ID: AB586C3B5AE5C037
16 changed files with 42 additions and 69 deletions

View file

@ -188,7 +188,7 @@
"devDependencies": {
"@lodder/grunt-postcss": "3.1.1",
"@playwright/test": "1.20.1",
"@tryghost/express-test": "0.7.1",
"@tryghost/express-test": "0.8.0",
"c8": "7.11.0",
"coffeescript": "2.6.1",
"cssnano": "5.1.5",

View file

@ -120,9 +120,7 @@ Object {
}
`;
exports[`Labels API Can destroy 3: [body] 1`] = `Object {}`;
exports[`Labels API Can destroy 4: [headers] 1`] = `
exports[`Labels API Can destroy 3: [headers] 1`] = `
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",

View file

@ -1,8 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Members Stripe Connect API can do auth 1: [body] 1`] = `Object {}`;
exports[`Members Stripe Connect API can do auth 2: [headers] 1`] = `
exports[`Members Stripe Connect API can do auth 1: [headers] 1`] = `
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",

View file

@ -746,8 +746,6 @@ Object {
}
`;
exports[`Members API Can delete a member without cancelling Stripe Subscription 1: [body] 1`] = `Object {}`;
exports[`Members API Can delete a member without cancelling Stripe Subscription 1: [headers] 1`] = `
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
@ -758,8 +756,6 @@ Object {
}
`;
exports[`Members API Can delete a member without cancelling Stripe Subscription 2: [body] 1`] = `Object {}`;
exports[`Members API Can delete a member without cancelling Stripe Subscription 2: [headers] 1`] = `
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
@ -811,9 +807,7 @@ Object {
}
`;
exports[`Members API Can destroy 3: [body] 1`] = `Object {}`;
exports[`Members API Can destroy 4: [headers] 1`] = `
exports[`Members API Can destroy 3: [headers] 1`] = `
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",
@ -823,7 +817,7 @@ Object {
}
`;
exports[`Members API Can destroy 5: [body] 1`] = `
exports[`Members API Can destroy 4: [body] 1`] = `
Object {
"errors": Array [
Object {
@ -840,7 +834,7 @@ Object {
}
`;
exports[`Members API Can destroy 6: [headers] 1`] = `
exports[`Members API Can destroy 5: [headers] 1`] = `
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",
@ -933,9 +927,7 @@ Object {
}
`;
exports[`Members API Can export CSV 1: [body] 1`] = `Object {}`;
exports[`Members API Can export CSV 2: [headers] 1`] = `
exports[`Members API Can export CSV 1: [headers] 1`] = `
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",
@ -948,9 +940,7 @@ Object {
}
`;
exports[`Members API Can export a filtered CSV 1: [body] 1`] = `Object {}`;
exports[`Members API Can export a filtered CSV 2: [headers] 1`] = `
exports[`Members API Can export a filtered CSV 1: [headers] 1`] = `
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",

View file

@ -1,8 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Sessions API can create session (log in) 1: [body] 1`] = `Object {}`;
exports[`Sessions API can create session (log in) 2: [headers] 1`] = `
exports[`Sessions API can create session (log in) 1: [headers] 1`] = `
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",
@ -17,9 +15,7 @@ Object {
}
`;
exports[`Sessions API can delete session (log out) 1: [body] 1`] = `Object {}`;
exports[`Sessions API can delete session (log out) 2: [headers] 1`] = `
exports[`Sessions API can delete session (log out) 1: [headers] 1`] = `
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",

View file

@ -1123,9 +1123,7 @@ Object {
}
`;
exports[`Settings API can do disconnectStripeConnectIntegration 1: [body] 1`] = `Object {}`;
exports[`Settings API can do disconnectStripeConnectIntegration 2: [headers] 1`] = `
exports[`Settings API can do disconnectStripeConnectIntegration 1: [headers] 1`] = `
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",
@ -1137,9 +1135,7 @@ Object {
}
`;
exports[`Settings API can do updateMembersEmail 1: [body] 1`] = `Object {}`;
exports[`Settings API can do updateMembersEmail 2: [headers] 1`] = `
exports[`Settings API can do updateMembersEmail 1: [headers] 1`] = `
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",
@ -1151,9 +1147,7 @@ Object {
}
`;
exports[`Settings API can do validateMembersEmailUpdate 1: [body] 1`] = `Object {}`;
exports[`Settings API can do validateMembersEmailUpdate 2: [headers] 1`] = `
exports[`Settings API can do validateMembersEmailUpdate 1: [headers] 1`] = `
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",

View file

@ -97,9 +97,7 @@ Object {
}
`;
exports[`Snippets API Can destroy 3: [body] 1`] = `Object {}`;
exports[`Snippets API Can destroy 4: [headers] 1`] = `
exports[`Snippets API Can destroy 3: [headers] 1`] = `
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",
@ -109,7 +107,7 @@ Object {
}
`;
exports[`Snippets API Can destroy 5: [body] 1`] = `
exports[`Snippets API Can destroy 4: [body] 1`] = `
Object {
"errors": Array [
Object {
@ -126,7 +124,7 @@ Object {
}
`;
exports[`Snippets API Can destroy 6: [headers] 1`] = `
exports[`Snippets API Can destroy 5: [headers] 1`] = `
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",

View file

@ -113,7 +113,7 @@ describe('Labels API', function () {
await agent
.delete(`labels/${id}`)
.expectStatus(204)
.matchBodySnapshot()
.expectEmptyBody()
.matchHeaderSnapshot({
etag: anyEtag
});

View file

@ -14,7 +14,7 @@ describe('Members Stripe Connect API', function () {
await agent
.get(`members/stripe_connect`)
.expectStatus(302)
.matchBodySnapshot()
.expectEmptyBody()
.matchHeaderSnapshot({
location: stringMatching(/^https:\/\/connect\.stripe\.com\/oauth\/authorize\?response_type=code&scope=read_write&client_id=/),
'set-cookie': [

View file

@ -695,7 +695,7 @@ describe('Members API', function () {
await agent
.delete(`/members/${newMember.id}`)
.expectStatus(204)
.matchBodySnapshot()
.expectEmptyBody()
.matchHeaderSnapshot({
etag: anyEtag
});
@ -732,7 +732,7 @@ describe('Members API', function () {
return [500];
});
// TODO This is wrong because it changes the state for teh rest of the tests
// @TODO This is wrong because it changes the state for the rest of the tests
// We need to add a member via a fixture and then remove them OR work out how
// to reapply fixtures before each test
const memberToDelete = fixtureManager.get('members', 2);
@ -740,10 +740,10 @@ describe('Members API', function () {
await agent
.delete(`members/${memberToDelete.id}/`)
.expectStatus(204)
.expectEmptyBody()
.matchHeaderSnapshot({
etag: anyEtag
})
.matchBodySnapshot();
});
assert.equal(subscriptionCanceled, false, 'expected subscription not to be canceled');
});
@ -754,7 +754,7 @@ describe('Members API', function () {
const res = await agent
.get(`/members/upload/`)
.expectStatus(200)
.matchBodySnapshot()
.expectEmptyBody() // express-test body parsing doesn't support CSV
.matchHeaderSnapshot({
etag: anyEtag,
'content-length': anyString, //For some reason the content-length changes between 1220 and 1317
@ -774,7 +774,7 @@ describe('Members API', function () {
const res = await agent
.get(`/members/upload/?search=Egg`)
.expectStatus(200)
.matchBodySnapshot()
.expectEmptyBody() // express-test body parsing doesn't support CSV
.matchHeaderSnapshot({
etag: anyEtag,
'content-disposition': anyString

View file

@ -19,7 +19,7 @@ describe('Sessions API', function () {
password: owner.password
})
.expectStatus(201)
.matchBodySnapshot()
.expectEmptyBody()
.matchHeaderSnapshot({
etag: anyString,
'set-cookie': [
@ -47,7 +47,7 @@ describe('Sessions API', function () {
await agent
.delete('session/')
.expectStatus(204)
.matchBodySnapshot()
.expectEmptyBody()
.matchHeaderSnapshot({
etag: anyString
});

View file

@ -172,7 +172,7 @@ describe('Settings API', function () {
type: 'fromAddressUpdate'
})
.expectStatus(200)
.matchBodySnapshot()
.expectEmptyBody()
.matchHeaderSnapshot({
etag: anyEtag
});
@ -189,7 +189,7 @@ describe('Settings API', function () {
await agent
.get(`settings/members/email/?token=${token}&action=fromAddressUpdate`)
.expectStatus(302)
.matchBodySnapshot()
.expectEmptyBody()
.matchHeaderSnapshot();
// Assert that the setting is changed as a side effect
@ -207,7 +207,7 @@ describe('Settings API', function () {
await agent
.delete('/settings/stripe/connect/')
.expectStatus(200)
.matchBodySnapshot()
.expectEmptyBody()
.matchHeaderSnapshot({
etag: anyEtag
});

View file

@ -119,7 +119,7 @@ describe('Snippets API', function () {
await agent
.delete(`snippets/${newSnippet.id}`)
.expectStatus(204)
.matchBodySnapshot()
.expectEmptyBody()
.matchHeaderSnapshot({
etag: anyEtag
});

View file

@ -449,9 +449,7 @@ Object {
}
`;
exports[`Authentication API Reset all passwords reset all passwords returns 200 1: [body] 1`] = `Object {}`;
exports[`Authentication API Reset all passwords reset all passwords returns 200 2: [headers] 1`] = `
exports[`Authentication API Reset all passwords reset all passwords returns 200 1: [headers] 1`] = `
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",

View file

@ -473,8 +473,9 @@ describe('Authentication API', function () {
await agent.post('authentication/reset_all_passwords')
.header('Accept', 'application/json')
.body({})
// @TODO: change to a 204 in 5.0
.expectStatus(200)
.matchBodySnapshot()
.expectEmptyBody()
.matchHeaderSnapshot({
etag: anyEtag
});

View file

@ -1826,12 +1826,12 @@
resolved "https://registry.yarnpkg.com/@tryghost/express-dynamic-redirects/-/express-dynamic-redirects-0.2.7.tgz#c176e54dc631d0f35c45429b0e93370842b1d4ed"
integrity sha512-DjHuOyPgULMxoXyVUakGtHLvfJeucHnxHSgdGveG0IRWbhUOfUU5+hJT1bvaBhWRQ+bGeLKmxJwxUk5bO8zk8Q==
"@tryghost/express-test@0.7.1":
version "0.7.1"
resolved "https://registry.yarnpkg.com/@tryghost/express-test/-/express-test-0.7.1.tgz#67370ebf66784d58ab3928c13cb69ba843420b32"
integrity sha512-Lzv/H3QRw8p6+wpfpxO6U24KO7BOkPpQW8Pqheopx1wegUWvEgh04FyYZOawIY6qdOd3aLid14N1kFA27pG44w==
"@tryghost/express-test@0.8.0":
version "0.8.0"
resolved "https://registry.yarnpkg.com/@tryghost/express-test/-/express-test-0.8.0.tgz#1e8ce435f798ca916752761027d29b5c65e4337e"
integrity sha512-7uCtoOmjUkiu/+Ldtgd8EShDbXIopwKdhc4FNgGrAaFnWHHA1szKCcqSccfFaYfaYdaIRkg40Qts96ulHPUY/w==
dependencies:
"@tryghost/jest-snapshot" "^0.3.7"
"@tryghost/jest-snapshot" "^0.3.8"
cookiejar "^2.1.3"
reqresnext "^1.7.0"
@ -1870,10 +1870,10 @@
optionalDependencies:
sharp "^0.30.0"
"@tryghost/jest-snapshot@^0.3.7":
version "0.3.7"
resolved "https://registry.yarnpkg.com/@tryghost/jest-snapshot/-/jest-snapshot-0.3.7.tgz#96bf2a3c95232e1f0be1f6758635bb8f21b9226d"
integrity sha512-9m5zzfXJ0OhmDCDiKP3ieSmkvEQvGenp7piAUPOl4INifczGNslZuuEOBFQe+QfYf+vfAknfbyOjMD4Fmecrdw==
"@tryghost/jest-snapshot@^0.3.8":
version "0.3.8"
resolved "https://registry.yarnpkg.com/@tryghost/jest-snapshot/-/jest-snapshot-0.3.8.tgz#c0bfe25ecddde291f76ca6f60a2e29f601af23c2"
integrity sha512-BwexomJqsTmP1vpiv0qXAMjnzS2UUDOFtBWrkm4MvzUJrVEcqHZ9vWYBsUJFIa2bpGs52+H47c/6Wr4Ht22JSg==
dependencies:
"@tryghost/errors" "^1.2.7"
expect "^27.5.0"