Skip to content

Commit

Permalink
Added e2e test for site.changed webhook event (#15595)
Browse files Browse the repository at this point in the history
refs: #15537

- snapshot test created to add confidence to webhook stability and increase overall test coverage.
  • Loading branch information
Halldor Thorhallsson authored Oct 13, 2022
1 parent e05889c commit 74f7b7b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ghost/core/test/e2e-webhooks/__snapshots__/site.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`site.* events site.changed event is triggered 1: [headers] 1`] = `
Object {
"accept-encoding": "gzip, deflate",
"content-length": Any<Number>,
"content-type": "application/json",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"user-agent": StringMatching /Ghost\\\\/\\\\d\\+\\\\\\.\\\\d\\+\\\\\\.\\\\d\\+\\\\s\\\\\\(https:\\\\/\\\\/github\\.com\\\\/TryGhost\\\\/Ghost\\\\\\)/,
}
`;
exports[`site.* events site.changed event is triggered 2: [body] 1`] = `Object {}`;
51 changes: 51 additions & 0 deletions ghost/core/test/e2e-webhooks/site.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const {agentProvider, mockManager, fixtureManager, matchers} = require('../utils/e2e-framework');
const {anyGhostAgent, anyContentVersion, anyNumber} = matchers;

describe('site.* 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('site.changed event is triggered', async function () {
const webhookURL = 'https://test-webhook-receiver.com/site-changed';
await webhookMockReceiver.mock(webhookURL);
await fixtureManager.insertWebhook({
event: 'site.changed',
url: webhookURL
});

const res = await adminAPIAgent
.post('posts/')
.body({
posts: [{
title: 'webhookz',
status: 'published',
mobiledoc: fixtureManager.get('posts', 1).mobiledoc
}]
})
.expectStatus(201);

await webhookMockReceiver.receivedRequest();

webhookMockReceiver
.matchHeaderSnapshot({
'content-version': anyContentVersion,
'content-length': anyNumber,
'user-agent': anyGhostAgent
})
.matchBodySnapshot();
});
});

0 comments on commit 74f7b7b

Please sign in to comment.