38 行
1.1 KiB
TypeScript
38 行
1.1 KiB
TypeScript
|
|
import assert from 'node:assert/strict'
|
||
|
|
import test from 'node:test'
|
||
|
|
|
||
|
|
import { _initializeFromConfigFile, awaitInitialization } from '../src/sdk'
|
||
|
|
|
||
|
|
const CONFIG_VECTOR =
|
||
|
|
'XUQM-CONFIG-V1.AAECAwQFBgcICQoLDA0ODw.EBESExQVFhcYGRob.vhdKh3AhEdeftXCdXp9KusVySkrBNAzmdaA747uf1tVWGFnAsJeCLe2mHKk0dxxez8SRTknIbk1UuRibnXY0Gbot1fmkR-jSN2ssMJO0_zQ8dUu8'
|
||
|
|
|
||
|
|
test('awaitInitialization observes config decryption already in progress', async () => {
|
||
|
|
const originalFetch = globalThis.fetch
|
||
|
|
let requestCount = 0
|
||
|
|
globalThis.fetch = async () => {
|
||
|
|
requestCount += 1
|
||
|
|
return new Response(
|
||
|
|
JSON.stringify({
|
||
|
|
data: {
|
||
|
|
apiUrl: 'https://api.example.test',
|
||
|
|
},
|
||
|
|
}),
|
||
|
|
{
|
||
|
|
headers: { 'content-type': 'application/json' },
|
||
|
|
status: 200,
|
||
|
|
},
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
try {
|
||
|
|
const autoInitialization = _initializeFromConfigFile(CONFIG_VECTOR, {
|
||
|
|
debug: true,
|
||
|
|
})
|
||
|
|
await assert.doesNotReject(() => awaitInitialization())
|
||
|
|
await autoInitialization
|
||
|
|
assert.equal(requestCount, 1)
|
||
|
|
} finally {
|
||
|
|
globalThis.fetch = originalFetch
|
||
|
|
}
|
||
|
|
})
|