From 85051199e3d0b42a6aa0d2671a2d185be84336a2 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Wed, 18 Jan 2023 08:09:28 +0100 Subject: [PATCH] Added email snapshots for `API versioning` tests (#16139) --- .../shared/__snapshots__/version.test.js.snap | 419 ++++++++++++++++++ .../core/test/e2e-api/shared/version.test.js | 28 +- 2 files changed, 432 insertions(+), 15 deletions(-) diff --git a/ghost/core/test/e2e-api/shared/__snapshots__/version.test.js.snap b/ghost/core/test/e2e-api/shared/__snapshots__/version.test.js.snap index d0f47060ff..dd67132b3d 100644 --- a/ghost/core/test/e2e-api/shared/__snapshots__/version.test.js.snap +++ b/ghost/core/test/e2e-api/shared/__snapshots__/version.test.js.snap @@ -328,6 +328,178 @@ Object { } `; +exports[`API Versioning Admin API responds with error and sends email ONCE when requested version is BEHIND and CANNOT respond multiple times 3: [html 1] 1`] = ` +" + + + + +Integration error + + + + + + + + + + +
  + +
+ + + + + + + + + + + + + +
+ + + + + + + + + + +
+

Uh-oh!

+
+

+ Your Zapier integration is no longer working as expected. This integration must be updated by its developer to work with your version of Ghost. +

+ +

+ To help you get things fixed as quickly as possible, Ghost has automatically generated some helpful information about the error that you can share with the creator of the Zapier integration below: +

+ +

+ Integration expected Ghost version:  v3.5 +
+ Current Ghost version:  v5.30 +
+ Failed request URL:  /ghost/api/admin/removed_endpoint/ +

+
+
+
+

This email was sent from http://127.0.0.1:2369/ to jbloggs@example.com

+
+
+ + +
+
 
+ + +" +`; + exports[`API Versioning Admin API responds with error and sends email ONCE when requested version is BEHIND and CANNOT respond multiple times 4: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", @@ -341,6 +513,59 @@ Object { } `; +exports[`API Versioning Admin API responds with error and sends email ONCE when requested version is BEHIND and CANNOT respond multiple times 4: [metadata 1] 1`] = ` +Object { + "subject": "Attention required: Your Zapier integration has failed", + "text": " [https://static.ghost.org/v4.0.0/images/ghost-orb-1.png] Uh-oh! + +Your Zapier integration is no longer working as expected. This integration must +be updated by its developer to work with your version of Ghost. + +To help you get things fixed as quickly as possible, Ghost has automatically +generated some helpful information about the error that you can share with the +creator of the Zapier integration below: + + Integration expected Ghost version:v3.5 +Current Ghost version:v5.30 +Failed request URL:/ghost/api/admin/removed_endpoint/ + +This email was sent from http://127.0.0.1:2369/ [http://127.0.0.1:2369/] to +jbloggs@example.com [jbloggs@example.com]", + "to": "jbloggs@example.com", +} +`; + +exports[`API Versioning Admin API responds with error and sends email ONCE when requested version is BEHIND and CANNOT respond multiple times 5: [body] 1`] = ` +Object { + "errors": Array [ + Object { + "code": "UPDATE_CLIENT", + "context": StringMatching /Provided client accept-version v3\\.5 is behind current Ghost version v\\\\d\\+\\\\\\.\\\\d\\+/, + "details": null, + "ghostErrorCode": null, + "help": "Try upgrading your Ghost API client.", + "id": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, + "message": "Request could not be served, the endpoint was not found.", + "property": null, + "type": "RequestNotAcceptableError", + }, + ], +} +`; + +exports[`API Versioning Admin API responds with error and sends email ONCE when requested version is BEHIND and CANNOT respond multiple times 6: [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", + "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 \\]\\|\\\\\\\\\\.\\)\\*"/, + "vary": "Accept-Version, Origin, Accept-Encoding", + "x-powered-by": "Express", +} +`; + exports[`API Versioning Admin API responds with error requested version is AHEAD and CANNOT respond 1: [body] 1`] = ` Object { "errors": Array [ @@ -403,6 +628,200 @@ Object { } `; +exports[`API Versioning Admin API responds with error when requested version is BEHIND and CANNOT respond 3: [html 1] 1`] = ` +" + + + + +Integration error + + + + + + + + + + +
  + +
+ + + + + + + + + + + + + +
+ + + + + + + + + + +
+

Uh-oh!

+
+

+ Your Zapier integration is no longer working as expected. This integration must be updated by its developer to work with your version of Ghost. +

+ +

+ To help you get things fixed as quickly as possible, Ghost has automatically generated some helpful information about the error that you can share with the creator of the Zapier integration below: +

+ +

+ Integration expected Ghost version:  v3.1 +
+ Current Ghost version:  v5.30 +
+ Failed request URL:  /ghost/api/admin/removed_endpoint/ +

+
+
+
+

This email was sent from http://127.0.0.1:2369/ to jbloggs@example.com

+
+
+ + +
+
 
+ + +" +`; + +exports[`API Versioning Admin API responds with error when requested version is BEHIND and CANNOT respond 4: [metadata 1] 1`] = ` +Object { + "subject": "Attention required: Your Zapier integration has failed", + "text": " [https://static.ghost.org/v4.0.0/images/ghost-orb-1.png] Uh-oh! + +Your Zapier integration is no longer working as expected. This integration must +be updated by its developer to work with your version of Ghost. + +To help you get things fixed as quickly as possible, Ghost has automatically +generated some helpful information about the error that you can share with the +creator of the Zapier integration below: + + Integration expected Ghost version:v3.1 +Current Ghost version:v5.30 +Failed request URL:/ghost/api/admin/removed_endpoint/ + +This email was sent from http://127.0.0.1:2369/ [http://127.0.0.1:2369/] to +jbloggs@example.com [jbloggs@example.com]", + "to": "jbloggs@example.com", +} +`; + exports[`API Versioning Admin API responds with no content version header when accept version header is NOT PRESENT 1: [body] 1`] = ` Object { "site": Object { diff --git a/ghost/core/test/e2e-api/shared/version.test.js b/ghost/core/test/e2e-api/shared/version.test.js index ea8fd53639..0e6b484494 100644 --- a/ghost/core/test/e2e-api/shared/version.test.js +++ b/ghost/core/test/e2e-api/shared/version.test.js @@ -10,6 +10,7 @@ const settingsMatcher = { describe('API Versioning', function () { describe('Admin API', function () { let agentAdminAPI; + let emailMockReceiver; before(async function () { agentAdminAPI = await agentProvider.getAdminAPIAgent(); @@ -18,7 +19,7 @@ describe('API Versioning', function () { }); beforeEach(function () { - mockManager.mockMail(); + emailMockReceiver = mockManager.mockMail(); }); afterEach(function () { @@ -129,11 +130,9 @@ describe('API Versioning', function () { }] }); - mockManager.assert.sentEmailCount(1); - mockManager.assert.sentEmail({ - subject: 'Attention required: Your Zapier integration has failed', - to: 'jbloggs@example.com' - }); + emailMockReceiver.sentEmailCount(1); + emailMockReceiver.matchHTMLSnapshot(); + emailMockReceiver.matchMetadataSnapshot(); }); it('responds with error and sends email ONCE when requested version is BEHIND and CANNOT respond multiple times', async function () { @@ -154,11 +153,9 @@ describe('API Versioning', function () { }] }); - mockManager.assert.sentEmailCount(1); - mockManager.assert.sentEmail({ - subject: 'Attention required: Your Zapier integration has failed', - to: 'jbloggs@example.com' - }); + emailMockReceiver.sentEmailCount(1); + emailMockReceiver.matchHTMLSnapshot(); + emailMockReceiver.matchMetadataSnapshot(); await agentAdminAPI .get('removed_endpoint') @@ -177,7 +174,7 @@ describe('API Versioning', function () { }] }); - mockManager.assert.sentEmailCount(1); + emailMockReceiver.sentEmailCount(1); }); it('responds with 404 error when the resource cannot be found', async function () { @@ -196,7 +193,7 @@ describe('API Versioning', function () { }] }); - mockManager.assert.sentEmailCount(0); + emailMockReceiver.sentEmailCount(0); }); it('Does an internal rewrite for canary URLs with accept version set', async function () { @@ -270,9 +267,10 @@ describe('API Versioning', function () { describe('Content API', function () { let agentContentAPI; + let emailMockReceiver; beforeEach(function () { - mockManager.mockMail(); + emailMockReceiver = mockManager.mockMail(); }); afterEach(function () { @@ -339,7 +337,7 @@ describe('API Versioning', function () { }] }); - mockManager.assert.sentEmailCount(0); + emailMockReceiver.sentEmailCount(0); }); }); });