From 4110ffaa2cb5700cc453044fe21ee3e65762626f Mon Sep 17 00:00:00 2001 From: Shubhadeep Das Date: Thu, 6 Oct 2022 12:51:15 +0530 Subject: [PATCH] Added e2e tests for tag.added webhook (#15537) --- .../__snapshots__/tags.test.js.snap | 42 ++++++++++++ ghost/core/test/e2e-webhooks/tags.test.js | 64 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 ghost/core/test/e2e-webhooks/__snapshots__/tags.test.js.snap create mode 100644 ghost/core/test/e2e-webhooks/tags.test.js diff --git a/ghost/core/test/e2e-webhooks/__snapshots__/tags.test.js.snap b/ghost/core/test/e2e-webhooks/__snapshots__/tags.test.js.snap new file mode 100644 index 0000000000..ac06a49644 --- /dev/null +++ b/ghost/core/test/e2e-webhooks/__snapshots__/tags.test.js.snap @@ -0,0 +1,42 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`tag.* events tag.added event is triggered 1: [headers] 1`] = ` +Object { + "accept-encoding": "gzip, deflate", + "content-length": Any, + "content-type": "application/json", + "content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/, + "user-agent": StringMatching /Ghost\\\\/\\\\d\\+\\\\\\.\\\\d\\+\\\\\\.\\\\d\\+\\\\s\\\\\\(https:\\\\/\\\\/github\\.com\\\\/TryGhost\\\\/Ghost\\\\\\)/, +} +`; + +exports[`tag.* events tag.added event is triggered 2: [body] 1`] = ` +Object { + "tag": Object { + "current": Object { + "accent_color": null, + "canonical_url": null, + "codeinjection_foot": null, + "codeinjection_head": null, + "created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, + "description": Any, + "feature_image": null, + "id": StringMatching /\\[a-f0-9\\]\\{24\\}/, + "meta_description": null, + "meta_title": null, + "name": "Test Tag", + "og_description": null, + "og_image": null, + "og_title": null, + "slug": "test-tag", + "twitter_description": null, + "twitter_image": null, + "twitter_title": null, + "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, + "url": StringMatching /http:\\\\/\\\\/127\\.0\\.0\\.1:2369\\\\/\\\\w\\+\\\\//, + "visibility": "public", + }, + "previous": Object {}, + }, +} +`; diff --git a/ghost/core/test/e2e-webhooks/tags.test.js b/ghost/core/test/e2e-webhooks/tags.test.js new file mode 100644 index 0000000000..22e8027390 --- /dev/null +++ b/ghost/core/test/e2e-webhooks/tags.test.js @@ -0,0 +1,64 @@ +const {agentProvider, mockManager, fixtureManager, matchers} = require('../utils/e2e-framework'); +const {anyGhostAgent, anyObjectId, anyISODateTime, anyUuid, anyString, anyContentVersion, anyNumber, anyLocalURL} = matchers; + +const tagSnapshot = { + created_at: anyISODateTime, + description: anyString, + id: anyObjectId, + updated_at: anyISODateTime, + url: anyLocalURL, + visibility: 'public' +}; + +describe('tag.* events', function () { + let adminAPIAgent; + let webhookMockReceiver; + + before(async function () { + adminAPIAgent = await agentProvider.getAdminAPIAgent(); + await fixtureManager.init('integrations'); + await adminAPIAgent.loginAsOwner(); + }); + + beforeEach(function () { + webhookMockReceiver = mockManager.mockWebhookRequests(); + }); + + afterEach(function () { + mockManager.restore(); + }); + + it('tag.added event is triggered', async function () { + const webhookURL = 'https://test-webhook-receiver.com/tag-added/'; + await webhookMockReceiver.mock(webhookURL); + await fixtureManager.insertWebhook({ + event: 'tag.added', + url: webhookURL + }); + + await adminAPIAgent + .post('tags/') + .body({ + tags: [{ + name: 'Test Tag', + slug: 'test-tag', + description: 'Test Description' + }] + }) + .expectStatus(201); + + await webhookMockReceiver.receivedRequest(); + + webhookMockReceiver + .matchHeaderSnapshot({ + 'content-version': anyContentVersion, + 'content-length': anyNumber, + 'user-agent': anyGhostAgent + }) + .matchBodySnapshot({ + tag: { + current: tagSnapshot + } + }); + }); +}); \ No newline at end of file