-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
58 lines (52 loc) · 1.43 KB
/
test.js
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
57
58
'use strict'
const test = require('ava')
const setupVcard = require('.')
const {mockClient} = require('@xmpp/test')
const _middleware = require('@xmpp/middleware')
const _iqCaller = require('@xmpp/iq/caller')
const xml = require('@xmpp/xml')
test.beforeEach(t => {
t.context = mockClient()
t.context.middleware = _middleware(t.context)
t.context.iqCaller = _iqCaller(t.context)
t.context.plugin = setupVcard(t.context)
})
test('set', t => {
t.context.scheduleIncomingResult()
return Promise.all([
t.context
.catchOutgoingSet()
.then(child =>
t.deepEqual(
child,
xml('vCard', {xmlns: 'vcard-temp'}, [
xml('FN', {}, 'Foo Bar'),
xml('N', {}, [xml('FAMILY', {}, 'Bar'), xml('GIVEN', {}, 'Foo')]),
])
)
),
t.context.plugin
.set({FN: 'Foo Bar', N: {FAMILY: 'Bar', GIVEN: 'Foo'}})
.then(value => t.deepEqual(value, undefined)),
])
})
test('get', t => {
t.context.scheduleIncomingResult(
xml(
'vCard',
{xmlns: 'vcard-temp'},
xml('FN', {}, 'Foo Bar'),
xml('N', {}, xml('FAMILY', {}, 'Bar'), xml('GIVEN', {}, 'Foo'))
)
)
return Promise.all([
t.context
.catchOutgoingGet()
.then(child => t.deepEqual(child, xml('vCard', {xmlns: 'vcard-temp'}))),
t.context.plugin
.get()
.then(vcard =>
t.deepEqual(vcard, {FN: 'Foo Bar', N: {FAMILY: 'Bar', GIVEN: 'Foo'}})
),
])
})