Skip to content

Commit 218dd32

Browse files
committed
Add search feedback, with tests
1 parent d3f1fa5 commit 218dd32

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

src/Inputs.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
let axios = require('axios');
22
let Input = require('./Input');
33
let {API, ERRORS, MAX_BATCH_SIZE, replaceVars} = require('./constants');
4-
let {INPUT_PATH, INPUTS_PATH, INPUTS_STATUS_PATH, SEARCH_PATH} = API;
4+
let {INPUT_PATH, INPUTS_PATH, INPUTS_STATUS_PATH, SEARCH_PATH, SEARCH_FEEDBACK_PATH} = API;
55
let {wrapToken, formatInput, formatImagesSearch, formatConceptsSearch} = require('./utils');
66
let {isSuccess, checkType, clone} = require('./helpers');
77

@@ -294,6 +294,32 @@ class Inputs {
294294
});
295295
}
296296

297+
searchFeedback(inputID, searchID, endUserID, sessionID) {
298+
let url = `${this._config.basePath}${SEARCH_FEEDBACK_PATH}`;
299+
const body = {
300+
input: {
301+
id: inputID,
302+
feedback_info: {
303+
event_type: 'search_click',
304+
search_id: searchID,
305+
end_user_id: endUserID,
306+
session_id: sessionID
307+
}
308+
}
309+
};
310+
return wrapToken(this._config, headers => {
311+
return new Promise((resolve, reject) => {
312+
axios.post(url, body, {
313+
headers
314+
}).then(({data}) => {
315+
const d = clone(data);
316+
d.rawData = clone(data);
317+
resolve(d);
318+
}, reject);
319+
});
320+
});
321+
}
322+
297323
/**
298324
* Get inputs status (number of uploaded, in process or failed inputs)
299325
* @return {Promise(response, error)} A Promise that is fulfilled with the API response or rejected with an error

src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = {
2929
INPUT_PATH: '/inputs/$0',
3030
INPUTS_STATUS_PATH: '/inputs/status',
3131
SEARCH_PATH: '/searches',
32+
SEARCH_FEEDBACK_PATH: '/searches/feedback',
3233
WORKFLOWS_PATH: '/workflows',
3334
WORKFLOW_PATH: '/workflows/$0',
3435
WORKFLOW_RESULTS_PATH: '/workflows/$0/results'

tests/unit/feedback-unit-tests.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,39 @@ describe('Unit Tests - Concepts', () => {
132132
})
133133
.catch(errorHandler.bind(done));
134134
});
135+
136+
it('Searches feedback', done => {
137+
mock.onPost(BASE_URL + '/v2/searches/feedback').reply(200, JSON.parse(`
138+
{
139+
"status": {
140+
"code": 10000,
141+
"description": "Ok"
142+
}
143+
}
144+
`));
145+
146+
app.inputs.searchFeedback("@inputID", "@searchID", "@endUserID", "@sessionID")
147+
.then(response => {
148+
expect(mock.history.post.length).toBe(1);
149+
150+
expect(JSON.parse(mock.history.post[0].data)).toEqual(JSON.parse(`
151+
{
152+
"input": {
153+
"id": "@inputID",
154+
"feedback_info": {
155+
"event_type": "search_click",
156+
"search_id": "@searchID",
157+
"end_user_id": "@endUserID",
158+
"session_id": "@sessionID"
159+
}
160+
}
161+
}
162+
`));
163+
164+
expect(response.status.code).toBe(10000);
165+
166+
done();
167+
})
168+
.catch(errorHandler.bind(done));
169+
});
135170
});

0 commit comments

Comments
 (0)