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
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

/*****************************************************************************************************************/

export { routes } from './routes'

export { createHyperClient } from './client'

/*****************************************************************************************************************/
21 changes: 21 additions & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*****************************************************************************************************************/

// @author Michael Roberts <michael@observerly.com>
// @package @observerly/hyper
// @license Copyright © 2021-2023 observerly

/*****************************************************************************************************************/

import { telescope } from './telescope'

/*****************************************************************************************************************/

export const routes = (
base: URL = new URL('http://localhost:3000/api/v1'),
init?: RequestInit,
headers?: () => Headers | Promise<Headers>
) => ({
telescope: telescope(base, init, headers)
})

/*****************************************************************************************************************/
32 changes: 32 additions & 0 deletions src/routes/telescope.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*****************************************************************************************************************/

// @author Michael Roberts <michael@observerly.com>
// @package @observerly/hyper
// @license Copyright © 2021-2023 observerly

/*****************************************************************************************************************/

import { dispatchRequest } from '../internals/dispatchRequest'

/*****************************************************************************************************************/

export const telescope = (
base: URL,
init?: RequestInit,
headers?: () => Promise<Headers> | Headers
) =>
[
{
name: 'isConnected',
action: <
T = {
connected: boolean
}
>() => {
const url = new URL('telescope/connected', base)
return dispatchRequest<T>(url, init, headers)
}
}
] as const

/*****************************************************************************************************************/
4 changes: 3 additions & 1 deletion tests/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

import { baseHandlers } from './base'

import { telescopeHandlers } from './telescope'

import { type Handler } from '../shared/handler'

/*****************************************************************************************************************/

export const handlers: Handler[] = [...baseHandlers]
export const handlers: Handler[] = [...baseHandlers, ...telescopeHandlers]

/*****************************************************************************************************************/
27 changes: 27 additions & 0 deletions tests/mocks/telescope.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*****************************************************************************************************************/

// @author Michael Roberts <michael@observerly.com>
// @package @observerly/hyper
// @license Copyright © 2021-2023 observerly

/*****************************************************************************************************************/

import { eventHandler } from 'h3'

import { type Handler } from '../shared/handler'

/*****************************************************************************************************************/

export const telescopeHandlers: Handler[] = [
{
method: 'GET',
url: '/api/v1/telescope/connected',
handler: eventHandler(_event => {
return {
connected: true
}
})
}
]

/*****************************************************************************************************************/
4 changes: 3 additions & 1 deletion tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export const setupClient = (url: string) => {

// Establish API mocking before all tests.
beforeAll(async () => {
listener = await listen(toNodeListener(server))
listener = await listen(toNodeListener(server), {
port: 3033
})
})

/*****************************************************************************************************************/
Expand Down
25 changes: 25 additions & 0 deletions tests/telescopeRoutes.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*****************************************************************************************************************/

// @author Michael Roberts <michael@observerly.com>
// @package @observerly/hyper
// @license Copyright © 2021-2023 observerly

/*****************************************************************************************************************/

import { describe, expect, it, suite } from 'vitest'

/*****************************************************************************************************************/

import { getURL, setupClient } from './setup'

/*****************************************************************************************************************/

suite('@observerly/hyper Fiber API Telescope Client', () => {
describe('telescopeRoutes', () => {
it('should be able to determine the connection status of the telescope', async () => {
const client = setupClient(getURL('/api/v1/'))
const { connected } = await client.telescope.isConnected()
expect(connected).toBe(true)
})
})
})