From a8d241cd7b1fb60744ce3eaa8870497219ebb30e Mon Sep 17 00:00:00 2001 From: Hayden Young Date: Fri, 8 Sep 2023 00:14:42 +0100 Subject: [PATCH] test: Basic tests for identity configuration. --- .../orbitdb-custom-identity-providers.test.js | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 test/orbitdb-custom-identity-providers.test.js diff --git a/test/orbitdb-custom-identity-providers.test.js b/test/orbitdb-custom-identity-providers.test.js new file mode 100644 index 0000000..9380a25 --- /dev/null +++ b/test/orbitdb-custom-identity-providers.test.js @@ -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') + }) +})