-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.browser.ts
56 lines (46 loc) · 1.48 KB
/
index.browser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { test } from '@socketsupply/tapzero'
import { Program, Session } from '@oddjs/odd'
import { createUsername } from '@ssc-hermes/profile'
import { example } from '../dist/index.js'
// @ts-ignore
const wn = self.oddjs
let program:Program
test('setup', async t => {
const APP_INFO = { name: 'testing', creator: 'test' }
program = await wn.program({
namespace: APP_INFO,
debug: true
})
t.ok(wn, 'wn should exist')
t.ok(program, 'should create a program')
})
test('example', t => {
const random = example(program.components.crypto)
t.ok(random, 'should return something')
})
let alicesUsername:string
let session:Session|null
test('create a user', async t => {
alicesUsername = await createUsername(program.components.crypto)
await program.auth.register({ username: alicesUsername })
session = await program.auth.session()
const wnfs = session?.fs
if (!wnfs) throw new Error('not wnfs')
if (!(await program.fileSystem.hasPublicExchangeKey(wnfs))) {
await program.fileSystem.addPublicExchangeKey(wnfs)
}
await wnfs.publish()
const published = await once(program, 'fileSystem:publish')
t.ok(published, 'should emit a publish event')
})
function once (bus:Program, eventName:string) {
return new Promise(resolve => {
// @ts-ignore
bus.on(eventName, onEvent)
function onEvent (ev) {
resolve(ev)
// @ts-ignore
bus.off(eventName, onEvent)
}
})
}