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
17 changes: 17 additions & 0 deletions src/routes/telescope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,23 @@ export const telescope = (
return dispatchRequest<T>(url, { ...init, method: 'PUT' }, headers)
}
},
{
name: 'shutdown',
action: <
T = {
connected: boolean
slewing: boolean
tracking: boolean
parked: boolean
home: boolean
utc: string
}
>() => {
const url = new URL('telescope/shutdown', base)

return dispatchRequest<T>(url, { ...init, method: 'PUT' }, headers)
}
},
{
name: 'connect',
action: <
Expand Down
25 changes: 25 additions & 0 deletions tests/mocks/telescope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,31 @@ export const telescopeHandlers: Handler[] = [
}
})
},
{
method: 'PUT',
url: '/api/v1/telescope/shutdown',
handler: eventHandler(event => {
const method = getMethod(event)

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

const utc = new Date('2021-05-14T00:00:00.000+00:00').toISOString()

return {
connected: false,
slewing: false,
tracking: false,
parked: true,
home: false,
utc
}
})
},
{
method: 'PUT',
url: '/api/v1/telescope/connect',
Expand Down
17 changes: 17 additions & 0 deletions tests/telescopeRoutes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ suite('@observerly/hyper Fiber API Telescope Client', () => {
expect(init).toStrictEqual({ connected: true })
})

it('should be able to shutdown the telescope', async () => {
const client = setupClient(getURL('/api/v1/'))
const shutdown = await client.telescope.shutdown()
expect(isDataResult(shutdown)).toBe(true)
if (!isDataResult(shutdown)) return
// Create a UTC now string:
const utc = new Date('2021-05-14T00:00:00.000+00:00').toISOString()
expect(shutdown).toStrictEqual({
connected: false,
slewing: false,
tracking: false,
parked: true,
home: false,
utc
})
})

it('should be able to connect to the telescope', async () => {
const client = setupClient(getURL('/api/v1/'))
const connect = await client.telescope.connect()
Expand Down