From d822e53f8cf1f6a77e9922a6daa3050420e68b10 Mon Sep 17 00:00:00 2001 From: "Michael J. Roberts" Date: Fri, 21 Apr 2023 13:33:39 +0100 Subject: [PATCH] feat: Added client.rotator.initialise() route handler. feat: Added client.rotator.initialise() route handler. Includes associated test suite for module export definition and expected output from API route. --- src/routes/rotator.ts | 34 +++++++++++++++++++++++----------- tests/mocks/rotator.ts | 9 +++++++++ tests/rotatorRoutes.spec.ts | 6 ++++++ 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/routes/rotator.ts b/src/routes/rotator.ts index 7c3f00d..394d9e3 100644 --- a/src/routes/rotator.ts +++ b/src/routes/rotator.ts @@ -14,16 +14,28 @@ export const rotator = ( base: URL, init?: RequestInit, headers?: () => Promise | Headers -) => [ - { - name: 'isConnected', - action: < - T = { - connected: boolean +) => + [ + { + name: 'isConnected', + action: < + T = { + connected: boolean + } + >() => { + const url = new URL('rotator/connected', base) + return dispatchRequest(url, init, headers) + } + }, + { + name: 'initialise', + action: < + T = { + connected: boolean + } + >() => { + const url = new URL('rotator/init', base) + return dispatchRequest(url, { ...init, method: 'PUT' }, headers) } - >() => { - const url = new URL('rotator/connected', base) - return dispatchRequest(url, init, headers) } - } -] + ] as const diff --git a/tests/mocks/rotator.ts b/tests/mocks/rotator.ts index c9d5987..ca54134 100644 --- a/tests/mocks/rotator.ts +++ b/tests/mocks/rotator.ts @@ -21,5 +21,14 @@ export const rotatorHandlers: Handler[] = [ connected: true } }) + }, + { + method: 'GET', + url: '/api/v1/rotator/init', + handler: eventHandler(_event => { + return { + connected: true + } + }) } ] diff --git a/tests/rotatorRoutes.spec.ts b/tests/rotatorRoutes.spec.ts index a67e858..f8e05a5 100644 --- a/tests/rotatorRoutes.spec.ts +++ b/tests/rotatorRoutes.spec.ts @@ -21,5 +21,11 @@ suite('@observerly/hyper Fiber API Rotator Client', () => { const { connected } = await client.rotator.isConnected() expect(connected).toBe(true) }) + + it('should be able to determine the connection status of the rotator', async () => { + const client = setupClient(getURL('/api/v1/')) + const { connected } = await client.rotator.initialise() + expect(connected).toBe(true) + }) }) })