Skip to content

Commit

Permalink
added a test
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Nov 30, 2021
1 parent ece4759 commit 57ddb24
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import axios from 'axios';
import { getServiceLocations } from './get_service_locations';
jest.mock('axios');
const mockedAxios = axios as jest.Mocked<typeof axios>;

describe('getServiceLocations', function () {
mockedAxios.get.mockRejectedValue('Network error: Something went wrong');
mockedAxios.get.mockResolvedValue({
data: {
locations: {
us_central: {
url: 'https://local.dev',
geo: {
name: 'US Central',
location: { lat: 41.25, lon: -95.86 },
},
status: 'beta',
},
},
},
});
it('should return parsed locations', async () => {
const locations = await getServiceLocations({
config: {
unsafe: {
service: {
manifestUrl: 'http://local.dev',
},
},
},
});

expect(locations).toEqual([
{
geo: {
lat: 41.25,
lon: -95.86,
},
id: 'us_central',
label: 'US Central',
},
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function getServiceLocations({ config }: { config: UptimeConfig })
try {
const { data } = await axios.get<Record<string, ManifestLocation>>(manifestURL);

Object.entries(data).forEach(([locationId, location]) => {
Object.entries(data.locations).forEach(([locationId, location]) => {
locations.push({
id: locationId,
label: location.geo.name,
Expand Down

0 comments on commit 57ddb24

Please sign in to comment.