diff --git a/client/app/scripts/utils/__tests__/web-api-utils-test.js b/client/app/scripts/utils/__tests__/web-api-utils-test.js index 2609a0364..fe52ac637 100644 --- a/client/app/scripts/utils/__tests__/web-api-utils-test.js +++ b/client/app/scripts/utils/__tests__/web-api-utils-test.js @@ -1,5 +1,7 @@ jest.dontMock('../web-api-utils'); +import {OrderedMap as makeOrderedMap} from 'immutable'; + describe('WebApiUtils', () => { const WebApiUtils = require('../web-api-utils'); @@ -22,4 +24,19 @@ describe('WebApiUtils', () => { expect(basePath('/')).toBe(''); }); }); + + describe('buildOptionsQuery', () => { + const buildOptionsQuery = WebApiUtils.buildOptionsQuery; + + it('should handle empty options', () => { + expect(buildOptionsQuery(makeOrderedMap({}))).toBe(''); + }); + + it('should combine multiple options', () => { + expect(buildOptionsQuery(makeOrderedMap([ + ['foo', 2], + ['bar', 4] + ]))).toBe('foo=2&bar=4'); + }); + }); }); diff --git a/client/app/scripts/utils/web-api-utils.js b/client/app/scripts/utils/web-api-utils.js index f5f0824f1..be3290d59 100644 --- a/client/app/scripts/utils/web-api-utils.js +++ b/client/app/scripts/utils/web-api-utils.js @@ -25,9 +25,9 @@ let controlErrorTimer = 0; let createWebsocketAt = 0; let firstMessageOnWebsocketAt = 0; -function buildOptionsQuery(options) { +export function buildOptionsQuery(options) { if (options) { - return options.reduce((query, value, param) => `${query}&${param}=${value}`, ''); + return options.map((value, param) => `${param}=${value}`).join('&'); } return ''; }