-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webhook test coverage #15537
Comments
hi @naz |
Hey @dshubhadeep 👋 Feel free to pick one event at a time, will try my best to review ASAP. And feel free to ask questions if anything is unclear! |
Thanks, I'll start with |
I'd like to work on |
I'll try my hand at page.added |
I can work on |
refs #15537 - this adds an e2e test and test snapshot for the `tag.deleted` webhook so we can prevent regressions and bugs in the future
refs #15537 - this adds an e2e test and test snapshot for the `member.added` webhook so we can prevent regressions and bugs in the future
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
working on post.deleted event |
ref TryGhost#15537 - this adds an e2e test and test snapshot for the page.published webhook so we can prevent regressions and bugs in the future
refs: TryGhost#15537 This adds an e2e test and test snapshot for the page.tag.detached webhook so we can prevent regressions and bugs in the future
refs: #15537 - snapshot test created to add confidence to webhook stability and increase overall test coverage.
refs: #15537 - snapshot test created to add confidence to webhook stability and increase overall test coverage.
Contributes to this issue: TryGhost#15537
refs: #15537 - snapshot test created to add confidence to webhook stability and increase overall test coverage.
Contributes to this issue: TryGhost#15537
refs: #15537 - snapshot test created to add confidence to webhook stability and increase overall test coverage.
We now have either a merged or open PR for every single webhook. Thank you to everyone who contributed ❤️ this is incredible - you've all helped us to make a sea-change in our test coverage and ability to support webhooks and zapier going forward. Thank you 🙏 |
refs: #15537 - snapshot test created to add confidence to webhook stability and increase overall test coverage.
refs: #15537 - snapshot test created to add confidence to webhook stability and increase overall test coverage.
Contributes to this issue: TryGhost#15537
refs: #15537 - snapshot test created to add confidence to webhook stability and increase overall test coverage.
Webhooks have been a part of Ghost since very first versions. This area has been constantly lagging behind with solid test coverage. Having tests would add confidence to webhooks stability. Snapshot tests would be a great source of example data webhooks deliver to external integrations.
To improve this situation, Ghost has introduced a special purpose Webhooks snapshot tests. These are snapshot-based tests (similar to the end-to-end API tests) with one big difference - they test the outgoing request payload instead of API responses.
To understand how end-to-end testing works at Ghost have a read through this guide. The concepts applied in end-to-end API tests are very similar to ones used in webhook tests.
Here is an example of a webhook test suite for for
post.published
andpost.added
events.The above suite covers two event's which Webhook events listen to. There are 29 total events Webhooks can respond to, 27 left to cover. We need help writing tests for them!
Below are some pointers around what you could help us with. For the most part it's covering all of the webhook events with at least one "happy path" test.
Steps to cover a webhook event listener with a test
1. Write a test
First, find one webhook event listener to cover - search for an event that has no test coverage in the list of all webhook event listeners.
Copy of all events below for quick reference and ✅ for the ones with at least one test:
site.changed
webhook event #15595)post.edited
webhook #15625)post.published.edited
webhook #15642)post.unpublished
webhook #15628)post.scheduled
event #15561)post.unscheduled
webhook #15675)page.deleted
webhook #15723)page.edited
webhook #15627)page.published.edited
webhook #15724)page.published.edited
webhook #15724)page.unpublished
webhook #15613)page.scheduled
webhook #15609)page.rescheduled
webhook #15736)tag.edited
webhook #15555)tag.deleted
webhook #15553)member.added
webhook #15554)member.deleted
webhook #15570)member.edited
webhook #15620)post.tag.attached
webhook #15576)page.tag.detached
webhook #15651)page.tag.attached
webhook #15648)page.tag.detached
webhook #15651)Before digging deep into work please double check if the list is up to date - check if there are any open or closed Pull Requests open with the name of the event you are about to pick up.
Let's pick
site.changed
event to cover with example a test.Webhook tests are located in
ghost/core/test/e2e-webhooks/{model_name}.test.js
(e.g.: test/e2e-webhooks/posts.test.js). As there is nosite.test.js
suite in the e2e-webhooks folder - create asite.test.js
file. Note, forpost.rescheduled
event, there is aposts.test.js
test suite already. In this case, we would add test cases to existingposts.test.js
test suite. The convention is to group test suites by common model name -{model_name}.test.js
.Write the test in the newly created file following concepts in end-to-end testing guide. For an easy start it's usually a good idea to copy a similar working test suite into your new file and tweak it.
Notes on Webhook test case structure
Webhook tests follow a setup->action->assert structure used commonly when writing other types of tests, like unit tests:
2. Run the test and record a snapshot
Use the
yarn test:single
command insideghost/core
to run the test suite you've been working on:After the test run, there will be a snapshot file created with recorder webhook payload (example).
Check the Snapshot Testing section of the end-to-end testing guide for more information about the inner workings of snapshot-based tests.
3. Open a PR
To make sure you've not broken anything & followed our code standard, run
yarn test:all
. You can also useyarn lint
to check formatting issues.Commit and push the test suite code and the snapshot to your working branch. Open up a separate PR for each webhook even you cover.
🎉 All done! we will try to review your contribution ASAP.
Please follow our contribution guidelines as closely as you can, particularly being sure to reference this issue in your commit. Test coverage commits should not use emojis as they are not user-facing changes.
This issue is going to improve the ease of bug reproductions and will let all Ghost developers sleep better after modifying webhook-related code. This means a lot for the team and contributors!
Thank you 🙏 💚
The text was updated successfully, but these errors were encountered: