test(idempotency): simplify wrapper & middleware tests #2919
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Changes
This PR consolidates the unit tests for the
makeIdempotent
function wrapper and themakeHandlerIdempotent
Middy.js middleware, thus reducing duplication and maintenance overhead.More than 90% of the test cases and assertions within the tests of the two files were the exact same, resulting in a code duplication of almost 70%. This PR consolidates the tests in a single file using the the
it.each()
feature present in Jest.For example, instead of having two test cases that only differ in how the handler is wrapped, we now have cases like this:
In short, we now run two test cases with a discriminator (
type
) which instantiates thehandler
constant either using the function wrapper or Middy.js middleware, then carry on with the tests as normal.The resulting test file has most of the test cases setup as described above, and only a handful of cases (<5) that are specific to one or the other method.
The logs/outputs of the tests are still distinguishable thanks to the templating used in the test case description:
Issue number: closes #2918
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.