import { parseQuery, _extractFilters } from '../urlParser'

describe('_extractFilters', () => {
  it('should return filters array', () => {
    const qs = { keywords: 'bar', organizations: 'foo' }
    const filters = [
      {name: 'keywords', value: 'bar'},
      {name: 'organizations', value: 'foo'},
    ]
    const extractedFilters = _extractFilters(qs)

    expect(extractedFilters).toEqual(filters)
  })

  it('should return only allowed filters', () => {
    const qs = { keywords: 'bar', notAllowed: 'foo' }
    const filters = [
      {name: 'keywords', value: 'bar'},
    ]
    const extractedFilters = _extractFilters(qs)

    expect(extractedFilters).toEqual(filters)
  })

  it('should create one items for each value', () => {
    const qs = { keywords: ['foo', 'bar'] }
    const filters = [
      {name: 'keywords', value: 'foo'},
      {name: 'keywords', value: 'bar'},
    ]
    const extractedFilters = _extractFilters(qs)

    expect(extractedFilters).toEqual(filters)
  })
})

describe('parseQuery', () => {
  it('should regroupe chaque clef dans un même array', () => {
    const query = 'q=42&page=2&keywords=keyword1&keywords=keyword2&organizations=foo'
    const result = parseQuery(query)

    expect(result).toEqual(
      {
        textInput: '42',
        page: '2',
        filters: [
          {name: 'keywords', value: 'keyword1'},
          {name: 'keywords', value: 'keyword2'},
          {name: 'organizations', value: 'foo'},
        ],
      }
    )
  })
})

@@ -149,33 +149,32 @@
 t qs = %7B keyword
-s
 : 'bar', organiz
@@ -178,17 +178,16 @@
 nization
-s
 : 'foo' 
@@ -223,33 +223,32 @@
  %7Bname: 'keyword
-s
 ', value: 'bar'%7D
@@ -267,33 +267,32 @@
 e: 'organization
-s
 ', value: 'foo'%7D
@@ -476,17 +476,16 @@
  keyword
-s
 : 'bar',
@@ -540,33 +540,32 @@
  %7Bname: 'keyword
-s
 ', value: 'bar'%7D
@@ -753,17 +753,16 @@
  keyword
-s
 : %5B'foo'
@@ -807,33 +807,32 @@
  %7Bname: 'keyword
-s
 ', value: 'foo'%7D
@@ -846,33 +846,32 @@
  %7Bname: 'keyword
-s
 ', value: 'bar'%7D
@@ -1031,47 +1031,34 @@
 uld 
+c
 re
-groupe chaque clef dans un m%C3%AAme array
+ate an array of filters
 ', (
@@ -1094,33 +1094,32 @@
 2&page=2&keyword
-s
 =keyword1&keywor
@@ -1119,17 +1119,16 @@
 &keyword
-s
 =keyword
@@ -1141,17 +1141,16 @@
 nization
-s
 =foo'%0A  
@@ -1301,33 +1301,32 @@
  %7Bname: 'keyword
-s
 ', value: 'keywo
@@ -1357,17 +1357,16 @@
 'keyword
-s
 ', value
@@ -1410,17 +1410,16 @@
 nization
-s
 ', value

Update tests