Skip to content
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

Adds & updates service user profile related tests for covering exceptions calling external apis #478

Conversation

haydnba
Copy link
Contributor

@haydnba haydnba commented Jun 14, 2024

Issue link / number:

#448

What changes did you make?

  1. Added new set of tests for serviceUserProfiles util to cover cases where external api calls fail - test asserts the util method should not propagate the error
  2. Added new test for partner-access service to cover case where mailchimp api call fails - test asserts the assignment should succeed when where the external api call results in an exception
  3. Minor modifications to the mocking / spying strategy for the above test
  4. Added several very similar tests to the user service for ensuring the identical scenario does not result in failures to create/update etc. - covers both mailchimp and crisp api calls in dedicated tests as handling these in the same test is redundant (since crisp api is always called first, we would not be testing the same outcome for mailchimp...)
  5. Added some awaits to calls on serviceUserProfiles methods - this was picked up during testing when it became clear that the test suite was completing before certain mocked methods had been called by the service under test...

EDIT removed the awaits as they interfere with desired behaviour on client -> ran tests again without any change and all are passing - basically, as I understood it at the time, the issue was the test suite was completing before all mocked methods were fully executed (because the caller methods were not awaiting the result of the call) and therefore some assertions (e.g. mocked x was called x times) were failing.... hopefully it was just a blip on my machine but it could potentially happen in CI also 🤞🏼

Why did you make the changes?

The team wants to ensure that there is adequate test coverage to prevent a regression allowing external (crisp/mailchimp) api calls to potentially break or interfere with critical flows like user signup...

haydnba added 4 commits June 14, 2024 23:52
…ce - requires some extra mocking and minor reorganisation
…y was not an issue in production but under test the runs could complete before mocked methods were called)
@haydnba haydnba changed the title adds generic test for external api call error suppression under the … Adds & updates service user profile related tests for covering exceptions calling external apis Jun 15, 2024
@haydnba haydnba marked this pull request as ready for review June 15, 2024 21:55
Copy link
Member

@annarhughes annarhughes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for this contribution! Super clean and complete, and will help save failed user creations in future 🙌

There's just one comment on the await, happy to approve once resolved!

src/user/user.service.ts Outdated Show resolved Hide resolved
@haydnba
Copy link
Contributor Author

haydnba commented Jun 17, 2024

@annarhughes sorry that was a presumptuous late night decision! I'll see what I can do to run the tests without the awaits 👍🏼👍🏼

Copy link
Member

@annarhughes annarhughes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again @haydnba 🌟 Merging now!

@annarhughes annarhughes merged commit e14efe6 into chaynHQ:develop Jun 18, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants