From 31d0a86485b9b0b7e40d1eaca7a84bad9cc0edd4 Mon Sep 17 00:00:00 2001 From: "Michael J. Roberts" Date: Fri, 21 Apr 2023 17:54:35 +0100 Subject: [PATCH] feat: Added client.telescope.getCoordinates() route handler. feat: Added client.telescope.getCoordinates() route handler. Includes associated test suite for module export definition and expected output from API route. --- src/routes/telescope.ts | 14 ++++++++++++++ tests/mocks/telescope.ts | 12 ++++++++++++ tests/setup.ts | 1 + tests/telescopeRoutes.spec.ts | 21 +++++++++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/src/routes/telescope.ts b/src/routes/telescope.ts index 92c425b..0864b96 100644 --- a/src/routes/telescope.ts +++ b/src/routes/telescope.ts @@ -62,6 +62,20 @@ export const telescope = ( return dispatchRequest(url, init, headers) } }, + { + name: 'getCoordinates', + action: < + T = { + ra: number + dec: number + az: number + alt: number + } + >() => { + const url = new URL('telescope/coordinates', base) + return dispatchRequest(url, init, headers) + } + }, { name: 'initialise', action: < diff --git a/tests/mocks/telescope.ts b/tests/mocks/telescope.ts index 78f9bff..831c536 100644 --- a/tests/mocks/telescope.ts +++ b/tests/mocks/telescope.ts @@ -51,6 +51,18 @@ export const telescopeHandlers: Handler[] = [ } }) }, + { + method: 'GET', + url: '/api/v1/telescope/coordinates', + handler: eventHandler(_event => { + return { + ra: 34.5619912, + dec: 56.1234567, + alt: 34.5619912, + az: 56.1234567 + } + }) + }, { method: 'PUT', url: '/api/v1/telescope/init', diff --git a/tests/setup.ts b/tests/setup.ts index 6dce45e..4a9f3ba 100644 --- a/tests/setup.ts +++ b/tests/setup.ts @@ -42,6 +42,7 @@ export const setupClient = (url: string) => { base: new URL(url), headers: async () => { return new Headers({ + Accept: 'application/json', 'X-API-Key': `Key <>` }) } diff --git a/tests/telescopeRoutes.spec.ts b/tests/telescopeRoutes.spec.ts index 383e05c..7684f74 100644 --- a/tests/telescopeRoutes.spec.ts +++ b/tests/telescopeRoutes.spec.ts @@ -61,6 +61,27 @@ suite('@observerly/hyper Fiber API Telescope Client', () => { expect(connected).toBe(false) }) + it('should be able to get the equatorial and horizontal coordinates of the telescope', async () => { + const client = setupClient(getURL('/api/v1/')) + const { ra, dec, az, alt } = await client.telescope.getCoordinates() + + // Right Ascension should be between 0 and 360 + expect(ra).toBeGreaterThanOrEqual(0) + expect(ra).toBeLessThan(360) + + // Declination should be between -90 and 90 + expect(dec).toBeGreaterThan(-90) + expect(dec).toBeLessThan(90) + + // Azimuth should be between 0 and 360 + expect(az).toBeGreaterThanOrEqual(0) + expect(az).toBeLessThan(360) + + // Altitude should be between -90 and 90 + expect(alt).toBeGreaterThan(-90) + expect(alt).toBeLessThan(90) + }) + it('should be able to set the equatorial coordinates of the telescope', async () => { const client = setupClient(getURL('/api/v1/')) const { slewing } = await client.telescope.slewToEquatorialCoordinate({