mirror of https://codeberg.org/pzp/pzp-db.git
tests for identity.find() etc
This commit is contained in:
parent
a442a26c2a
commit
a3fcb641eb
|
@ -51,8 +51,10 @@
|
||||||
"typescript": "^5.1.3"
|
"typescript": "^5.1.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc --build --clean && tsc --build",
|
"clean-check": "tsc --build --clean",
|
||||||
"test": "node --test",
|
"prepublishOnly": "npm run clean-check && tsc --build",
|
||||||
|
"postpublish": "npm run clean-check",
|
||||||
|
"test": "npm run clean-check && node --test",
|
||||||
"format-code": "prettier --write \"(lib|test)/**/*.js\"",
|
"format-code": "prettier --write \"(lib|test)/**/*.js\"",
|
||||||
"format-code-staged": "pretty-quick --staged --pattern \"(lib|test)/**/*.js\"",
|
"format-code-staged": "pretty-quick --staged --pattern \"(lib|test)/**/*.js\"",
|
||||||
"coverage": "c8 --reporter=lcov npm run test"
|
"coverage": "c8 --reporter=lcov npm run test"
|
||||||
|
|
|
@ -36,6 +36,7 @@ test('identity.create() with just "domain"', async (t) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('identity.create() with "keypair" and "domain"', async (t) => {
|
test('identity.create() with "keypair" and "domain"', async (t) => {
|
||||||
|
rimraf.sync(DIR)
|
||||||
const keypair = Keypair.generate('ed25519', 'alice')
|
const keypair = Keypair.generate('ed25519', 'alice')
|
||||||
|
|
||||||
const peer = SecretStack({ appKey: caps.shse })
|
const peer = SecretStack({ appKey: caps.shse })
|
||||||
|
@ -62,3 +63,79 @@ test('identity.create() with "keypair" and "domain"', async (t) => {
|
||||||
|
|
||||||
await p(peer.close)()
|
await p(peer.close)()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('identity.find() can find', async (t) => {
|
||||||
|
rimraf.sync(DIR)
|
||||||
|
const keypair = Keypair.generate('ed25519', 'alice')
|
||||||
|
const domain = 'person'
|
||||||
|
|
||||||
|
const peer = SecretStack({ appKey: caps.shse })
|
||||||
|
.use(require('../lib'))
|
||||||
|
.use(require('ssb-box'))
|
||||||
|
.call(null, { keypair, path: DIR })
|
||||||
|
|
||||||
|
await peer.db.loaded()
|
||||||
|
const identity = await p(peer.db.identity.create)({ keypair, domain })
|
||||||
|
assert.ok(identity, 'identity created')
|
||||||
|
|
||||||
|
const found = await p(peer.db.identity.find)({ keypair, domain })
|
||||||
|
assert.equal(found, identity, 'found')
|
||||||
|
|
||||||
|
await p(peer.close)()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('identity.findOrCreate() can find', async (t) => {
|
||||||
|
rimraf.sync(DIR)
|
||||||
|
const keypair = Keypair.generate('ed25519', 'alice')
|
||||||
|
const domain = 'person'
|
||||||
|
|
||||||
|
const peer = SecretStack({ appKey: caps.shse })
|
||||||
|
.use(require('../lib'))
|
||||||
|
.use(require('ssb-box'))
|
||||||
|
.call(null, { keypair, path: DIR })
|
||||||
|
|
||||||
|
await peer.db.loaded()
|
||||||
|
const identity = await p(peer.db.identity.create)({ keypair, domain })
|
||||||
|
assert.ok(identity, 'identity created')
|
||||||
|
|
||||||
|
const found = await p(peer.db.identity.findOrCreate)({ keypair, domain })
|
||||||
|
assert.equal(found, identity, 'found')
|
||||||
|
|
||||||
|
await p(peer.close)()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('identity.findOrCreate() can create', async (t) => {
|
||||||
|
rimraf.sync(DIR)
|
||||||
|
const keypair = Keypair.generate('ed25519', 'alice')
|
||||||
|
const domain = 'person'
|
||||||
|
|
||||||
|
const peer = SecretStack({ appKey: caps.shse })
|
||||||
|
.use(require('../lib'))
|
||||||
|
.use(require('ssb-box'))
|
||||||
|
.call(null, { keypair, path: DIR })
|
||||||
|
|
||||||
|
await peer.db.loaded()
|
||||||
|
|
||||||
|
let gotError = false
|
||||||
|
await p(peer.db.identity.find)({ keypair, domain }).catch(err => {
|
||||||
|
assert.equal(err.cause, 'ENOENT');
|
||||||
|
gotError = true
|
||||||
|
})
|
||||||
|
assert.ok(gotError, 'identity not found')
|
||||||
|
|
||||||
|
const identity = await p(peer.db.identity.findOrCreate)({ keypair, domain })
|
||||||
|
assert.ok(identity, 'identity created')
|
||||||
|
const msg = peer.db.get(identity)
|
||||||
|
assert.equal(msg.data.add, keypair.public, 'msg.data.add')
|
||||||
|
assert.equal(msg.metadata.identity, 'self', 'msg.metadata.identity')
|
||||||
|
assert.equal(msg.metadata.identityTips, null, 'msg.metadata.identityTips')
|
||||||
|
assert.deepEqual(
|
||||||
|
Object.keys(msg.metadata.tangles),
|
||||||
|
[],
|
||||||
|
'msg.metadata.tangles'
|
||||||
|
)
|
||||||
|
assert.equal(msg.pubkey, keypair.public, 'msg.pubkey')
|
||||||
|
|
||||||
|
await p(peer.close)()
|
||||||
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue