Skip to content

Commit

Permalink
Added e2e test for tag.edited webhook (TryGhost#15555)
Browse files Browse the repository at this point in the history
refs TryGhost#15537
- this adds an e2e test and test snapshot for the `tag.edited` webhook so we can prevent regressions and bugs in the future
  • Loading branch information
dshubhadeep committed Oct 7, 2022
1 parent a0ec94f commit 95aefe8
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
45 changes: 45 additions & 0 deletions ghost/core/test/e2e-webhooks/__snapshots__/tags.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,48 @@ Object {
},
}
`;
exports[`tag.* events tag.edited 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[`tag.* events tag.edited event is triggered 2: [body] 1`] = `
Object {
"tag": Object {
"current": Object {
"accent_color": null,
"canonical_url": null,
"codeinjection_foot": null,
"codeinjection_head": null,
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"description": Any<String>,
"feature_image": null,
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"meta_description": null,
"meta_title": null,
"name": "Updated Tag 3",
"og_description": null,
"og_image": null,
"og_title": null,
"slug": "updated-tag-3",
"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\\+\\\\//,
"visibility": "public",
},
"previous": Object {
"name": "Test Tag 3",
"slug": "test-tag-3",
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
},
},
}
`;
48 changes: 48 additions & 0 deletions ghost/core/test/e2e-webhooks/tags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,52 @@ describe('tag.* events', function () {
}
});
});

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

const res = await adminAPIAgent
.post('tags/')
.body({
tags: [{
name: 'Test Tag 3',
slug: 'test-tag-3',
description: 'Test description'
}]
})
.expectStatus(201);

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

const updatedTag = res.body.tags[0];
updatedTag.name = 'Updated Tag 3';
updatedTag.slug = 'updated-tag-3';

await adminAPIAgent
.put('tags/' + id)
.body({
tags: [updatedTag]
})
.expectStatus(200);

await webhookMockReceiver.receivedRequest();

webhookMockReceiver
.matchHeaderSnapshot({
'content-version': anyContentVersion,
'content-length': anyNumber,
'user-agent': anyGhostAgent
})
.matchBodySnapshot({
tag: {
current: {...tagSnapshot, url: anyLocalURL},
previous: {updated_at: anyISODateTime}
}
});
});
});

0 comments on commit 95aefe8

Please sign in to comment.