-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from observerly/feature/client/exposure/isReady
feat: added client.exposure.isReady() router handler.
- Loading branch information
Showing
5 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/*****************************************************************************************************************/ | ||
|
||
// @author Michael Roberts <[email protected]> | ||
// @package @observerly/hyper | ||
// @license Copyright © 2021-2023 observerly | ||
|
||
/*****************************************************************************************************************/ | ||
|
||
import { dispatchRequest } from '../internals/dispatchRequest' | ||
|
||
/*****************************************************************************************************************/ | ||
|
||
export const exposure = ( | ||
base: URL, | ||
init?: RequestInit, | ||
headers?: () => Promise<Headers> | Headers | ||
) => | ||
[ | ||
{ | ||
name: 'isReady', | ||
action: < | ||
T = { | ||
complete: boolean | ||
progress: number | ||
ready: boolean | ||
} | ||
>() => { | ||
const url = new URL('exposure/ready', base) | ||
return dispatchRequest<T>(url, init, headers) | ||
} | ||
} | ||
] as const | ||
|
||
/*****************************************************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*****************************************************************************************************************/ | ||
|
||
// @author Michael Roberts <[email protected]> | ||
// @package @observerly/hyper | ||
// @license Copyright © 2021-2023 observerly | ||
|
||
/*****************************************************************************************************************/ | ||
|
||
import { describe, expect, it, suite } from 'vitest' | ||
|
||
import { isDataResult } from '../src' | ||
|
||
/*****************************************************************************************************************/ | ||
|
||
import { getURL, setupClient } from './setup' | ||
|
||
/*****************************************************************************************************************/ | ||
|
||
suite('@observerly/hyper NOX API Observing Exposure Client', () => { | ||
describe('exposureRoutes', () => { | ||
it('should be able to determine if the exposure is ready', async () => { | ||
const client = setupClient(getURL('/api/v1/')) | ||
const isReady = await client.exposure.isReady() | ||
expect(isDataResult(isReady)).toBe(true) | ||
if (!isDataResult(isReady)) return | ||
expect(isReady).toStrictEqual({ | ||
complete: true, | ||
progress: 100, | ||
ready: true | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
/*****************************************************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/*****************************************************************************************************************/ | ||
|
||
// @author Michael Roberts <[email protected]> | ||
// @package @observerly/hyper | ||
// @license Copyright © 2021-2023 observerly | ||
|
||
/*****************************************************************************************************************/ | ||
|
||
import { eventHandler } from 'h3' | ||
|
||
import { type Handler } from '../shared/handler' | ||
|
||
/*****************************************************************************************************************/ | ||
|
||
export const exposureHandlers: Handler[] = [ | ||
{ | ||
method: 'GET', | ||
url: '/api/v1/exposure/ready', | ||
handler: eventHandler(_event => { | ||
return { | ||
complete: true, | ||
progress: 100, | ||
ready: true | ||
} | ||
}) | ||
} | ||
] | ||
|
||
/*****************************************************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters