import { expect, should, assert } from 'chai'

import URLHelper from '../../../lib/Utils/URLHelper'
import mocks from '../../mocks'

describe('URLHelper', function() {
    describe('stringifyOptions', function() {
        it('should be empty string with no options', function() {
            const { none: opts } = mocks.options
            const actual = URLHelper.stringifyOptions(opts)
            expect(actual).to.equal('')
        })
        it('should be correct with single option', function() {
            const { single: opts } = mocks.options
            const actual = URLHelper.stringifyOptions(opts)
            expect(actual).to.equal('name=Contractz')
        })
        it('should be correct with multiple options', function() {
            const { multiple: opts } = mocks.options
            const actual = URLHelper.stringifyOptions(opts)
            expect(actual).to.equal('name=poz&rank=challenger')
        })
    })

    describe('getQueryParamString', function() {
        it('should get the correct query param string', function() {
            const { multiple: opts } = mocks.options
            const arrayOfOpts = Object.keys(opts).map(k => ({
                [k]: opts[k],
            }))
            const actual = URLHelper.getQueryParamString(arrayOfOpts)
            expect(actual).to.equal('?name=poz&rank=challenger')
        })

        it('should get the encoded string', function() {
            const { multipleEncoded: opts } = mocks.options
            const arrayOfOpts = Object.keys(opts).map(k => ({
                [k]: opts[k],
            }))
            const actual = URLHelper.getQueryParamString(arrayOfOpts)
            expect(actual).to.equal('?name=T%C3%A9st&rank=%C3%B3h%20no')
        })
    })

    describe('createRequestURL', function() {
        it('should create a request URL', function() {
            const url = URLHelper.createRequestURL(
                'na1',
                'tournament',
                'endpoint',
                '1',
            )
            expect(actual).to.equal(
                'https://na1.api.riotgames.com/lol/tournament/v4/endpoint',
            )
        })

        it('should create a request URL with a custom API URL prefix', function() {
            const url = URLHelper.createRequestURL(
                'na1',
                'tournament',
                'endpoint',
                '1',
                'http://%s.localhost',
            )
            expect(actual).to.equal(
                'http://na1.localhost/lol/tournament/v4/endpoint',
            )
        })

        it('should create a request URL with a custom API URL prefix with no platform ID', function() {
            const url = URLHelper.createRequestURL(
                'na1',
                'tournament',
                'endpoint',
                '1',
                'http://localhost',
            )
            expect(actual).to.equal(
                'http://localhost/lol/tournament/v4/endpoint',
            )
        })
    })
})

@@ -148,32 +148,33 @@
 elper', function
+ 
 () %7B%0A    describ
@@ -195,32 +195,33 @@
 tions', function
+ 
 () %7B%0A        it(
@@ -262,32 +262,33 @@
 tions', function
+ 
 () %7B%0A           
@@ -487,32 +487,33 @@
 ption', function
+ 
 () %7B%0A           
@@ -731,32 +731,33 @@
 tions', function
+ 
 () %7B%0A           
@@ -977,32 +977,33 @@
 tring', function
+ 
 () %7B%0A        it(
@@ -1047,32 +1047,33 @@
 tring', function
+ 
 () %7B%0A           
@@ -1413,32 +1413,33 @@
 tring', function
+ 
 () %7B%0A           
@@ -1790,32 +1790,33 @@
 stURL', function
+ 
 () %7B%0A        it(
@@ -1846,32 +1846,33 @@
 t URL', function
+ 
 () %7B%0A           
@@ -1870,34 +1870,37 @@
           const 
-ur
+actua
 l = URLHelper.cr
@@ -2005,36 +2005,83 @@
                '
-1
+4
 ',%0A
+                'https://%25s.api.riotgames.com'%0A
             )%0A  
@@ -2288,32 +2288,33 @@
 refix', function
+ 
 () %7B%0A           
@@ -2312,34 +2312,37 @@
           const 
-ur
+actua
 l = URLHelper.cr
@@ -2447,33 +2447,33 @@
                '
-1
+4
 ',%0A             
@@ -2741,16 +2741,17 @@
 function
+ 
 () %7B%0A   
@@ -2765,18 +2765,21 @@
   const 
-ur
+actua
 l = URLH
@@ -2900,17 +2900,17 @@
        '
-1
+4
 ',%0A     

test (URLHelper): Fix tests