From b6476ad0955f76f2d3c6a26f80fd46735e15455d Mon Sep 17 00:00:00 2001 From: addievo Date: Fri, 27 Oct 2023 15:54:34 +1100 Subject: [PATCH] lintfix --- tests/client/handlers/nodes.test.ts | 59 ++++++++++++----------------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/tests/client/handlers/nodes.test.ts b/tests/client/handlers/nodes.test.ts index 71aad65e4e..c5391d65d6 100644 --- a/tests/client/handlers/nodes.test.ts +++ b/tests/client/handlers/nodes.test.ts @@ -1,7 +1,9 @@ import type GestaltGraph from '@/gestalts/GestaltGraph'; -import type { NodeIdEncoded } from '@/ids/types'; -import type { TLSConfig, Host, Port } from '@/network/types'; +import type { NodeIdEncoded, NodeId } from '@/ids/types'; +import type { TLSConfig, Host, Port, Hostname } from '@/network/types'; import type { Notification } from '@/notifications/types'; +import type { NodeAddress } from '@/nodes/types'; +import type { Array } from 'fast-check/lib/types/utils/globals'; import fs from 'fs'; import path from 'path'; import os from 'os'; @@ -38,12 +40,9 @@ import * as keysUtils from '@/keys/utils'; import * as nodesUtils from '@/nodes/utils'; import * as networkUtils from '@/network/utils'; import * as validationErrors from '@/validation/errors'; +import { parseHostOrHostname, parsePort } from '@/network/utils'; +import { parseNodeId } from '@/ids'; import * as testsUtils from '../../utils'; -import { parseHostOrHostname, parsePort } from "@/network/utils"; -import { parseNodeId } from "@/ids"; -import { NodeAddress } from "@/nodes/types"; -import mock = jest.mock; -import { Array } from "fast-check/lib/types/utils/globals"; describe('nodesAdd', () => { const logger = new Logger('nodesAdd test', LogLevel.WARN, [ @@ -715,7 +714,6 @@ describe('nodesGetAll', () => { let webSocketClient: WebSocketClient; let rpcClient: RPCClient<{ nodesGetAll: typeof nodesGetAll; - nodesAdd: typeof nodesAdd; }>; let nodeGraph: NodeGraph; let taskManager: TaskManager; @@ -784,10 +782,6 @@ describe('nodesGetAll', () => { }); await clientService.start({ manifest: { - nodesAdd: new NodesAdd({ - db, - nodeManager, - }), nodesGetAll: new NodesGetAll({ nodeGraph, keyRing, @@ -806,7 +800,6 @@ describe('nodesGetAll', () => { rpcClient = new RPCClient({ manifest: { nodesGetAll, - nodesAdd, }, streamFactory: () => webSocketClient.connection.newStream(), toError: networkUtils.toError, @@ -865,7 +858,6 @@ describe('nodesListConnections', () => { let webSocketClient: WebSocketClient; let rpcClient: RPCClient<{ nodesListConnections: typeof nodesListConnections; - nodesAdd: typeof nodesAdd; }>; let nodeGraph: NodeGraph; let taskManager: TaskManager; @@ -874,7 +866,10 @@ describe('nodesListConnections', () => { let sigchain: Sigchain; let mockedConnection: jest.SpyInstance; beforeEach(async () => { - mockedConnection = jest.spyOn(NodeConnectionManager.prototype, 'listConnections'); + mockedConnection = jest.spyOn( + NodeConnectionManager.prototype, + 'listConnections', + ); dataDir = await fs.promises.mkdtemp( path.join(os.tmpdir(), 'polykey-test-'), ); @@ -936,7 +931,6 @@ describe('nodesListConnections', () => { }); await clientService.start({ manifest: { - nodesAdd: new NodesAdd({ db, nodeManager }), nodesListConnections: new NodesListConnections({ nodeConnectionManager, }), @@ -954,7 +948,6 @@ describe('nodesListConnections', () => { rpcClient = new RPCClient({ manifest: { nodesListConnections, - nodesAdd, }, streamFactory: () => webSocketClient.connection.newStream(), toError: networkUtils.toError, @@ -979,27 +972,23 @@ describe('nodesListConnections', () => { }); }); test('lists all connections', async () => { - await rpcClient.methods.nodesAdd({ - nodeIdEncoded: - 'vrsc24a1er424epq77dtoveo93meij0pc8ig4uvs9jbeld78n9nl0' as NodeIdEncoded, - host: '127.0.0.1', - port: 11111, - ping: false, - force: false, - }); - mockedConnection.mockResolvedValue( + mockedConnection.mockReturnValue([ { - nodeId: 'vrsc24a1er424epq77dtoveo93meij0pc8ig4uvs9jbeld78n9nl0' as NodeIdEncoded, - address: {host: '127.0.0.1' as Host, port: 11111 as Port } as NodeAddress, + nodeId: testsUtils.generateRandomNodeId(), + address: { + host: '127.0.0.1', + port: 11111, + hostname: undefined, + }, usageCount: 1, - timeout: 99999, - }); + timeout: undefined, + }, + ]); const values: Array = []; - const response = await rpcClient.methods.nodesListConnections({}); - for await (const respons of response) { - console.log(respons); - values.push(respons); + const responses = await rpcClient.methods.nodesListConnections({}); + for await (const response of responses) { + values.push(response); } - expect(response).toBeTruthy(); + expect(values[0].port).toEqual(11111); }); });