-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update logic * update package * add test * update jest config
- Loading branch information
1 parent
b52334a
commit a03cab1
Showing
7 changed files
with
87 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import { getGeoloc } from 'geo-locate'; | ||
|
||
describe('getGeoLoc runs as expected', () => { | ||
|
||
beforeEach(() => { | ||
|
||
global.fetch = jest.fn(() => | ||
Promise.resolve({ | ||
json: () => Promise.resolve( {"country": "US", "is_eu": false, "app_region": "us1"} ), | ||
}) | ||
); | ||
|
||
// set up window, localStorage mock | ||
window.document.url = 'localhost'; | ||
window.Storage = true; | ||
window.localStorage.__proto__.getItem = jest.fn(); | ||
window.localStorage.__proto__.setItem = jest.fn(); | ||
}); | ||
|
||
it('Should default US as the country and us1 as the region', () => { | ||
// run geo function | ||
getGeoloc().then((loc) => { | ||
expect(loc.country).toBe('US'); | ||
expect(loc.appRegion).toBe('us1'); | ||
|
||
// make sure setItem is called | ||
expect(localStorage.setItem).toHaveBeenCalled(); | ||
}); | ||
|
||
// fetch was executed as well | ||
expect(fetch).toHaveBeenCalledWith( | ||
"https://corpsite-staging.datadoghq.com/locate" | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
targets: { | ||
node: 'current' | ||
} | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
transformIgnorePatterns: ['<rootDir>/node_modules/(?!geo-locate)'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters