Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added missing mock geo data #5231

Merged
merged 9 commits into from
Nov 16, 2022
9 changes: 9 additions & 0 deletions src/lib/geo-location.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ const REQUEST_TIMEOUT = 1e4
* @property {object} subdivision
* @property {string} subdivision.code
* @property {string} subdivision.name
* @property {number} longitude
* @property {number} latitude
* @property {string} timezone
*/

const mockLocation = {
city: 'San Francisco',
country: { code: 'US', name: 'United States' },
subdivision: { code: 'CA', name: 'California' },
longitude: 0,
latitude: 0,
timezone: 'UTC',
}

/**
Expand Down Expand Up @@ -71,6 +77,9 @@ const getGeoLocation = async ({ geoCountry, mode, offline, state }) => {
city: 'Mock City',
country: { code: geoCountry, name: 'Mock Country' },
subdivision: { code: 'SD', name: 'Mock Subdivision' },
longitude: 0,
latitude: 0,
timezone: 'UTC',
}
}
return mockLocation
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/lib/geo-location.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ test('`getGeoLocation` returns mock geolocation data if valid country code set',
city: 'Mock City',
country: { code: 'CA', name: 'Mock Country' },
subdivision: { code: 'SD', name: 'Mock Subdivision' },
latitude: 0,
longitude: 0,
timezone: 'UTC',
}

const mockState = {
Expand All @@ -144,6 +147,9 @@ test('`getGeoLocation` mocks country code when not using mock flag', async (t) =
city: 'Mock City',
country: { code: 'CA', name: 'Mock Country' },
subdivision: { code: 'SD', name: 'Mock Subdivision' },
latitude: 0,
longitude: 0,
timezone: 'UTC',
}

const geo = await getGeoLocation({ mode: 'update', offline: false, state: mockState, geoCountry: 'CA' })
Expand Down