Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/routes/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,29 @@ export const camera = (base: URL, init?: RequestInit, headers?: () => Promise<He
return dispatchRequest<T>(url, { ...init, method: 'PUT' }, headers)
}
},
{
name: 'connect',
action: <
T = {
connected: boolean
}
>() => {
const url = new URL('camera/connect', base)

const data = JSON.stringify({ connect: true })

return dispatchRequest<T>(
url,
{
...init,
method: 'PUT',
body: JSON.stringify({ connect: true })
},
headers,
data
)
}
},
{
name: 'turnCoolerOn',
action: <
Expand Down
8 changes: 8 additions & 0 deletions tests/camera.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ suite('@observerly/hyper Fiber API Observing Camera Client', () => {
expect(isConnected).toStrictEqual({ connected: true })
})

it('should be able to connect the camera', async () => {
const client = setupClient(getURL('/api/v1/'))
const status = await client.camera.connect()
expect(isDataResult(status)).toBe(true)
if (!isDataResult(status)) return
expect(status).toStrictEqual({ connected: true })
})

it('should be able to get the configuration of the camera', async () => {
const client = setupClient(getURL('/api/v1/'))
const configuration = await client.camera.getConfiguration()
Expand Down
27 changes: 27 additions & 0 deletions tests/mocks/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,33 @@ export const cameraHandlers: Handler[] = [
}
})
},
{
method: 'PUT',
url: '/api/v1/camera/connect',
handler: eventHandler(async event => {
const method = getMethod(event)

if (method !== 'PUT') {
return new Response('Method Not Allowed', {
status: 405,
statusText: 'Method Not Allowed'
})
}

const body = await readBody<{ connect: boolean }>(event)

if (!body) {
return new Response('Bad Request', {
status: 400,
statusText: 'Bad Request'
})
}

return {
connected: body.connect
}
})
},
{
method: ['PUT', 'DELETE'],
url: '/api/v1/camera/cooler',
Expand Down