Skip to content

Commit

Permalink
chore: condense setup code in MemberAPI tests (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
achou11 authored Sep 18, 2023
1 parent 479f96f commit 09d6ad0
Showing 1 changed file with 24 additions and 18 deletions.
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

0 comments on commit 09d6ad0

Please sign in to comment.