48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { mkdtempSync, rmSync } from 'fs'
|
|
import { tmpdir } from 'os'
|
|
import { join } from 'path'
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
import { encodePairingOffer } from './pairing'
|
|
import {
|
|
RuntimeEnvironmentStoreError,
|
|
addEnvironmentFromPairingCode,
|
|
listEnvironments
|
|
} from './runtime-environment-store'
|
|
|
|
function pairingCode(endpoint = 'ws://127.0.0.1:6768'): string {
|
|
return encodePairingOffer({
|
|
v: 2,
|
|
endpoint,
|
|
deviceToken: 'device-token',
|
|
publicKeyB64: Buffer.from(new Uint8Array(32).fill(1)).toString('base64')
|
|
})
|
|
}
|
|
|
|
describe('runtime environment store', () => {
|
|
const tempDirs: string[] = []
|
|
|
|
afterEach(() => {
|
|
for (const dir of tempDirs.splice(0)) {
|
|
rmSync(dir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
|
|
it('rejects duplicate server names instead of silently replacing the saved server', () => {
|
|
const userDataPath = mkdtempSync(join(tmpdir(), 'orca-runtime-env-store-'))
|
|
tempDirs.push(userDataPath)
|
|
|
|
const first = addEnvironmentFromPairingCode(userDataPath, {
|
|
name: 'dev box',
|
|
pairingCode: pairingCode('ws://127.0.0.1:6768')
|
|
})
|
|
|
|
expect(() =>
|
|
addEnvironmentFromPairingCode(userDataPath, {
|
|
name: 'dev box',
|
|
pairingCode: pairingCode('ws://192.0.2.10:6768')
|
|
})
|
|
).toThrow(RuntimeEnvironmentStoreError)
|
|
expect(listEnvironments(userDataPath)).toEqual([first])
|
|
})
|
|
})
|