Skip to content

Commit

Permalink
Handle intents without a query slot (#19)
Browse files Browse the repository at this point in the history
* Handle intents without a query slot

* Handle cases where there are no intents
  • Loading branch information
dustincoates committed Aug 23, 2017
1 parent 3141e1e commit 5e09a1c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/utils/build_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ function buildFromObject(obj, index, stateString) {
object[key] = function() {
const args = {event: this.event};
const params = buildParams(paramsObj, this.event);
let query = '';
if (args.event.request.intent.slots && args.event.request.intent.slots.query) {
query = args.event.request.intent.slots.query.value;
}

index
.search(args.event.request.intent.slots.query.value, params)
.search(query, params)
.then((results, err) => {
Object.assign(args, {err, results});
func.call(this, args);
Expand Down
13 changes: 11 additions & 2 deletions test/utils/build_handlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,19 @@ describe('handlers', () => {

describe('with answerWith', () => {
describe('without params to merge', () => {
const expectedParams = {};

describe('without a query slot', () => {
const withoutQuery = JSON.parse(JSON.stringify(scope));
delete withoutQuery.event.request.intent.slots;

builtHandlers[0].spyIntent.call(withoutQuery);

expect(searchSpy).toHaveBeenCalledWith('', expectedParams);
});

describe('when handler is invoked', () => {
it('searches Algolia', () => {
const expectedParams = {};

builtHandlers[0].spyIntent.call(scope);

expect(searchSpy).toHaveBeenCalledWith(expectedQuery, expectedParams);
Expand Down

0 comments on commit 5e09a1c

Please sign in to comment.