Skip to content

Commit

Permalink
Merge pull request #103 from infinimesh/dev-mocks-fixes
Browse files Browse the repository at this point in the history
mocks fixes
  • Loading branch information
slntopp authored Mar 22, 2024
2 parents 84a0df7 + e8dff8f commit 6bdcf08
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
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) })
}
})
})

0 comments on commit 6bdcf08

Please sign in to comment.