From 401fe46380f31e40681d51883dd1fcabb8171db3 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Fri, 6 May 2022 12:40:55 +0100 Subject: [PATCH] Changed webhooks to store safe version refs: https://github.com/TryGhost/Toolbox/issues/229 - We're getting rid of the concept of api versions inside of Ghost - Instead of storing the supposed api version a webhook was created with, store the current ghost version - This way we can determine if anything signicant changes in future and we need to update webhooks or something --- core/server/models/webhook.js | 3 ++- test/e2e-api/admin/__snapshots__/webhooks.test.js.snap | 8 ++++---- test/e2e-api/admin/webhooks.test.js | 6 ++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/core/server/models/webhook.js b/core/server/models/webhook.js index 0adc1d52ab..63a5d13461 100644 --- a/core/server/models/webhook.js +++ b/core/server/models/webhook.js @@ -1,5 +1,6 @@ const Promise = require('bluebird'); const ghostBookshelf = require('./base'); +const ghostVersion = require('@tryghost/version'); let Webhook; let Webhooks; @@ -8,7 +9,7 @@ Webhook = ghostBookshelf.Model.extend({ defaults() { return { - api_version: 'v4', + api_version: `v${ghostVersion.safe}`, status: 'available' }; }, diff --git a/test/e2e-api/admin/__snapshots__/webhooks.test.js.snap b/test/e2e-api/admin/__snapshots__/webhooks.test.js.snap index c7ec2bfd7c..e80a9bdfc6 100644 --- a/test/e2e-api/admin/__snapshots__/webhooks.test.js.snap +++ b/test/e2e-api/admin/__snapshots__/webhooks.test.js.snap @@ -4,7 +4,7 @@ exports[`Webhooks API Can create a webhook 1: [body] 1`] = ` Object { "webhooks": Array [ Object { - "api_version": "canary", + "api_version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/, "created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}/, "event": "test.create", "id": StringMatching /\\[a-f0-9\\]\\{24\\}/, @@ -26,7 +26,7 @@ exports[`Webhooks API Can create a webhook 2: [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": "414", + "content-length": "413", "content-type": "application/json; charset=utf-8", "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, "vary": "Origin, Accept-Encoding", @@ -48,7 +48,7 @@ exports[`Webhooks API Can edit a webhook 1: [body] 1`] = ` Object { "webhooks": Array [ Object { - "api_version": "canary", + "api_version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/, "created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}/, "event": "subscriber.added", "id": StringMatching /\\[a-f0-9\\]\\{24\\}/, @@ -70,7 +70,7 @@ exports[`Webhooks API Can edit a webhook 2: [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": "418", + "content-length": "417", "content-type": "application/json; charset=utf-8", "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, "vary": "Origin, Accept-Encoding", diff --git a/test/e2e-api/admin/webhooks.test.js b/test/e2e-api/admin/webhooks.test.js index 56358dc008..e4e8428f66 100644 --- a/test/e2e-api/admin/webhooks.test.js +++ b/test/e2e-api/admin/webhooks.test.js @@ -1,9 +1,9 @@ const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework'); -const {anyEtag, anyErrorId, anyObjectId, anyISODate} = matchers; -const API_VERSION = 'canary'; +const {anyEtag, anyErrorId, anyObjectId, anyISODate, stringMatching} = matchers; const webhookMatcher = { id: anyObjectId, + api_version: stringMatching(/v\d+\.\d+/), integration_id: anyObjectId, created_at: anyISODate, updated_at: anyISODate @@ -25,7 +25,6 @@ describe('Webhooks API', function () { target_url: 'http://example.com/webhooks/test/extra/1', name: 'test', secret: 'thisissecret', - api_version: API_VERSION, integration_id: fixtureManager.get('integrations', 0).id }; }); @@ -69,7 +68,6 @@ describe('Webhooks API', function () { target_url: 'http://example.com/webhooks/test/extra/10', name: 'test', secret: 'thisissecret', - api_version: API_VERSION, integration_id: `fake-integration` }]}) .expectStatus(422)