diff --git a/x-pack/plugins/uptime/server/lib/synthetics_service/get_service_locations.test.ts b/x-pack/plugins/uptime/server/lib/synthetics_service/get_service_locations.test.ts new file mode 100644 index 0000000000000..375ceffe492da --- /dev/null +++ b/x-pack/plugins/uptime/server/lib/synthetics_service/get_service_locations.test.ts @@ -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; + +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', + }, + ]); + }); +}); diff --git a/x-pack/plugins/uptime/server/lib/synthetics_service/get_service_locations.ts b/x-pack/plugins/uptime/server/lib/synthetics_service/get_service_locations.ts index 5eb3028b55300..fdd24ed2394b2 100644 --- a/x-pack/plugins/uptime/server/lib/synthetics_service/get_service_locations.ts +++ b/x-pack/plugins/uptime/server/lib/synthetics_service/get_service_locations.ts @@ -15,7 +15,7 @@ export async function getServiceLocations({ config }: { config: UptimeConfig }) try { const { data } = await axios.get>(manifestURL); - Object.entries(data).forEach(([locationId, location]) => { + Object.entries(data.locations).forEach(([locationId, location]) => { locations.push({ id: locationId, label: location.geo.name,