mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-05 13:46:36 +00:00
test: Basic tests for identity configuration.
This commit is contained in:
parent
01f401a71a
commit
a8d241cd7b
60
test/orbitdb-custom-identity-providers.test.js
Normal file
60
test/orbitdb-custom-identity-providers.test.js
Normal file
@ -0,0 +1,60 @@
|
||||
import { deepStrictEqual } from 'assert'
|
||||
import rmrf from 'rimraf'
|
||||
import * as IPFS from 'ipfs-core'
|
||||
import { createOrbitDB, Identities, useIdentityProvider } from '../src/index.js'
|
||||
import config from './config.js'
|
||||
// import pathJoin from '../src/utils/path-join.js'
|
||||
import CustomIdentityProvider from './fixtures/providers/custom.js'
|
||||
|
||||
describe('Add a custom identity provider', function () {
|
||||
this.timeout(5000)
|
||||
|
||||
let ipfs
|
||||
|
||||
before(async () => {
|
||||
ipfs = await IPFS.create({ ...config.daemon1, repo: './ipfs1' })
|
||||
})
|
||||
|
||||
it('creates an identity using an id and default pubkey provider', async () => {
|
||||
useIdentityProvider(CustomIdentityProvider)
|
||||
const identities = await Identities()
|
||||
const identity = await identities.createIdentity({ id: 'abc' })
|
||||
const orbitdb = await createOrbitDB({ ipfs, identities, id: 'abc' })
|
||||
|
||||
deepStrictEqual(orbitdb.identity, identity)
|
||||
|
||||
await orbitdb.stop()
|
||||
})
|
||||
|
||||
it('creates an identity using a custom provider', async () => {
|
||||
useIdentityProvider(CustomIdentityProvider)
|
||||
const identities = await Identities()
|
||||
const identity = { provider: CustomIdentityProvider() }
|
||||
const expectedIdentity = await identities.createIdentity(identity)
|
||||
const orbitdb = await createOrbitDB({ ipfs, identities, identity })
|
||||
|
||||
deepStrictEqual(orbitdb.identity, expectedIdentity)
|
||||
|
||||
await orbitdb.stop()
|
||||
})
|
||||
|
||||
it('uses an existing identity created with a custom provider', async () => {
|
||||
useIdentityProvider(CustomIdentityProvider)
|
||||
const identities = await Identities()
|
||||
const identity = await identities.createIdentity({ provider: CustomIdentityProvider() })
|
||||
const orbitdb = await createOrbitDB({ ipfs, identities, identity })
|
||||
|
||||
deepStrictEqual(orbitdb.identity, identity)
|
||||
|
||||
await orbitdb.stop()
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if (ipfs) {
|
||||
await ipfs.stop()
|
||||
}
|
||||
|
||||
await rmrf('./orbitdb')
|
||||
await rmrf('./ipfs1')
|
||||
})
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user