Skip to content

Commit

Permalink
feat: added client.exposure.isReady() router handler.
Browse files Browse the repository at this point in the history
feat: added client.exposure.isReady() router handler. Includes associated test suite for module export definition and expected output from API route.
  • Loading branch information
michealroberts committed Apr 13, 2024
1 parent 88a836f commit 7afa32d
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/routes/exposure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*****************************************************************************************************************/

// @author Michael Roberts <[email protected]>
// @package @observerly/hyper
// @license Copyright © 2021-2023 observerly

/*****************************************************************************************************************/

import { dispatchRequest } from '../internals/dispatchRequest'

/*****************************************************************************************************************/

export const exposure = (
base: URL,
init?: RequestInit,
headers?: () => Promise<Headers> | Headers
) =>
[
{
name: 'isReady',
action: <
T = {
complete: boolean
progress: number
ready: boolean
}
>() => {
const url = new URL('exposure/ready', base)
return dispatchRequest<T>(url, init, headers)
}
}
] as const

/*****************************************************************************************************************/
2 changes: 2 additions & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { camera } from './camera'
import { conditions } from './conditions'
import { dome } from './dome'
import { exposure } from './exposure'
import { filterwheel } from './filterwheel'
import { focuser } from './focuser'
import { monitor } from './monitor'
Expand All @@ -25,6 +26,7 @@ export const routes = (
camera: camera(base, init, headers),
conditions: conditions(base, init, headers),
dome: dome(base, init, headers),
exposure: exposure(base, init, headers),
filterwheel: filterwheel(base, init, headers),
focuser: focuser(base, init, headers),
monitor: monitor(base, init, headers),
Expand Down
35 changes: 35 additions & 0 deletions tests/exposure.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*****************************************************************************************************************/

// @author Michael Roberts <[email protected]>
// @package @observerly/hyper
// @license Copyright © 2021-2023 observerly

/*****************************************************************************************************************/

import { describe, expect, it, suite } from 'vitest'

import { isDataResult } from '../src'

/*****************************************************************************************************************/

import { getURL, setupClient } from './setup'

/*****************************************************************************************************************/

suite('@observerly/hyper NOX API Observing Exposure Client', () => {
describe('exposureRoutes', () => {
it('should be able to determine if the exposure is ready', async () => {
const client = setupClient(getURL('/api/v1/'))
const isReady = await client.exposure.isReady()
expect(isDataResult(isReady)).toBe(true)
if (!isDataResult(isReady)) return
expect(isReady).toStrictEqual({
complete: true,
progress: 100,
ready: true
})
})
})
})

/*****************************************************************************************************************/
29 changes: 29 additions & 0 deletions tests/mocks/exposure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*****************************************************************************************************************/

// @author Michael Roberts <[email protected]>
// @package @observerly/hyper
// @license Copyright © 2021-2023 observerly

/*****************************************************************************************************************/

import { eventHandler } from 'h3'

import { type Handler } from '../shared/handler'

/*****************************************************************************************************************/

export const exposureHandlers: Handler[] = [
{
method: 'GET',
url: '/api/v1/exposure/ready',
handler: eventHandler(_event => {
return {
complete: true,
progress: 100,
ready: true
}
})
}
]

/*****************************************************************************************************************/
2 changes: 2 additions & 0 deletions tests/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { baseHandlers } from './base'

import { cameraHandlers } from './camera'
import { domeHandlers } from './dome'
import { exposureHandlers } from './exposure'
import { filterwheelHandlers } from './filterwheel'
import { focuserHandlers } from './focuser'
import { monitorHandlers } from './monitor'
Expand All @@ -26,6 +27,7 @@ export const handlers: Handler[] = [
...cameraHandlers,
...conditionsHandlers,
...domeHandlers,
...exposureHandlers,
...filterwheelHandlers,
...focuserHandlers,
...monitorHandlers,
Expand Down

0 comments on commit 7afa32d

Please sign in to comment.