mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
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:
parent
9c3ed1a1f5
commit
b536cf5d9c
2 changed files with 116 additions and 3 deletions
|
@ -1,5 +1,84 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// 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`] = `
|
exports[`post.* events post.published even is triggered 1: [body] 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"post": Object {
|
"post": Object {
|
||||||
|
|
|
@ -7,12 +7,12 @@ const tierSnapshot = {
|
||||||
updated_at: anyISODateTime
|
updated_at: anyISODateTime
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildPostSnapshotWithTiers = ({tiersCount}) => {
|
const buildPostSnapshotWithTiers = ({published, tiersCount}) => {
|
||||||
return {
|
return {
|
||||||
id: anyObjectId,
|
id: anyObjectId,
|
||||||
uuid: anyUuid,
|
uuid: anyUuid,
|
||||||
comment_id: anyObjectId,
|
comment_id: anyObjectId,
|
||||||
published_at: anyISODateTime,
|
published_at: published ? anyISODateTime : null,
|
||||||
created_at: anyISODateTime,
|
created_at: anyISODateTime,
|
||||||
updated_at: anyISODateTime,
|
updated_at: anyISODateTime,
|
||||||
// @TODO: hack here! it's due to https://github.com/TryGhost/Toolbox/issues/341
|
// @TODO: hack here! it's due to https://github.com/TryGhost/Toolbox/issues/341
|
||||||
|
@ -81,9 +81,43 @@ describe('post.* events', function () {
|
||||||
// .matchHeaderSnapshot();
|
// .matchHeaderSnapshot();
|
||||||
.matchBodySnapshot({
|
.matchBodySnapshot({
|
||||||
post: {
|
post: {
|
||||||
current: buildPostSnapshotWithTiers({tiersCount: 2}),
|
current: buildPostSnapshotWithTiers({
|
||||||
|
published: true,
|
||||||
|
tiersCount: 2
|
||||||
|
}),
|
||||||
previous: buildPreviousPostSnapshotWithTiers({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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue