Skip to content

Commit

Permalink
Merge branch 'hotfix/0.1.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
webus committed Aug 28, 2017
2 parents 4b19c4f + 1c076c4 commit 95ea05f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
34 changes: 34 additions & 0 deletions fixtures/apiai/test_response_empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"id": "efe087b8-8486-4117-8863-c63b09a0dd5a",
"timestamp": "2017-08-08T17:06:28.086Z",
"lang": "ru",
"result": {
"source": "agent",
"resolvedQuery": "turbo test",
"action": "action1",
"actionIncomplete": false,
"parameters": { "binType": "Yellow Bin" },
"contexts": [
{ "name": "missed_pickup",
"parameters": { "bintype.original": "yellow", "bintype": "Yellow Bin" },
"lifespan": 1
}
],
"metadata": {
"intentId": "762939a1-36f6-4a99-9de3-349e72ecb7be",
"webhookUsed": "false",
"webhookForSlotFillingUsed": "false",
"intentName": "turboTest"
},
"fulfillment": {
"speech": "",
"messages": []
},
"score": 1
},
"status": {
"code": 200,
"errorType": "success"
},
"sessionId": "35cb38b7-cc7a-4f56-a43c-c00fc3eb13d6"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "botstack",
"version": "0.1.3",
"version": "0.1.4",
"description": "Bot Stack",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 5 additions & 7 deletions src/api-ai.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ function processResponse(response, senderID) {
senderId: senderID
});
return null;
} else if (!lodash.isEmpty(messages)) {
const returnData = {
messages,
response
};
return returnData;
}
return null;
const returnData = {
messages,
response
};
return returnData;
}
return null;
}
Expand Down
29 changes: 29 additions & 0 deletions tests/test_fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,33 @@ describe('Testing FB', () => {
assert.equal(lodash.get(data, '[0].attachment.type'), 'image');
assert.equal(lodash.get(data, '[0].attachment.payload.url'), 'http://example.com/image.jpg');
});

it('Testing with empty response', async () => {
const apiAiTextResponse = require('../fixtures/apiai/test_response_empty.json');
const data = [];

const apiai = require('../src/api-ai');
const apiAiResult = apiai.processResponse(apiAiTextResponse, '1234567890');

rewiremock('./reply').callThought().with({
reply: async (message, senderId) => {
data.push(message);
return true;
}
});

rewiremock.enable();
rewiremock.isolation();

const fb = require(rewiremock.resolve('../src/fb'));

const senderID = '1234567890';
const res = await fb.processMessagesFromApiAi(apiAiResult, senderID);

rewiremock.disable();
rewiremock.clear();

assert.equal(lodash.get(apiAiResult, 'messages').length, 0);
assert.equal(!lodash.isEmpty(lodash.get(apiAiResult, 'response.result.action')), true);
});
});

0 comments on commit 95ea05f

Please sign in to comment.