<commit_before><commit_msg>Add toQueryString test suite<commit_after>import { toQueryString } from '../data';

describe('DataUtil', () => {
  let params;
  beforeEach(() => {
    params = {
      text: 'Birthday',
      dates: '20170508/20170509'
    }
  })
  describe('toQueryString()', () => {

    it('should create a query string representation of the passed in object', () => {
      const queryString = toQueryString(params)
      const queryParams = queryString.split('&')
      const paramKeys = Object.keys(params).sort()
      const queryKeys = queryParams.map(param => param.split('=')[0])
      queryKeys.sort()
      expect(queryKeys).toEqual(paramKeys)
    })

    it('should URI encode params', () => {
      const queryString = toQueryString(params)
      const queryParams = queryString.split('&')
      for (let kv of queryParams) {
        const [key, queryValue] = kv.split('=')
        const uriEncodedValue = encodeURIComponent(params[key])

        expect(queryValue).toBe(uriEncodedValue)
      }
    })

    it('should ignore undefined values', () => {
      params.foo = undefined
      const queryString = toQueryString(params)
      const queryParams = queryString.split('&')
      const queryKeys = queryParams.map(param => param.split('=')[0])

      expect(queryKeys).not.toContain('foo')
    })
  })
})

{'fraction_non_alphanumeric': 0.14831460674157304, 'fraction_numerical': 0.01348314606741573, 'mean_word_length': 3.1490683229813663, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4647568', 'n_tokens_mistral': 406, 'n_tokens_neox': 392, 'n_words': 83}