-
Notifications
You must be signed in to change notification settings - Fork 78
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
test(verification): integration tests for otp verification #1928
Merged
seaerchin
merged 6 commits into
refactor/migrate-verify-otp
from
test/integration-tests-verify-otp
May 27, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a548878
test(public-forms/verification/routes/spec): adds integration tests f…
seaerchin a91ff25
docs(public-forms/verification/routes/test): fixed typo
seaerchin 326e034
refactor(public-forms/verifaction/routes/spec): changed to generating…
seaerchin 7474612
Merge branch 'develop' into test/integration-tests-verify-otp
seaerchin 72ac5de
Merge branch 'develop' into test/integration-tests-verify-otp
seaerchin 1fec51d
Merge branch 'refactor/migrate-verify-otp' into test/integration-test…
seaerchin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but is it okay that the
mockRejectedValue
is 'no' instead of an error?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeap! the reason this is ok (or not, because of
neverthrow
hehehe) is due toneverthrow
'sResultAsync.fromPromise
.our calls to the database essentially returns
Promise<ModelSchema | null>
, where the null is used to indicate an expected error when something is off with the query and the requested information could not be found (eg: no model matching the specified options).however, promises and throwable functions actually have the possibility of an exception, which is an unexpected error that the called function isn't qualified to handle, and returns to teh caller. this is not encoded in the type signature and hence, is a mental overhead that engineers have to keep in the when calling functions, lest it crashes their system. In light of this, promises are actually typed as such:
Promise<your_return_type | exception>
The
ResultAsync.fromPromise
function inneverthrow
essentially allows us to sidestep this problem for promises (the corresponding function for throwables isResult.fromThrowable
. This allows us to catch a rejecting promise (or an error) and map it back using a function. Because the type of exception is not encoded in ts' type system, this has to transform an unknown error back into a proper error type, which is done bytransformMongoError
tl; dr: rejecting the promise causes it to go into error branch, and then a default error is returned from
transformMongoError
hence it's fine. thx for coming to my ted talk.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh okay thanks for sharing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chowyiyin fyi the team decided a while ago that integration tests only need to cover Joi validation and success cases, since the controller unit tests should already test for the various error cases. @seaerchin has put in a lot of effort to mock lower layers even in integration tests so that error cases can be tested, which is great, but requires quite a bit of additional work.