Skip to content

Commit

Permalink
Merge pull request #60 from Financial-Times/lk/fix-msearch-req-body
Browse files Browse the repository at this point in the history
Fix msearch request body format
  • Loading branch information
kavanagh authored May 11, 2021
2 parents fadb34a + 5ce95e9 commit 67ec261
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/msearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function search (queries = [], timeout = 3000, dataHandler = handleData) {
return accumulator;
}, []);

const body = lines.map(JSON.stringify).join('\n');
const body = lines.map(JSON.stringify).join('\n') + '\n';

return signedFetch('https://next-elasticsearch-v7.gslb.ft.com/content/_msearch', {
body,
Expand Down
4 changes: 2 additions & 2 deletions test/spec/msearch-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('msearch', () => {
it('formats each header and query onto a line', () => {
nock('https://next-elasticsearch-v7.gslb.ft.com')
.post('/content/_msearch', (body) => {
const lines = body.split(/\n/).map(JSON.parse);
const lines = body.split(/\n/).filter(Boolean).map(JSON.parse);

expect(lines.length).to.equal(4);

Expand All @@ -34,7 +34,7 @@ describe('msearch', () => {
it('sets defaults for each query', () => {
nock('https://next-elasticsearch-v7.gslb.ft.com')
.post('/content/_msearch', (body) => {
const lines = body.split(/\n/).map(JSON.parse);
const lines = body.split(/\n/).filter(Boolean).map(JSON.parse);

expect(lines[1]).to.include.keys('query', 'from', 'size', 'sort');
expect(lines[3]).to.include.keys('query', 'from', 'size', 'sort');
Expand Down

0 comments on commit 67ec261

Please sign in to comment.