Added e2e test coverage for post.added event

refs https://github.com/TryGhost/Toolbox/issues/320

- Wanted to verify if multiple webhook snapshot tests would play nicely together. They did!
- Also having few tests of the same type allows to detect patterns that could be extracted and reused later :)
This commit is contained in:
Naz 2022-06-03 14:56:55 +08:00
parent 9c3ed1a1f5
commit b536cf5d9c
2 changed files with 116 additions and 3 deletions

View File

@ -1,5 +1,84 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`post.* events post.added even is triggered 1: [body] 1`] = `
Object {
"post": Object {
"current": Object {
"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,
"email": Object {},
"email_only": false,
"email_segment": "all",
"email_subject": null,
"excerpt": null,
"feature_image": null,
"feature_image_alt": null,
"feature_image_caption": null,
"featured": false,
"frontmatter": null,
"html": null,
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"meta_description": null,
"meta_title": null,
"mobiledoc": "{\\"version\\":\\"0.3.1\\",\\"ghostVersion\\":\\"4.0\\",\\"markups\\":[],\\"atoms\\":[],\\"cards\\":[],\\"sections\\":[[1,\\"p\\",[[0,[],0,\\"\\"]]]]}",
"og_description": null,
"og_image": null,
"og_title": null,
"plaintext": null,
"primary_tag": null,
"published_at": null,
"slug": "testing-post-added-webhook",
"status": "draft",
"tags": Array [],
"tiers": Array [
Object {
"active": true,
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"description": null,
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"monthly_price_id": null,
"name": "Default Product",
"slug": "default-product",
"type": "paid",
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"visibility": "public",
"welcome_page_url": null,
"yearly_price_id": null,
},
Object {
"active": true,
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"description": null,
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"monthly_price_id": null,
"name": "Free",
"slug": "free",
"type": "free",
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"visibility": "public",
"welcome_page_url": null,
"yearly_price_id": null,
},
],
"title": "testing post.added webhook",
"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\\+\\\\//,
"uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
"visibility": "public",
},
"previous": Object {},
},
}
`;
exports[`post.* events post.published even is triggered 1: [body] 1`] = `
Object {
"post": Object {

View File

@ -7,12 +7,12 @@ const tierSnapshot = {
updated_at: anyISODateTime
};
const buildPostSnapshotWithTiers = ({tiersCount}) => {
const buildPostSnapshotWithTiers = ({published, tiersCount}) => {
return {
id: anyObjectId,
uuid: anyUuid,
comment_id: anyObjectId,
published_at: anyISODateTime,
published_at: published ? anyISODateTime : null,
created_at: anyISODateTime,
updated_at: anyISODateTime,
// @TODO: hack here! it's due to https://github.com/TryGhost/Toolbox/issues/341
@ -81,9 +81,43 @@ describe('post.* events', function () {
// .matchHeaderSnapshot();
.matchBodySnapshot({
post: {
current: buildPostSnapshotWithTiers({tiersCount: 2}),
current: buildPostSnapshotWithTiers({
published: true,
tiersCount: 2
}),
previous: buildPreviousPostSnapshotWithTiers({tiersCount: 2})
}
});
});
it('post.added even is triggered', async function () {
const webhookURL = 'https://test-webhook-receiver.com/post-added/';
await webhookMockReceiver.mock(webhookURL);
await fixtureManager.insertWebhook({
event: 'post.added',
url: webhookURL
});
await adminAPIAgent
.post('posts/')
.body({
posts: [{
title: 'testing post.added webhook',
status: 'draft'
}]
})
.expectStatus(201);
await webhookMockReceiver
// TODO: implement header matching feature next!
// .matchHeaderSnapshot();
.matchBodySnapshot({
post: {
current: buildPostSnapshotWithTiers({
published: false,
tiersCount: 2
})
}
});
});
});