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

fix: Make getTopScoringIntent return '' instead of undefined #3870

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/botbuilder-core/src/recognizerResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const getTopScoringIntent = (result: RecognizerResult): { intent: string;
throw new Error('result is empty');
}

let topIntent: string;
let topIntent: string = '';
let topScore = -1;
for (const [intentName, intent] of Object.entries(result.intents)) {
const score = intent.score ?? -1;
Expand Down
16 changes: 16 additions & 0 deletions libraries/botbuilder-core/tests/getTopScoringIntent.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const assert = require('assert');
const { getTopScoringIntent} = require('../lib');

describe('getTopScoringIntent', function () {
it(' should never return undefined', function () {
let result = getTopScoringIntent({
text: '',
intents: {},
entities: {}
});

assert.notStrictEqual(result.intent, undefined);
assert.strictEqual(result.intent, '');
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class CrossTrainedRecognizerSet extends AdaptiveRecognizer implements Cro
* @returns {boolean} Boolean result of whether or not an intent begins with the `DeferToRecognizer_` prefix.
*/
private isRedirect(intent: string): boolean {
return intent.startsWith(deferPrefix);
return intent?.startsWith(deferPrefix) ?? false;
}

/**
Expand Down