From aeabc303ad948622fa7c73678378942dc4527dfc Mon Sep 17 00:00:00 2001 From: Tokyo Date: Wed, 14 Oct 2020 20:11:31 +0200 Subject: [PATCH] :white_check_mark: raise coverage --- README.md | 4 ++-- __tests__/index.test.js | 19 +++++++++++++++++++ src/index.js | 4 ++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5458e7e..41fde6a 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ - - + + Follow @ahmad_tokyo diff --git a/__tests__/index.test.js b/__tests__/index.test.js index e7387f0..dd64ab5 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -66,6 +66,25 @@ describe('index Test', () => { }); it('Returns proper schema with timeout', async () => { + const result = await geodecodeIp('207.97.227.239', { timeout: 1000 * 3 }); + expect(result).toEqual( + expect.objectContaining({ + ip: '207.97.227.239', + range: [3479298048, 3479302143], + country: 'US', + region: 'TX', + eu: '0', + timezone: 'America/Chicago', + city: 'San Antonio', + ll: [29.4963, -98.4004], + metro: 641, + area: 1000, + }), + ); + expect(result.error).toEqual(undefined); + }); + + it('Returns proper schema with timeout AND NO IP', async () => { const result = await geodecodeIp(undefined, { timeout: 1000 * 3 }); expect(result).toEqual( expect.objectContaining({ diff --git a/src/index.js b/src/index.js index 62cdcc5..6f88c81 100644 --- a/src/index.js +++ b/src/index.js @@ -29,8 +29,8 @@ const geodecodeIp = ( error?: string, }> => ky( - `${serviceUrl || SERVICE_URL_GEOIP}${ - ip ? `?ip=${ip}${timeout ? `&timeout=${timeout}` : ''}` : '' + `${serviceUrl || SERVICE_URL_GEOIP}${ip ? `?ip=${ip}` : ''}${ + timeout ? `${ip ? '&' : '?'}timeout=${timeout}` : '' }`, ) .then((res) => res.json())