mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 05:21:15 +00:00
fix(native): new lint warnings and the MapLibre protocol type after the dev merge
Awaits that sat in loops in the native-auth tests run together, the hand-off hook marks its navigations as ignored, the native tests drop their non-null assertions, and the offline protocol answers with the data type MapLibre 6.15 expects.
This commit is contained in:
@@ -43,11 +43,11 @@ describe('signInThroughBrowser', () => {
|
||||
|
||||
await signInThroughBrowser('oidc')
|
||||
|
||||
const opened = new URL(vi.mocked(TrekShell.authenticate).mock.calls[0]![0].url)
|
||||
const opened = new URL(vi.mocked(TrekShell.authenticate).mock.calls[0][0].url)
|
||||
expect(opened.pathname).toBe('/native-handoff')
|
||||
expect(opened.searchParams.get('start')).toBe('oidc')
|
||||
expect(vi.mocked(TrekShell.authenticate).mock.calls[0]![0].callbackScheme).toBe('com.liketrek.trek')
|
||||
const { code, verifier } = vi.mocked(nativeAuthApi.exchange).mock.calls[0]![0]
|
||||
expect(vi.mocked(TrekShell.authenticate).mock.calls[0][0].callbackScheme).toBe('com.liketrek.trek')
|
||||
const { code, verifier } = vi.mocked(nativeAuthApi.exchange).mock.calls[0][0]
|
||||
expect(code).toBe('abc')
|
||||
expect(bytesToHex(sha256(new TextEncoder().encode(verifier)))).toBe(opened.searchParams.get('challenge'))
|
||||
})
|
||||
|
||||
@@ -18,7 +18,8 @@ vi.mock('../sync/networkMode', () => ({ isEffectivelyOffline: vi.fn() }))
|
||||
|
||||
function backButtonHandler(): (event: { canGoBack: boolean }) => void {
|
||||
const call = vi.mocked(App.addListener).mock.calls.find(([name]) => name === 'backButton')
|
||||
return call![1] as unknown as (event: { canGoBack: boolean }) => void
|
||||
if (!call) throw new Error('no backButton listener')
|
||||
return call[1] as unknown as (event: { canGoBack: boolean }) => void
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -37,6 +37,8 @@ export function offlineStyle<T>(style: T): T {
|
||||
}
|
||||
|
||||
type Doc = Record<string, unknown>
|
||||
/** What a protocol handler may hand MapLibre back. */
|
||||
type ProtocolData = Awaited<ReturnType<AddProtocolAction>>['data']
|
||||
|
||||
const isDoc = (value: unknown): value is Doc => typeof value === 'object' && value !== null && !Array.isArray(value)
|
||||
const rewriteList = (value: unknown): unknown => (Array.isArray(value) ? value.map((v) => (typeof v === 'string' ? toOfflineUrl(v) : v)) : value)
|
||||
@@ -90,11 +92,11 @@ async function load(url: string, networkFirst: boolean, signal: AbortSignal): Pr
|
||||
throw new Error(`Not available offline: ${url}`)
|
||||
}
|
||||
|
||||
export const offlineProtocol: AddProtocolAction = async (params: RequestParameters, abortController: AbortController): Promise<GetResourceResponse<unknown>> => {
|
||||
export const offlineProtocol: AddProtocolAction = async (params: RequestParameters, abortController: AbortController): Promise<GetResourceResponse<ProtocolData>> => {
|
||||
const url = fromOfflineUrl(params.url)
|
||||
const response = await load(url, params.type === 'json', abortController.signal)
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status} for ${url}`)
|
||||
if (params.type === 'json') return { data: rewriteDocument(await response.json()) }
|
||||
if (params.type === 'json') return { data: rewriteDocument(await response.json()) as ProtocolData }
|
||||
if (params.type === 'string') return { data: await response.text() }
|
||||
return { data: await response.arrayBuffer() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user