mirror of https://codeberg.org/pzp/pzp-invite.git
70 lines
1.7 KiB
JavaScript
70 lines
1.7 KiB
JavaScript
const test = require('node:test')
|
|
const assert = require('node:assert')
|
|
const plugin = require('../lib/index')
|
|
|
|
test('parse() error cases', (t) => {
|
|
assert.throws(() => {
|
|
plugin.parse('ssb://invite/join/ip4/127.0.0.1/tcp/HUB_PUBKEY/HUB_TOKEN')
|
|
})
|
|
assert.throws(() => {
|
|
plugin.parse('pzp:invite')
|
|
})
|
|
assert.throws(() => {
|
|
plugin.parse('pzp:invite/join/ip4/127.0.0.1')
|
|
})
|
|
})
|
|
|
|
test('parse() good friend invite', (t) => {
|
|
const commands = plugin.parse(
|
|
'pzp://invite/join/dns/example.com/tcp/8080/shse/PUBKEY.TOKEN/follow/ALICE/promise.follow/pubkey.ALICE/ALICE_TOKEN'
|
|
)
|
|
assert.deepEqual(commands, [
|
|
{
|
|
type: 'join',
|
|
multiaddr: '/dns/example.com/tcp/8080/shse/PUBKEY.TOKEN',
|
|
},
|
|
{
|
|
type: 'follow',
|
|
id: 'ALICE',
|
|
},
|
|
{
|
|
type: 'promise.follow',
|
|
issuer: ['pubkey', 'ALICE'],
|
|
token: 'ALICE_TOKEN',
|
|
},
|
|
])
|
|
})
|
|
|
|
test('parse() good myself invite', (t) => {
|
|
const commands = plugin.parse(
|
|
'pzp://invite/join/dns/example.com/tcp/8080/shse/PUBKEY.TOKEN/tunnel-connect/HUB_PUBKEY/OLD_PUBKEY/promise.account-add/pubkey.PUBKEY/OLD_TOKEN'
|
|
)
|
|
assert.deepEqual(commands, [
|
|
{
|
|
type: 'join',
|
|
multiaddr: '/dns/example.com/tcp/8080/shse/PUBKEY.TOKEN',
|
|
},
|
|
{
|
|
type: 'tunnel-connect',
|
|
multiaddr: '/tunnel/HUB_PUBKEY.OLD_PUBKEY/shse/OLD_PUBKEY',
|
|
},
|
|
{
|
|
type: 'promise.account-add',
|
|
issuer: ['pubkey', 'PUBKEY'],
|
|
token: 'OLD_TOKEN',
|
|
},
|
|
])
|
|
})
|
|
|
|
test('parse() good tokenless join invite', (t) => {
|
|
const commands = plugin.parse(
|
|
'pzp://invite/join/dns/example.com/tcp/8080/shse/PUBKEY'
|
|
)
|
|
assert.deepEqual(commands, [
|
|
{
|
|
type: 'join',
|
|
multiaddr: '/dns/example.com/tcp/8080/shse/PUBKEY',
|
|
},
|
|
])
|
|
})
|