-
Notifications
You must be signed in to change notification settings - Fork 5
Chi 1967 productionize lex pre survey chatbot test #473
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
Chi 1967 productionize lex pre survey chatbot test #473
Conversation
|
@acedeywin The issue you are currently having here is related to how you are mocking things. See that in while in The second means |
|
@acedeywin Also, can you merge this PR against my branch instead than master? I'd prefer to have the other one merged against master, cause there's a lot of important details in the description. |
@gpaoloni - I have tried implementing the mock both as a function using |
@gpaoloni - Yes, that has been done. |
|
@gpaoloni - Finally got to the root cause of why the unit tests for The major issues I encountered were properly mocking handlerPath and lexClient. With further investigation, I implemented the mock for |
|
@acedeywin @gpaoloni - this PR will be easiuer to review if both the PR branch and the target branch have Murilo's asset changes merged in :-) |
@stephenhand - It's done |
| expect(context.getTwilioClient().chat.services().channels().fetch).toHaveBeenCalled(); | ||
|
|
||
| if ( | ||
| event.EventType === 'onMessageSent' && |
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.
This is always true?
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.
@stephenhand - It can be false but for us to to be able to test the codes within the if block, we must check that EventType === 'onMessageSent' && fromServiceUser === From.
The should handle the event and ignore it is to test when EventType === 'onMessageSent' && fromServiceUser === From is false
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.
But for this test, you explicitly set it to 'onMessageSent' at the start of the test, so there's no point in checking it here, we know it's set to that already.
The same with the attributes.fromServiceUser, the attributes set up as a response to a mock in this test, so they will always have the expected values, the 'if' condition is only checking the value of your own mock against some test data that also gets assigned in the test, not any production code. You could remove the call to the mock on line 155 and this check and the testwould be still testing the same production behaviour.
Generally 'if' blocks in tests should be considered a smell. If this 'if' condition is ever false, it will result in the rest of the test being bypassed completely and passing because none of the assertions get checked. I assume this wouldn't be desirable, we should actually fail the test if this condition was ever not true, so the if statement would be replaced with some assertions.
But in this case I don't think the checks in the 'if' condition are adding any value to the test at all and it can just be removed
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.
@stephenhand - I see what you mean in the comment. I can set From to equal attributes.fromServiceUser, and since EventType is already onMessageSent, the test will pass—the if block is unnecessary. I have gone ahead and made the necessary changes.
| }); | ||
|
|
||
| expect(lexClient.postText).toHaveBeenCalledWith(...expectedPostTextArgs); | ||
| expect(createMessageMock).toHaveBeenCalledWith({ |
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.
It is pointless to verify a method that is called directly from the test, this doesn't verify anything about the production code.
In fact it looks like none of the stuff around creating a mock message would maqke any difference, because it's all mocked - apart from the verification on line 195 that looks to test some production behaviour, the other bit just looks to set up some mocked code and then test the mocks?
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.
@stephenhand - Yes, Steve. You are absolutely correct. I was using it to test if that actual mock would work as expected. I will go ahead and remove it.
stephenhand
left a comment
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.
LGTM!
Description
Checklist
Related Issues
Fixes CHI-1967
Verification steps