Skip to content

Commit bf50162

Browse files
committed
add decodePrivate test
1 parent 80358ca commit bf50162

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/decodePrivate.test.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import test from "ava"
22
import decodePrivate from './decodePrivate'
33

4+
function unecrypt(data) {
5+
return data.replace(/\*/g, '')
6+
}
7+
48
test.cb('ignore not encrypted msgs', (t) => {
59
const data = {
610
content: {}
@@ -12,4 +16,26 @@ test.cb('ignore not encrypted msgs', (t) => {
1216
}
1317
const sbot = {}
1418
decodePrivate(sbot)(data, done)
19+
})
20+
21+
test.cb('decode encrypted msgs', (t) => {
22+
t.plan(3)
23+
const data = {
24+
content: "e*n*cry**p*t*e*dmsg"
25+
}
26+
const done = (err, d) => {
27+
t.is(err, null)
28+
t.is(
29+
d.content.text,
30+
unecrypt(data.content)
31+
)
32+
t.end()
33+
}
34+
const sbot = {
35+
unbox(cypher, cb) {
36+
t.is(cypher, data.content)
37+
cb(null, unecrypt(cypher))
38+
}
39+
}
40+
decodePrivate(sbot)(data, done)
1541
})

0 commit comments

Comments
 (0)