From 226d1dc26d2b31306d29b9b7d13c95459859241d Mon Sep 17 00:00:00 2001 From: Martin Varmuza Date: Thu, 23 May 2024 11:46:58 +0200 Subject: [PATCH] test(transport-bridge): add more unit tests --- packages/transport-bridge/tests/http.test.ts | 69 ++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/packages/transport-bridge/tests/http.test.ts b/packages/transport-bridge/tests/http.test.ts index d53f91a3808..5156666e5d9 100644 --- a/packages/transport-bridge/tests/http.test.ts +++ b/packages/transport-bridge/tests/http.test.ts @@ -1,5 +1,6 @@ import { getFreePort } from '@trezor/node-utils'; import { AbstractApi } from '@trezor/transport/src/api/abstract'; +import { bridgeApiCall } from '@trezor/transport/src/utils/bridgeApiCall'; import { TrezordNode } from '../src/http'; @@ -67,4 +68,72 @@ describe('http', () => { logger: muteLogger, }); }); + + it('stop should make previously used port available again', async () => { + const trezordNode = new TrezordNode({ + port, + api: createTransportApi(), + // @ts-expect-error + logger: muteLogger, + }); + await trezordNode.start(); + await trezordNode.stop(); + const anotherInstance = new TrezordNode({ + port, + api: createTransportApi(), + // @ts-expect-error + logger: muteLogger, + }); + await anotherInstance.start(); + await anotherInstance.stop(); + }); + + describe('endpoints', () => { + let trezordNode: TrezordNode; + + beforeAll(async () => { + trezordNode = new TrezordNode({ + port, + api: createTransportApi(), + // @ts-expect-error + logger: muteLogger, + }); + await trezordNode.start(); + await new Promise(resolve => setTimeout(resolve, 1000)); + }); + + afterAll(async () => { + await trezordNode.stop(); + }); + + describe('GET', () => { + ['/', '/status'].forEach(endpoint => { + it(endpoint, async () => { + const url = trezordNode.server!.getRouteAddress('/')!; + const response = await bridgeApiCall({ + url, + method: 'GET', + }); + if (!response.success) { + throw new Error(response.error); + } + expect(response.payload).toContain(' { + it('/', async () => { + const url = trezordNode.server!.getRouteAddress('/')!; + const response = await bridgeApiCall({ + url, + method: 'POST', + }); + if (!response.success) { + throw new Error(response.error); + } + expect(response.payload).toEqual({ version: trezordNode.version }); + }); + }); + }); });