From e289f2c792f99fb200aa2cf78c082478a9279dc5 Mon Sep 17 00:00:00 2001 From: "Michael J. Roberts" <84131395+michealroberts@users.noreply.github.com> Date: Fri, 14 Jul 2023 12:03:26 +0100 Subject: [PATCH] feat: Added client.telescope.shutdown() route handler. feat: Added client.telescope.shutdown() route handler. Includes associated test suite for module export definition and expected output from API route. --- src/routes/telescope.ts | 17 +++++++++++++++++ tests/mocks/telescope.ts | 25 +++++++++++++++++++++++++ tests/telescopeRoutes.spec.ts | 17 +++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/src/routes/telescope.ts b/src/routes/telescope.ts index 0cc0005..3c08626 100644 --- a/src/routes/telescope.ts +++ b/src/routes/telescope.ts @@ -103,6 +103,23 @@ export const telescope = ( return dispatchRequest(url, { ...init, method: 'PUT' }, headers) } }, + { + name: 'shutdown', + action: < + T = { + connected: boolean + slewing: boolean + tracking: boolean + parked: boolean + home: boolean + utc: string + } + >() => { + const url = new URL('telescope/shutdown', base) + + return dispatchRequest(url, { ...init, method: 'PUT' }, headers) + } + }, { name: 'connect', action: < diff --git a/tests/mocks/telescope.ts b/tests/mocks/telescope.ts index 4e85c61..446a4c8 100644 --- a/tests/mocks/telescope.ts +++ b/tests/mocks/telescope.ts @@ -97,6 +97,31 @@ export const telescopeHandlers: Handler[] = [ } }) }, + { + method: 'PUT', + url: '/api/v1/telescope/shutdown', + handler: eventHandler(event => { + const method = getMethod(event) + + if (method !== 'PUT') { + return new Response('Method Not Allowed', { + status: 405, + statusText: 'Method Not Allowed' + }) + } + + const utc = new Date('2021-05-14T00:00:00.000+00:00').toISOString() + + return { + connected: false, + slewing: false, + tracking: false, + parked: true, + home: false, + utc + } + }) + }, { method: 'PUT', url: '/api/v1/telescope/connect', diff --git a/tests/telescopeRoutes.spec.ts b/tests/telescopeRoutes.spec.ts index 4296401..8ddbf6e 100644 --- a/tests/telescopeRoutes.spec.ts +++ b/tests/telescopeRoutes.spec.ts @@ -79,6 +79,23 @@ suite('@observerly/hyper Fiber API Telescope Client', () => { expect(init).toStrictEqual({ connected: true }) }) + it('should be able to shutdown the telescope', async () => { + const client = setupClient(getURL('/api/v1/')) + const shutdown = await client.telescope.shutdown() + expect(isDataResult(shutdown)).toBe(true) + if (!isDataResult(shutdown)) return + // Create a UTC now string: + const utc = new Date('2021-05-14T00:00:00.000+00:00').toISOString() + expect(shutdown).toStrictEqual({ + connected: false, + slewing: false, + tracking: false, + parked: true, + home: false, + utc + }) + }) + it('should be able to connect to the telescope', async () => { const client = setupClient(getURL('/api/v1/')) const connect = await client.telescope.connect()