| … | … | @@ -0,0 +1,48 @@ |
| 1 | // identity-lookup-member.test.js — identity.lookupMember passes the MEMBER id |
| 2 | // (hyper-games #89 defect 8: "passes roomId where keet-core expects the member id"). |
| 3 | // |
| 4 | // keet-core's lookupUserByMemberId takes ONE argument — the member key — and |
| 5 | // decodes it for the username registry (keet-core 4.22.28 lib/api/v1/index.js |
| 6 | // _lookupUserByMemberId(e): hypercoreIdEncoding.decode(e) -> userRegistry.lookupByKey). |
| 7 | // The router called it as (roomId, memberId), so keet-core looked up the ROOM key. |
| 8 | // |
| 9 | // No keet-core needed: the backend is a stub that records what it was called with. |
| 10 | // |
| 11 | // Run: cd hyper-fleeky/packages/keet-daemon && bare test/identity-lookup-member.test.js |
| 12 | |
| 13 | import fs from 'bare-fs' |
| 14 | import path from 'bare-path' |
| 15 | import os from 'bare-os' |
| 16 | import { Router } from '../lib/router.js' |
| 17 | |
| 18 | let exitCode = 0 |
| 19 | function ok (cond, msg) { |
| 20 | if (cond) console.log(' ok ' + msg) |
| 21 | else { console.log(' FAIL ' + msg); exitCode = 1 } |
| 22 | } |
| 23 | |
| 24 | const storage = path.join(os.tmpdir(), 'keet-daemon-test-lookup-' + Date.now()) |
| 25 | fs.mkdirSync(storage, { recursive: true }) |
| 26 | |
| 27 | const calls = [] |
| 28 | const backend = { |
| 29 | api: { |
| 30 | core: { |
| 31 | lookupUserByMemberId: async (...args) => { calls.push(args); return { username: 'alice0' } } |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | const router = new Router(backend, null, { storage }) |
| 36 | |
| 37 | const res = await router._identityLookupMember({ roomId: 'ROOMKEY', memberId: 'MEMBERKEY' }) |
| 38 | ok(calls.length === 1, 'keet-core lookupUserByMemberId called once') |
| 39 | ok(calls[0] && calls[0].length === 1 && calls[0][0] === 'MEMBERKEY', |
| 40 | 'with the MEMBER id as its only argument (got ' + JSON.stringify(calls[0]) + ')') |
| 41 | ok(res && res.username === 'alice0', 'and its result is returned') |
| 42 | |
| 43 | let threw = false |
| 44 | try { await router._identityLookupMember({ roomId: 'ROOMKEY' }) } catch { threw = true } |
| 45 | ok(threw, 'a missing memberId is refused') |
| 46 | |
| 47 | console.log(exitCode === 0 ? '\nPASS' : '\nFAIL') |
| 48 | Bare.exit(exitCode) |