Skip to content

Commit

Permalink
Test rpc group creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
saul-jb committed Mar 22, 2024
1 parent 0881152 commit ae3cfbd
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions packages/daemon/test/modules/groups.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import fs from 'fs/promises'
import { createNetClient } from '@organicdesign/net-rpc'
import * as cborg from 'cborg'
import all from 'it-all'
import { type CID } from 'multiformats/cid'
import { toString as uint8ArrayToString } from 'uint8arrays'
import { CID } from 'multiformats/cid'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import createGroups from '../../src/modules/groups/index.js'
import createNetwork from '../../src/modules/network/index.js'
import createRpc from '../../src/modules/rpc/index.js'
Expand Down Expand Up @@ -192,4 +193,42 @@ describe('groups', () => {
client.close()
await sigint.interupt()
})

it('rpc - create groups creates a group without other peers', async () => {
const { groups: m, sigint, argv } = await create()
const client = createNetClient(argv.socket)
const name = 'test'

const cid = await client.rpc.request('create-group', { name, peers: [] })
const group = CID.parse(cid)
const database = m.groups.get(group)

assert(database != null)
assert.equal(database.manifest.name, name)
assert.deepEqual(database.manifest.access.config?.write, [m.welo.identity.id])

client.close()
await sigint.interupt()
})

it('rpc - create groups creates a group with other peers', async () => {
const { groups: m, sigint, argv } = await create()
const client = createNetClient(argv.socket)
const name = 'test'
const otherPeer = 'GZsJqUjmbVqZCUMbJoe5ye4xfdKZVPVwBoFFQiyCZYesq6Us5b'

const cid = await client.rpc.request('create-group', { name, peers: [otherPeer] })
const group = CID.parse(cid)
const database = m.groups.get(group)

assert(database != null)
assert.equal(database.manifest.name, name)
assert.deepEqual(database.manifest.access.config?.write, [
m.welo.identity.id,
uint8ArrayFromString(otherPeer, 'base58btc')
])

client.close()
await sigint.interupt()
})
})

0 comments on commit ae3cfbd

Please sign in to comment.