Skip to content

Commit

Permalink
Merge pull request #98 from observerly/feature/client/camera/stopExpo…
Browse files Browse the repository at this point in the history
…sure

feat: Added client.camera.stopExposure() route handler.
  • Loading branch information
michealroberts authored Sep 14, 2023
2 parents 6cb2e58 + 763a42a commit af8569c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
8 changes: 8 additions & 0 deletions src/routes/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,13 @@ export const camera = (base: URL, init?: RequestInit, headers?: () => Promise<He
data
)
}
},
{
name: 'stopExposure',
action: <T = {}>() => {
const url = new URL('camera/exposure', base)

return dispatchRequest<T>(url, { ...init, method: 'DELETE' }, headers)
}
}
] as const
8 changes: 8 additions & 0 deletions tests/camera.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,13 @@ suite('@observerly/hyper Fiber API Observing Camera Client', () => {
light: true
})
})

it('should be able to stop an exposure on the camera', async () => {
const client = setupClient(getURL('/api/v1/'))
const status = await client.camera.stopExposure()
expect(isDataResult(status)).toBe(true)
if (!isDataResult(status)) return
expect(status).toStrictEqual({})
})
})
})
18 changes: 10 additions & 8 deletions tests/mocks/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ export const cameraHandlers: Handler[] = [
})
},
{
method: ['PUT'],
method: ['PUT', 'DELETE'],
url: '/api/v1/camera/exposure',
handler: eventHandler(async event => {
const method = getMethod(event)

if (method !== 'PUT') {
if (method !== 'PUT' && method !== 'DELETE') {
return new Response('Method Not Allowed', {
status: 405,
statusText: 'Method Not Allowed'
Expand All @@ -201,12 +201,14 @@ export const cameraHandlers: Handler[] = [
})
}

return {
duration: 300,
flat: false,
dark: false,
light: true
}
return method === 'PUT'
? {
duration: 300,
flat: false,
dark: false,
light: true
}
: {}
})
}
]

0 comments on commit af8569c

Please sign in to comment.