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
14 changes: 14 additions & 0 deletions src/routes/telescope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ export const telescope = (
return dispatchRequest<T>(url, init, headers)
}
},
{
name: 'getCoordinates',
action: <
T = {
ra: number
dec: number
az: number
alt: number
}
>() => {
const url = new URL('telescope/coordinates', base)
return dispatchRequest<T>(url, init, headers)
}
},
{
name: 'initialise',
action: <
Expand Down
12 changes: 12 additions & 0 deletions tests/mocks/telescope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ export const telescopeHandlers: Handler[] = [
}
})
},
{
method: 'GET',
url: '/api/v1/telescope/coordinates',
handler: eventHandler(_event => {
return {
ra: 34.5619912,
dec: 56.1234567,
alt: 34.5619912,
az: 56.1234567
}
})
},
{
method: 'PUT',
url: '/api/v1/telescope/init',
Expand Down
1 change: 1 addition & 0 deletions tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const setupClient = (url: string) => {
base: new URL(url),
headers: async () => {
return new Headers({
Accept: 'application/json',
'X-API-Key': `Key <<API_KEY>>`
})
}
Expand Down
21 changes: 21 additions & 0 deletions tests/telescopeRoutes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ suite('@observerly/hyper Fiber API Telescope Client', () => {
expect(connected).toBe(false)
})

it('should be able to get the equatorial and horizontal coordinates of the telescope', async () => {
const client = setupClient(getURL('/api/v1/'))
const { ra, dec, az, alt } = await client.telescope.getCoordinates()

// Right Ascension should be between 0 and 360
expect(ra).toBeGreaterThanOrEqual(0)
expect(ra).toBeLessThan(360)

// Declination should be between -90 and 90
expect(dec).toBeGreaterThan(-90)
expect(dec).toBeLessThan(90)

// Azimuth should be between 0 and 360
expect(az).toBeGreaterThanOrEqual(0)
expect(az).toBeLessThan(360)

// Altitude should be between -90 and 90
expect(alt).toBeGreaterThan(-90)
expect(alt).toBeLessThan(90)
})

it('should be able to set the equatorial coordinates of the telescope', async () => {
const client = setupClient(getURL('/api/v1/'))
const { slewing } = await client.telescope.slewToEquatorialCoordinate({
Expand Down