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

Add tests suite for the Webhook sender package #19

Closed
koladev32 opened this issue Sep 9, 2023 · 0 comments · Fixed by #24
Closed

Add tests suite for the Webhook sender package #19

koladev32 opened this issue Sep 9, 2023 · 0 comments · Fixed by #24
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@koladev32
Copy link
Collaborator

To ensure our sender package is reliable and robust, we need to implement a comprehensive suite of unit tests. Specifically, the focus will be on the SendWebhook function, as well as any auxiliary functions it calls.

Scope:

  1. Test marshalJSON:

    • Ensure correct JSON marshaling with valid data structures.
    • Test with invalid structures and ensure that errors are correctly returned.
  2. Test prepareRequest:

    • Ensure the request is correctly prepared with the given URL, JSON bytes, and secret hash.
    • Confirm headers (like Content-Type and X-Secret-Hash) are appropriately set.
  3. Test sendRequest:

    • Mock different scenarios including:
      • Successful responses.
      • Client Errors (e.g., HTTP 400).
      • Server Errors (e.g., HTTP 500).
    • Ensure errors are returned as expected.
  4. Test closeResponse:

    • Verify that the response body is correctly closed.
    • Ensure that any errors during the closure are handled appropriately.
  5. Test processResponse:

    • Check that the function correctly determines the status based on various mocked response codes and bodies.
    • Ensure the function returns the response body and any potential errors.
  6. Test Overall Flow in SendWebhook:

    • Successful webhook sending.
    • Failed webhook due to request preparation errors.
    • Failed webhook due to marshaling errors.
    • Failed webhook due to response processing errors.
    • Logging on failed webhook delivery (checking the invocation of WebhookLogger).
@koladev32 koladev32 added enhancement New feature or request good first issue Good for newcomers labels Sep 9, 2023
@koladev32 koladev32 linked a pull request Sep 9, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant