Skip to content

Commit

Permalink
lintfix
Browse files Browse the repository at this point in the history
  • Loading branch information
addievo committed Oct 27, 2023
1 parent 805f179 commit b6476ad
Showing 1 changed file with 24 additions and 35 deletions.
59 changes: 24 additions & 35 deletions tests/client/handlers/nodes.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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, [
Expand Down Expand Up @@ -715,7 +714,6 @@ describe('nodesGetAll', () => {
let webSocketClient: WebSocketClient;
let rpcClient: RPCClient<{
nodesGetAll: typeof nodesGetAll;
nodesAdd: typeof nodesAdd;
}>;
let nodeGraph: NodeGraph;
let taskManager: TaskManager;
Expand Down Expand Up @@ -784,10 +782,6 @@ describe('nodesGetAll', () => {
});
await clientService.start({
manifest: {
nodesAdd: new NodesAdd({
db,
nodeManager,
}),
nodesGetAll: new NodesGetAll({
nodeGraph,
keyRing,
Expand All @@ -806,7 +800,6 @@ describe('nodesGetAll', () => {
rpcClient = new RPCClient({
manifest: {
nodesGetAll,
nodesAdd,
},
streamFactory: () => webSocketClient.connection.newStream(),
toError: networkUtils.toError,
Expand Down Expand Up @@ -865,7 +858,6 @@ describe('nodesListConnections', () => {
let webSocketClient: WebSocketClient;
let rpcClient: RPCClient<{
nodesListConnections: typeof nodesListConnections;
nodesAdd: typeof nodesAdd;
}>;
let nodeGraph: NodeGraph;
let taskManager: TaskManager;
Expand All @@ -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-'),
);
Expand Down Expand Up @@ -936,7 +931,6 @@ describe('nodesListConnections', () => {
});
await clientService.start({
manifest: {
nodesAdd: new NodesAdd({ db, nodeManager }),
nodesListConnections: new NodesListConnections({
nodeConnectionManager,
}),
Expand All @@ -954,7 +948,6 @@ describe('nodesListConnections', () => {
rpcClient = new RPCClient({
manifest: {
nodesListConnections,
nodesAdd,
},
streamFactory: () => webSocketClient.connection.newStream(),
toError: networkUtils.toError,
Expand All @@ -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<any> = [];
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);
});
});

0 comments on commit b6476ad

Please sign in to comment.