Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mocks fixes #103

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions mocks/es/devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ export const transport = createRouterTransport(({ service }) => {
const devicesByNs = new Map<string, Device[]>()
const nodes = new Map<string, Node[]>()

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
}

Expand Down
15 changes: 8 additions & 7 deletions mocks/es/namespaces.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 }) => {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) })
}
})
})
Loading