From 89fcd61b45f736644587941de2a1824d2e06106c Mon Sep 17 00:00:00 2001 From: 639852 Date: Wed, 20 Mar 2024 23:54:04 +0400 Subject: [PATCH 1/2] fix: fixed nodes in namespaces mocks --- mocks/es/namespaces.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mocks/es/namespaces.ts b/mocks/es/namespaces.ts index c6d468a..1f816df 100644 --- a/mocks/es/namespaces.ts +++ b/mocks/es/namespaces.ts @@ -1,3 +1,4 @@ +import { Struct } from '@bufbuild/protobuf' import { createPromiseClient, createRouterTransport } from '@connectrpc/connect' import { AccountsService, NamespacesService } from '../../build/es/node/node_connect' import { DeleteResponse, EmptyMessage } from '../../build/es/node/node_pb' @@ -19,14 +20,14 @@ export const transport = createRouterTransport(({ service }) => { const level = Math.floor(Math.random() * 4 + 1) for (const key of namespaces.keys()) { - nodes[key] = [0, 1].map((i) => + nodes.set(key, [0, 1].map((i) => new Node({ access: new Access({ namespace: key, level, role }), edge: `Namespases2Accounts/${key}-${i}`, parent: `Namespaces/${key}`, node: '' }) - ) + )) } accountsApi.list(new EmptyMessage()).then(({ accounts }) => { @@ -63,7 +64,7 @@ export const transport = createRouterTransport(({ service }) => { title: `Namespace ${i + 1}`, plugin: new Plugin({ uuid, vars: {} }), access: new Access({ namespace, level, role }), - config: {} + config: new Struct({}) }) namespaces.set(namespace, namespaceItem) @@ -99,16 +100,16 @@ export const transport = createRouterTransport(({ service }) => { accountsByNs.get(request.namespace)?.push(account) } - return new Accounts({ accounts: accountsByNs[request.namespace] }) + return new Accounts({ accounts: accountsByNs.get(request.namespace) }) }, joins(request) { - return new Accounts({ accounts: accountsByNs[request.uuid] }) + return new Accounts({ accounts: accountsByNs.get(request.uuid) }) }, accessibles(request) { - return new Nodes({ nodes: nodes[request.uuid] }) + return new Nodes({ nodes: nodes.get(request.uuid) }) }, deletables(request) { - return new Nodes({ nodes: nodes[request.uuid] }) + return new Nodes({ nodes: nodes.get(request.uuid) }) } }) }) From e8dff8fc92aebd5d9919d4093bbb86fefd2cfe83 Mon Sep 17 00:00:00 2001 From: 639852 Date: Wed, 20 Mar 2024 23:55:04 +0400 Subject: [PATCH 2/2] fix: fixed changeDevice function in devices mocks --- mocks/es/devices.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mocks/es/devices.ts b/mocks/es/devices.ts index 5dda873..53c8309 100644 --- a/mocks/es/devices.ts +++ b/mocks/es/devices.ts @@ -13,20 +13,23 @@ export const transport = createRouterTransport(({ service }) => { const devicesByNs = new Map() const nodes = new Map() - function changeDevice(key: string, uuid: string, value?: JsonValue) { + function changeDevice(key: keyof Device, uuid: string, value?: JsonValue) { const device = devices.get(uuid) ?? new Device({ uuid }) - if (value ?? true) value = !device[key] + if (typeof value !== 'boolean' && (value ?? true)) { + value = !device[key] + } + for (const devices of devicesByNs.values()) { const device = devices.find(({ uuid: id }) => id === uuid) if (device) { - device[key] = value + (device[key] as JsonValue | undefined) = value break } } - device[key] = value + (device[key] as JsonValue | undefined) = value return device }