From d4fdb2b4697804e0f91ba59450504a099f10aec9 Mon Sep 17 00:00:00 2001 From: "Michael J. Roberts" Date: Mon, 24 Apr 2023 21:32:14 +0100 Subject: [PATCH] feat: Added client.filterwheel.initialise() route handler. feat: Added client.filterwheel.initialise() route handler. Includes associated test suite for module export definition and expected output from API route. --- src/routes/filterwheel.ts | 11 +++++++++++ tests/filterwheelRoutes.spec.ts | 8 ++++++++ tests/mocks/filterwheel.ts | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/routes/filterwheel.ts b/src/routes/filterwheel.ts index f9ba8a1..c71642f 100644 --- a/src/routes/filterwheel.ts +++ b/src/routes/filterwheel.ts @@ -48,5 +48,16 @@ export const filterwheel = ( const url = new URL('filterwheel/names', base) return dispatchRequest(url, init, headers) } + }, + { + name: 'initialise', + action: < + T = { + connected: boolean + } + >() => { + const url = new URL('filterwheel/init', base) + return dispatchRequest(url, { ...init, method: 'PUT' }, headers) + } } ] as const diff --git a/tests/filterwheelRoutes.spec.ts b/tests/filterwheelRoutes.spec.ts index 27c625f..3a58a36 100644 --- a/tests/filterwheelRoutes.spec.ts +++ b/tests/filterwheelRoutes.spec.ts @@ -41,5 +41,13 @@ suite('@observerly/hyper Fiber API Filterwheel Client', () => { if (!isDataResult(names)) return expect(names).toStrictEqual({ names: ['R', 'G', 'B', 'Ha', 'OIII', 'SII', 'L'] }) }) + + it('should be able to initialise the filterwheel', async () => { + const client = setupClient(getURL('/api/v1/')) + const init = await client.filterwheel.initialise() + expect(isDataResult(init)).toBe(true) + if (!isDataResult(init)) return + expect(init).toStrictEqual({ connected: true }) + }) }) }) diff --git a/tests/mocks/filterwheel.ts b/tests/mocks/filterwheel.ts index e8f8b1e..c2d7806 100644 --- a/tests/mocks/filterwheel.ts +++ b/tests/mocks/filterwheel.ts @@ -39,5 +39,23 @@ export const filterwheelHandlers: Handler[] = [ names: ['R', 'G', 'B', 'Ha', 'OIII', 'SII', 'L'] } }) + }, + { + method: 'PUT', + url: '/api/v1/filterwheel/init', + handler: eventHandler(async event => { + const method = getMethod(event) + + if (method !== 'PUT') { + return new Response('Method Not Allowed', { + status: 405, + statusText: 'Method Not Allowed' + }) + } + + return { + connected: true + } + }) } ]