Skip to content

Conversation

JuanAr
Copy link
Collaborator

@JuanAr JuanAr commented Aug 23, 2018

Tests in qnaMaker.test.js were adapted to use Nock and retrieve responses stored in JSON files.

  • Each test is coupled with mocked responses in JSON files named after each test.
  • For tests with multiple service calls, mocked responses have an incremental numeric suffix to be queued following that order.
  • A test was added to validate a response for a question with no correct answers after receiving a response with correct answers.
  • All asserts were changed to assert.strictEqual, and an error message was added for each assert.
  • Inline explicit timeout was removed.
  • In case the hostname environment variable is not defined, a default one is used by Nock
  • A flag variable mockQnA was added to toggle between using the service or the mocked responses

@JuanAr JuanAr force-pushed the southworks/qna/test-mocks branch from 5fcb47f to dd5e24e Compare August 23, 2018 18:03
@coveralls
Copy link

coveralls commented Aug 23, 2018

Pull Request Test Coverage Report for Build 1118

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 7 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+2.0%) to 68.503%

Files with Coverage Reduction New Missed Lines %
libraries/botframework-config/src/botConfiguration.ts 7 87.42%
Totals Coverage Status
Change from base Build 989: 2.0%
Covered Lines: 2071
Relevant Lines: 2850

💛 - Coveralls

@JuanAr JuanAr requested a review from Stevenic August 27, 2018 16:07
const endpointKey = process.env.QNAENDPOINTKEY;
const hostname = process.env.QNAHOSTNAME;
const hostname = process.env.QNAHOSTNAME || 'botbuilder-test-app';
const mockQnA = true;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be dependent on earlier variables? Something that looks more like this:

const mockQna = knowledgeBaseId && endpointKey && hostname !== 'botbuilder-test-app';

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We'll include this logic. Moreover, we'll include an override flag to force using the mocks.

return;
console.warn('WARNING: QnAMaker test suite QNAENDPOINTKEY environment variable is not defined');
}
if (!hostname) {
Copy link
Member

Choose a reason for hiding this comment

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

This check is no longer necessary because hostname is always defined via L10.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, we'll remove this.

assert(res);
assert(res.length == 1);
assert(res[0].answer.startsWith("BaseCamp: You can use a damp rag to clean around the Power Pack"));
assert.strictEqual(typeof res !== 'undefined', true, 'The response was returned as \'undefined\'.');
Copy link
Member

Choose a reason for hiding this comment

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

This seems needlessly complex... Since I'm assuming the QnAMaker and our API never returns an undefined or null we should just verify that a response exists (look for a truthy value). So instead we should use:

assert(res, `A valid response was not returned.`);

Otherwise if we should check for undefined we can use:

assert.strictNotEqual(res, undefined, `The response was returned as 'undefined'.`);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We'll use the second option, to keep consistency between all the asserts.

return qna.generateAnswer(`how do I clean the stove?`)
.then(res => {
assert.strictEqual(typeof res !== 'undefined', true, 'The response was returned as \'undefined\'.');
assert.strictEqual(res.length, 1, 'Should have receive just one answer on the first call.');
Copy link
Member

Choose a reason for hiding this comment

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

"received"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We'll fix this typo.

- Modified the logic for `mockQnA` flag.
- Added an override flag to force the use of mocks.
- Removed the warning for missing `hostname` environment variable.
- Replaced `assert.strictEqual` with `assert.notStrictEqual` where necessary.
- Fixed several typos.
- Replaced escaped backslashes with ticks.
@JuanAr
Copy link
Collaborator Author

JuanAr commented Aug 28, 2018

@stevengum we applied your feedback. Thanks!

@stevengum
Copy link
Member

@JuanAr, can you look into why the build is failing, and also include an explicit console log that indicates if the mocks (nocks?) are running.

- additionally fixed minor tracing bug
@JuanAr JuanAr merged commit 4c22fa3 into master Aug 31, 2018
@JuanAr JuanAr deleted the southworks/qna/test-mocks branch August 31, 2018 16:00
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.

3 participants