-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added e2e test for
site.changed
webhook event (#15595)
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
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
ghost/core/test/e2e-webhooks/__snapshots__/site.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |