Skip to content

Commit

Permalink
Added e2e tests for post.deleted webhook (#15572)
Browse files Browse the repository at this point in the history
refs: #15537

- Added  missing e2e tests for post.deleted webhook to increase coverage 

Co-authored-by: Kritika Sharma <[email protected]>
  • Loading branch information
2 people authored and sam-lord committed Oct 17, 2022
1 parent 2d79d4c commit b265011
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
76 changes: 76 additions & 0 deletions ghost/core/test/e2e-webhooks/__snapshots__/posts.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,82 @@ Object {
}
`;
exports[`post.* events post.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[`post.* events post.deleted event is triggered 2: [body] 1`] = `
Object {
"post": 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": "[email protected]",
"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": "http://127.0.0.1:2369/author/joe-bloggs/",
"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": null,
"slug": "testing-post-deleted-webhook",
"status": "draft",
"title": "testing post.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[`post.* events post.published event is triggered 1: [headers] 1`] = `
Object {
"accept-encoding": "gzip, deflate",
Expand Down
51 changes: 51 additions & 0 deletions ghost/core/test/e2e-webhooks/posts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ const buildPreviousPostSnapshotWithTiers = ({tiersCount}) => {
};
};

const buildPreviousPostSnapshotForDeletedPost = () => {
return {
id: anyObjectId,
uuid: anyUuid,
comment_id: anyObjectId,
created_at: anyISODateTime,
updated_at: anyISODateTime,
authors: new Array(1).fill(buildAuthorSnapshot(true))
};
};

describe('post.* events', function () {
let adminAPIAgent;
let webhookMockReceiver;
Expand Down Expand Up @@ -154,4 +165,44 @@ describe('post.* events', function () {
}
});
});

it('post.deleted event is triggered', async function () {
const webhookURL = 'https://test-webhook-receiver.com/post-deleted/';
await webhookMockReceiver.mock(webhookURL);
await fixtureManager.insertWebhook({
event: 'post.deleted',
url: webhookURL
});

const res = await adminAPIAgent
.post('posts/')
.body({
posts: [{
title: 'testing post.deleted webhook',
status: 'draft'
}]
})
.expectStatus(201);

const id = res.body.posts[0].id;

await adminAPIAgent
.delete('posts/' + id)
.expectStatus(204);

await webhookMockReceiver.receivedRequest();

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

0 comments on commit b265011

Please sign in to comment.