diff --git a/src/routes/camera.ts b/src/routes/camera.ts index 4bbafa2..a823bdd 100644 --- a/src/routes/camera.ts +++ b/src/routes/camera.ts @@ -197,7 +197,15 @@ export const camera = (base: URL, init?: RequestInit, headers?: () => Promise() => { const url = new URL('camera/cooler', base) - return dispatchRequest(url, { ...init, method: 'PUT' }, headers) + + const data = JSON.stringify({ on: true }) + + return dispatchRequest( + url, + { ...init, method: 'PUT', body: JSON.stringify({ on: true }) }, + headers, + data + ) } }, { @@ -214,7 +222,15 @@ export const camera = (base: URL, init?: RequestInit, headers?: () => Promise() => { const url = new URL('camera/cooler', base) - return dispatchRequest(url, { ...init, method: 'DELETE' }, headers) + + const data = JSON.stringify({ on: false }) + + return dispatchRequest( + url, + { ...init, method: 'PUT', body: JSON.stringify({ on: false }) }, + headers, + data + ) } }, { diff --git a/tests/mocks/camera.ts b/tests/mocks/camera.ts index f0ae10b..5415bb1 100644 --- a/tests/mocks/camera.ts +++ b/tests/mocks/camera.ts @@ -140,33 +140,30 @@ export const cameraHandlers: Handler[] = [ }) }, { - method: ['PUT', 'DELETE'], + method: ['PUT'], url: '/api/v1/camera/cooler', - handler: eventHandler(event => { + handler: eventHandler(async event => { const method = getMethod(event) - if (!['PUT', 'DELETE'].includes(method)) { + if (!['PUT'].includes(method)) { return new Response('Method Not Allowed', { status: 405, statusText: 'Method Not Allowed' }) } + const body = await readBody<{ on: boolean }>(event) + const status = { connected: true, pulseGuiding: false, - coolerOn: false, + coolerOn: body.on, coolerPower: 0, CCDtemperature: 0, heatSinkTemperature: 0, state: 'idle' } - if (method === 'PUT') { - status.coolerOn = true - return status - } - return status }) },