Files
simplexmq/xftp-web/test/browser.test.ts
Evgeny @ SimpleX Chat 41d474f0d4 persistent client sessions
2026-02-04 16:05:17 +00:00

20 lines
714 B
TypeScript

import {test, expect} from 'vitest'
import {encryptFileForUpload, uploadFile, downloadFile, newXFTPAgent, closeXFTPAgent} from '../src/agent.js'
import {parseXFTPServer} from '../src/protocol/address.js'
const server = parseXFTPServer(import.meta.env.XFTP_SERVER)
test('browser upload + download round-trip', async () => {
const agent = newXFTPAgent()
try {
const data = new Uint8Array(50000)
crypto.getRandomValues(data)
const encrypted = encryptFileForUpload(data, 'test.bin')
const {rcvDescription} = await uploadFile(agent, server, encrypted)
const {content} = await downloadFile(agent, rcvDescription)
expect(content).toEqual(data)
} finally {
closeXFTPAgent(agent)
}
})