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

chore: condense setup code in MemberAPI tests #267

Merged
merged 1 commit into from
Sep 18, 2023
Merged
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
42 changes: 24 additions & 18 deletions tests/member-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import { replicate } from './helpers/rpc.js'
test('invite() sends expected project-related details', async (t) => {
t.plan(4)

const projectKey = KeyManager.generateProjectKeypair().publicKey
const encryptionKeys = { auth: randomBytes(32) }
const projectInfo = { name: 'mapeo' }
const { projectKey, encryptionKeys, rpc: r1 } = setup()

const r1 = new MapeoRPC()
const projectInfo = { name: 'mapeo' }
const r2 = new MapeoRPC()

const memberApi = new MemberApi({
Expand Down Expand Up @@ -54,7 +52,8 @@ test('invite() sends expected project-related details', async (t) => {
test('invite() assigns role to invited device after invite accepted', async (t) => {
t.plan(4)

const r1 = new MapeoRPC()
const { projectKey, encryptionKeys, rpc: r1 } = setup()

const r2 = new MapeoRPC()

const expectedRoleId = randomBytes(8).toString('hex')
Expand All @@ -71,8 +70,8 @@ test('invite() assigns role to invited device after invite accepted', async (t)

const memberApi = new MemberApi({
capabilities,
encryptionKeys: { auth: randomBytes(32) },
projectKey: KeyManager.generateProjectKeypair().publicKey,
encryptionKeys,
projectKey,
rpc: r1,
dataTypes: {
project: {
Expand Down Expand Up @@ -112,7 +111,8 @@ test('invite() does not assign role to invited device if invite is not accepted'
t.test(decision, (t) => {
t.plan(1)

const r1 = new MapeoRPC()
const { projectKey, encryptionKeys, rpc: r1 } = setup()

const r2 = new MapeoRPC()

const capabilities = {
Expand All @@ -126,8 +126,8 @@ test('invite() does not assign role to invited device if invite is not accepted'

const memberApi = new MemberApi({
capabilities,
encryptionKeys: { auth: randomBytes(32) },
projectKey: KeyManager.generateProjectKeypair().publicKey,
encryptionKeys,
projectKey,
rpc: r1,
dataTypes: {
project: {
Expand Down Expand Up @@ -159,10 +159,7 @@ test('invite() does not assign role to invited device if invite is not accepted'
})

test('getById() works', async (t) => {
const projectKey = KeyManager.generateProjectKeypair().publicKey
const encryptionKeys = { auth: randomBytes(32) }

const rpc = new MapeoRPC()
const { projectKey, encryptionKeys, rpc } = setup()

const deviceId = randomBytes(32).toString('hex')

Expand Down Expand Up @@ -204,10 +201,7 @@ test('getById() works', async (t) => {
})

test('getMany() works', async (t) => {
const projectKey = KeyManager.generateProjectKeypair().publicKey
const encryptionKeys = { auth: randomBytes(32) }

const rpc = new MapeoRPC()
const { projectKey, encryptionKeys, rpc } = setup()

const deviceInfoRecords = []

Expand Down Expand Up @@ -250,6 +244,18 @@ test('getMany() works', async (t) => {
}
})

function setup() {
const projectKey = KeyManager.generateProjectKeypair().publicKey
const encryptionKeys = { auth: randomBytes(32) }
const rpc = new MapeoRPC()

return {
projectKey,
encryptionKeys,
rpc,
}
}

/**
* @param {Object} opts
* @param {string} [opts.deviceId]
Expand Down