mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
Added e2e tests for page.deleted
webhook (#15723)
refs: https://github.com/TryGhost/Ghost/issues/15537 - snapshot test created to add confidence to webhook stability and increase overall test coverage.
This commit is contained in:
parent
a8ba8cc444
commit
0bccbcb083
@ -147,6 +147,82 @@ Object {
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`page.* events page.deleted 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[`page.* events page.deleted event is triggered 2: [body] 1`] = `
|
||||
Object {
|
||||
"page": Object {
|
||||
"current": Object {},
|
||||
"previous": Object {
|
||||
"authors": Array [
|
||||
Object {
|
||||
"accessibility": null,
|
||||
"bio": "bio",
|
||||
"comment_notifications": true,
|
||||
"cover_image": null,
|
||||
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||
"email": "jbloggs@example.com",
|
||||
"facebook": null,
|
||||
"free_member_signup_notification": true,
|
||||
"id": "1",
|
||||
"last_seen": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||
"location": "location",
|
||||
"meta_description": null,
|
||||
"meta_title": null,
|
||||
"name": "Joe Bloggs",
|
||||
"paid_subscription_canceled_notification": false,
|
||||
"paid_subscription_started_notification": true,
|
||||
"profile_image": "https://example.com/super_photo.jpg",
|
||||
"roles": Array [
|
||||
Object {
|
||||
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||
"description": "Blog Owner",
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Owner",
|
||||
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||
},
|
||||
],
|
||||
"slug": "joe-bloggs",
|
||||
"status": "active",
|
||||
"tour": null,
|
||||
"twitter": 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\\\\/\\[A-Za-z0-9_-\\]\\+\\\\//,
|
||||
"website": null,
|
||||
},
|
||||
],
|
||||
"canonical_url": null,
|
||||
"codeinjection_foot": null,
|
||||
"codeinjection_head": null,
|
||||
"comment_id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||
"custom_excerpt": null,
|
||||
"custom_template": null,
|
||||
"feature_image": null,
|
||||
"featured": false,
|
||||
"html": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"mobiledoc": "{\\"version\\":\\"0.3.1\\",\\"ghostVersion\\":\\"4.0\\",\\"markups\\":[],\\"atoms\\":[],\\"cards\\":[],\\"sections\\":[[1,\\"p\\",[[0,[],0,\\"\\"]]]]}",
|
||||
"published_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||
"slug": "testing-page-deleted-webhook",
|
||||
"status": "published",
|
||||
"title": "testing page.deleted webhook",
|
||||
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||
"uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
|
||||
"visibility": "public",
|
||||
},
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`page.* events page.edited event is triggered 1: [headers] 1`] = `
|
||||
Object {
|
||||
"accept-encoding": "gzip, deflate",
|
||||
|
@ -62,6 +62,17 @@ const buildPageSnapshotWithTiers = ({
|
||||
};
|
||||
|
||||
const buildPreviousPageSnapshotWithTiers = (tiersCount) => {
|
||||
if (tiersCount === 0) {
|
||||
return {
|
||||
id: anyObjectId,
|
||||
uuid: anyUuid,
|
||||
comment_id: anyObjectId,
|
||||
published_at: anyISODateTime,
|
||||
created_at: anyISODateTime,
|
||||
updated_at: anyISODateTime,
|
||||
authors: new Array(1).fill(buildAuthorSnapshot(true))
|
||||
};
|
||||
}
|
||||
return {
|
||||
tiers: new Array(tiersCount).fill(tierSnapshot),
|
||||
updated_at: anyISODateTime
|
||||
@ -188,6 +199,50 @@ describe('page.* events', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('page.deleted event is triggered', async function () {
|
||||
const webhookURL = 'https://test-webhook-receiver.com/page-deleted/';
|
||||
await webhookMockReceiver.mock(webhookURL);
|
||||
await fixtureManager.insertWebhook({
|
||||
event: 'page.deleted',
|
||||
url: webhookURL
|
||||
});
|
||||
|
||||
const res = await adminAPIAgent
|
||||
.post('pages/')
|
||||
.body({
|
||||
pages: [
|
||||
{
|
||||
title: 'testing page.deleted webhook',
|
||||
status: 'published',
|
||||
published_at: moment().subtract(6, 'hours').toISOString()
|
||||
}
|
||||
]
|
||||
})
|
||||
.expectStatus(201);
|
||||
|
||||
const id = res.body.pages[0].id;
|
||||
|
||||
await adminAPIAgent
|
||||
.delete('pages/' + id)
|
||||
.expectStatus(204)
|
||||
.expectEmptyBody();
|
||||
|
||||
await webhookMockReceiver.receivedRequest();
|
||||
|
||||
webhookMockReceiver
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
'content-length': anyNumber,
|
||||
'user-agent': anyGhostAgent
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
page: {
|
||||
current: {},
|
||||
previous: buildPreviousPageSnapshotWithTiers(0)
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('page.edited event is triggered', async function () {
|
||||
const webhookURL = 'https://test-webhook-receiver.com/page-edited/';
|
||||
await webhookMockReceiver.mock(webhookURL);
|
||||
|
Loading…
Reference in New Issue
Block a user