Skip to content

Commit

Permalink
test(transport-bridge): add more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz22 committed May 23, 2024
1 parent b652893 commit 226d1dc
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions packages/transport-bridge/tests/http.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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('<html');
});
});
});

describe('POST', () => {
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 });
});
});
});
});

0 comments on commit 226d1dc

Please sign in to comment.