-
Notifications
You must be signed in to change notification settings - Fork 1
/
buddycloud.search.js
90 lines (77 loc) · 2.8 KB
/
buddycloud.search.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
var should = require('should')
, Buddycloud = require('../../index')
, helper = require('../helper')
/* jshint -W030 */
describe('buddycloud', function() {
var buddycloud, socket, xmpp, manager
before(function() {
socket = new helper.SocketEventer()
xmpp = new helper.XmppEventer()
manager = {
socket: socket,
client: xmpp,
trackId: function(id, callback) {
if (typeof id !== 'object')
throw new Error('Stanza protection ID not added')
this.callback = callback
},
makeCallback: function(error, data) {
this.callback(error, data)
},
_getLogger: function() {
return {
log: function() {},
info: function() {},
error: function() {},
warn: function() {}
}
}
}
buddycloud = new Buddycloud()
buddycloud.init(manager)
buddycloud.channelServer = 'chanels.example.com'
})
beforeEach(function() {
socket.removeAllListeners()
xmpp.removeAllListeners()
buddycloud.init(manager)
buddycloud.channelServer = 'channels.example.com'
})
it('Parses entry XML to expected format', function(done) {
var payload = {
form: [
{ var: 'content', value: 'test' }
]
}
xmpp.once('stanza', function() {
manager.makeCallback(helper.getStanza('search-response'))
})
var callback = function(error, data) {
should.not.exist(error)
var fields = data.fields
fields.node.should.eql({
label: 'Node',
type: 'text-single'
})
fields.id.should.eql({
label: 'Item ID',
type: 'text-single'
})
fields.entry.should.eql({
label: 'Item',
type: 'xml'
})
data.results.length.should.equal(2)
var results = data.results
results[0].node.should.equal('/user/romeo@montague.lit/posts')
results[0].id.should.equal('5w382609806986536982502859083409')
results[0].entry.body.should.equal('Hello World')
results[1].node.should.equal('/user/juliet@capulet.lit/posts')
results[1].id.should.equal('fg455g542hg4hhtfgh4554hg5g5g54h4F')
results[1].entry.body.should.equal('Hello Everyone')
done()
}
socket.send('xmpp.buddycloud.search.do', payload, callback)
})
})