xmppify 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/app/assets/javascripts/xmpp/index.js +0 -0
  8. data/app/assets/javascripts/xmpp/scripts/checkplayer.js +12 -0
  9. data/app/assets/javascripts/xmpp/scripts/crossdomain.xml +7 -0
  10. data/app/assets/javascripts/xmpp/scripts/flXHR.js +2 -0
  11. data/app/assets/javascripts/xmpp/scripts/flXHR.swf +0 -0
  12. data/app/assets/javascripts/xmpp/scripts/flXHR.vbs +44 -0
  13. data/app/assets/javascripts/xmpp/scripts/flensed.js +12 -0
  14. data/app/assets/javascripts/xmpp/scripts/strophe.flxhr.js +31 -0
  15. data/app/assets/javascripts/xmpp/scripts/strophe.js +3538 -0
  16. data/app/assets/javascripts/xmpp/scripts/swfobject.js +5 -0
  17. data/app/assets/javascripts/xmpp/scripts/updateplayer.swf +0 -0
  18. data/app/assets/javascripts/xmpp/scripts/xmpp.js.coffee +386 -0
  19. data/app/assets/javascripts/xmpp/strophejs-plugins/LICENSE.txt +19 -0
  20. data/app/assets/javascripts/xmpp/strophejs-plugins/README.markdown +95 -0
  21. data/app/assets/javascripts/xmpp/strophejs-plugins/archive/README.markdown +14 -0
  22. data/app/assets/javascripts/xmpp/strophejs-plugins/archive/iso8601_support.js +32 -0
  23. data/app/assets/javascripts/xmpp/strophejs-plugins/archive/strophe.archive.js +88 -0
  24. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/README.markdown +53 -0
  25. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/sha1.js +202 -0
  26. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.coffee +153 -0
  27. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.js +88 -0
  28. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.caps.jsonly.js +240 -0
  29. data/app/assets/javascripts/xmpp/strophejs-plugins/chatstates/strophe.chatstates.js +80 -0
  30. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/README.markdown +47 -0
  31. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/GetUrlComamndSpec.js +66 -0
  32. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/strophe.cmds.spec.coffee +145 -0
  33. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/support/jasmine.json +16 -0
  34. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.coffee +265 -0
  35. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.js +403 -0
  36. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/README.markdown +82 -0
  37. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/spec/strophe.x.coffee +715 -0
  38. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.coffee +443 -0
  39. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.js +854 -0
  40. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/.gitignore +1 -0
  41. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/README.markdown +0 -0
  42. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/convert.js +13 -0
  43. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/jasmine.json +11 -0
  44. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/lib/strophe.disco.js +137 -0
  45. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/public/javascript/strophe.disco.js +137 -0
  46. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/01_querying_information.xml +6 -0
  47. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/02_result_set_for_information_request.xml +22 -0
  48. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/03_target_entity_does_not_exist.xml +10 -0
  49. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/04_service_unavailable.xml +11 -0
  50. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/09_querying_specific_jid_and_node_combination.xml +7 -0
  51. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/10_jid_and_node_result.xml +12 -0
  52. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/11_requesting_all_items.xml +6 -0
  53. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/12_result_set_for_all_items.xml +23 -0
  54. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/13_empty_result_set.xml +7 -0
  55. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/17_service_returns_nodes.xml +16 -0
  56. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/18_requesting_further_nodes.xml +7 -0
  57. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/24_jid_and_node_error.xml +11 -0
  58. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/DiscoNodeSpec.js +50 -0
  59. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/SpecHelper.js +51 -0
  60. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/Stanzas.js +0 -0
  61. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.helper.js +54 -0
  62. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.js +0 -0
  63. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/support/jasmine.json +13 -0
  64. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/strophe.disco.js +232 -0
  65. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/public/javascript/jquery.epic.js +61 -0
  66. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/SpecHelper.js +9 -0
  67. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/jquery.epic.js +39 -0
  68. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/support/jasmine.json +22 -0
  69. data/app/assets/javascripts/xmpp/strophejs-plugins/iexdomain/iexdomain.js +36 -0
  70. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/README.markdown +117 -0
  71. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/buster.js +23 -0
  72. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.coffee +64 -0
  73. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.js +92 -0
  74. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/browserSetup.coffee +1 -0
  75. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/jid.spec.coffee +96 -0
  76. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/strophe.joap.spec.coffee +461 -0
  77. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.coffee +304 -0
  78. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.js +522 -0
  79. data/app/assets/javascripts/xmpp/strophejs-plugins/mam/LICENSE.txt +19 -0
  80. data/app/assets/javascripts/xmpp/strophejs-plugins/mam/README.markdown +52 -0
  81. data/app/assets/javascripts/xmpp/strophejs-plugins/mam/strophe.mam.js +62 -0
  82. data/app/assets/javascripts/xmpp/strophejs-plugins/muc/LICENSE.txt +20 -0
  83. data/app/assets/javascripts/xmpp/strophejs-plugins/muc/strophe.muc.js +1003 -0
  84. data/app/assets/javascripts/xmpp/strophejs-plugins/ping/README.markdown +28 -0
  85. data/app/assets/javascripts/xmpp/strophejs-plugins/ping/strophe.ping.js +68 -0
  86. data/app/assets/javascripts/xmpp/strophejs-plugins/private/README.markdown +16 -0
  87. data/app/assets/javascripts/xmpp/strophejs-plugins/private/strophe.private.js +192 -0
  88. data/app/assets/javascripts/xmpp/strophejs-plugins/pubsub/strophe.pubsub.js +555 -0
  89. data/app/assets/javascripts/xmpp/strophejs-plugins/receipts/strophe.receipts.js +155 -0
  90. data/app/assets/javascripts/xmpp/strophejs-plugins/register/README.markdown +44 -0
  91. data/app/assets/javascripts/xmpp/strophejs-plugins/register/strophe.register.js +431 -0
  92. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/public/javascript/strophe.roster.js +40 -0
  93. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/strophe.roster.spec.js +65 -0
  94. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/support/jasmine.json +15 -0
  95. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/strophe.roster.js +438 -0
  96. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/.gitignore +6 -0
  97. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/README.md +113 -0
  98. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/buster.js +11 -0
  99. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/lib/strophe.js +4198 -0
  100. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.helper.js +38 -0
  101. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.js +262 -0
  102. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/strophe.rpc.js +464 -0
  103. data/app/assets/javascripts/xmpp/strophejs-plugins/rsm/strophe.rsm.js +52 -0
  104. data/app/assets/javascripts/xmpp/strophejs-plugins/serverdate/strophe.serverdate.js +58 -0
  105. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/index.html +17 -0
  106. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/strophevcard.js +0 -0
  107. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.coffee +44 -0
  108. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.js +66 -0
  109. data/app/assets/stylesheets/xmpp/index.css +0 -0
  110. data/app/controllers/omniauth_callbacks_controller.rb +15 -0
  111. data/app/controllers/ruby_bosh.rb +221 -0
  112. data/app/models/identity.rb +3 -0
  113. data/app/models/user.rb +40 -0
  114. data/bin/rails +8 -0
  115. data/db/migrate/20140329065635_create_users.rb +10 -0
  116. data/db/migrate/20140329070238_create_identities.rb +11 -0
  117. data/lib/xmppify/version.rb +3 -0
  118. data/lib/xmppify.rb +6 -0
  119. data/xmppify.gemspec +23 -0
  120. metadata +197 -0
@@ -0,0 +1 @@
1
+ (-> buster.spec.expose())()
@@ -0,0 +1,96 @@
1
+ buster.spec.expose()
2
+
3
+ if require?
4
+ JID = require('./../lib/xmpp').JID
5
+ else if window?
6
+ JID = window.JID
7
+
8
+ describe 'JID', ->
9
+
10
+ describe 'parsing', ->
11
+
12
+ it 'should parse a "domain" JID', ->
13
+ j = new JID 'd'
14
+ assert.equals j.user, null
15
+ assert.equals j.domain, 'd'
16
+ assert.equals j.resource, null
17
+
18
+ it 'should parse a "user@domain" JID', ->
19
+ j = new JID('u@d')
20
+ assert.equals(j.user, 'u')
21
+ assert.equals(j.domain, 'd')
22
+ assert.equals(j.resource, null)
23
+
24
+ it 'should parse a "domain/resource" JID', ->
25
+ j = new JID('d/r')
26
+ assert.equals(j.user, null)
27
+ assert.equals(j.domain, 'd')
28
+ assert.equals(j.resource, 'r')
29
+
30
+ it 'should parse a "user@domain/resource" JID', ->
31
+ j = new JID 'u@d/r'
32
+ assert.equals(j.user, 'u')
33
+ assert.equals(j.domain, 'd')
34
+ assert.equals(j.resource, 'r')
35
+
36
+ it 'should parse an internationalized domain name as unicode', ->
37
+ j = new JID('öko.de')
38
+ assert.equals(j.domain, 'öko.de')
39
+
40
+ it 'should parse an internationalized domain name as ascii/punycode', ->
41
+ j = new JID 'xn--ko-eka.de'
42
+ assert.equals j.domain, 'öko.de'
43
+
44
+ it 'should parse a JID with punycode', ->
45
+ j = new JID('Сергей@xn--lsa92diaqnge.xn--p1ai')
46
+ assert.equals j.user, 'сергей'
47
+ assert.equals j.domain, 'приме́р.рф'
48
+
49
+ describe 'serialization', ->
50
+ it 'should serialize a "domain" JID', ->
51
+ j = new JID(null, 'd')
52
+ assert.equals(j.toString(), 'd')
53
+
54
+ it 'should serialize a "user@domain" JID', ->
55
+ j = new JID('u', 'd')
56
+ assert.equals(j.toString(), 'u@d')
57
+
58
+ it 'should serialize a "domain/resource" JID', ->
59
+ j = new JID(null, 'd', 'r')
60
+ assert.equals(j.toString(), 'd/r')
61
+
62
+ it 'should serialize a "user@domain/resource" JID', ->
63
+ j = new JID('u', 'd', 'r')
64
+ assert.equals(j.toString(), 'u@d/r')
65
+
66
+ describe 'equality', ->
67
+
68
+ it 'should parsed JIDs should be equal', ->
69
+ j1 = new JID('foo@bar/baz')
70
+ j2 = new JID('foo@bar/baz')
71
+ assert.equals(j1.equals(j2), true)
72
+
73
+ it 'should parsed JIDs should be not equal', ->
74
+ j1 = new JID('foo@bar/baz')
75
+ j2 = new JID('quux@bar/baz')
76
+ assert.equals(j1.equals(j2), false)
77
+
78
+ it 'should should ignore case in user', ->
79
+ j1 = new JID('foo@bar/baz')
80
+ j2 = new JID('FOO@bar/baz')
81
+ assert.equals(j1.equals(j2), true)
82
+
83
+ it 'should should ignore case in domain', ->
84
+ j1 = new JID('foo@bar/baz')
85
+ j2 = new JID('foo@BAR/baz')
86
+ assert.equals(j1.equals(j2), true)
87
+
88
+ it 'should should not ignore case in resource', ->
89
+ j1 = new JID('foo@bar/baz')
90
+ j2 = new JID('foo@bar/Baz')
91
+ assert.equals(j1.equals(j2), false)
92
+
93
+ it 'should should ignore international caseness', ->
94
+ j1 = new JID('föö@bär/baß')
95
+ j2 = new JID('fÖö@BÄR/baß')
96
+ assert.equals(j1.equals(j2), true)
@@ -0,0 +1,461 @@
1
+ mockConnection = ->
2
+ c = new Strophe.Connection()
3
+ c.authenticated = true
4
+ c.jid = 'n@d/r2'
5
+ c._processRequest = ->
6
+ c._changeConnectStatus Strophe.Status.CONNECTED
7
+ c
8
+
9
+ str = (builder) ->
10
+ if builder.tree
11
+ return Strophe.serialize(builder.tree())
12
+ Strophe.serialize(builder)
13
+
14
+ spyon = (obj, method, cb) ->
15
+ sinon.stub obj, method, (res) ->
16
+ cb.call @, ($ str res)
17
+
18
+ receive = (c,req) ->
19
+ c._dataRecv(createRequest(req))
20
+ expect(c.send).toHaveBeenCalled()
21
+
22
+ createRequest = (iq) ->
23
+ iq = iq.tree() if typeof iq.tree is "function"
24
+ req = new Strophe.Request(iq, ->)
25
+ req.getResponse = ->
26
+ env = new Strophe.Builder('env', {type: 'mock'}).tree()
27
+ env.appendChild(iq)
28
+ env
29
+ req
30
+
31
+ describe "strophe.joap plugin", ->
32
+
33
+ before ->
34
+ @c = mockConnection()
35
+ @successHandler = sinon.spy()
36
+ @errorHandler = sinon.spy()
37
+
38
+ it "provides connection.joap", ->
39
+ (expect window.Strophe).toBeDefined()
40
+ (expect typeof @c.joap).toEqual "object"
41
+
42
+ it "has a method for creating a new connection to an object server", ->
43
+ server = new @c.joap.JOAPServer "service.example.com"
44
+ (expect server).toBeDefined()
45
+
46
+ describe "object server", ->
47
+
48
+ server = null
49
+
50
+ before ->
51
+ server = new @c.joap.JOAPServer "service.example.com"
52
+
53
+ it "can create an instance", (done) ->
54
+
55
+ spyon @c, "send", (iq) ->
56
+ (expect iq.attr "to").toEqual "user@service.example.com"
57
+ (expect iq.attr "type").toEqual "set"
58
+
59
+ child = $ iq.children()[0]
60
+
61
+ (expect child.attr "xmlns").toEqual "jabber:iq:joap"
62
+ (expect child[0].tagName).toEqual "ADD"
63
+ (expect child.children().length).toEqual 2
64
+
65
+ foo = $ child.children()[0]
66
+ pass = $ child.children()[1]
67
+
68
+ (expect foo[0].tagName).toEqual "ATTRIBUTE"
69
+ (expect pass[0].tagName).toEqual "ATTRIBUTE"
70
+ (expect foo.children().length).toEqual 2
71
+ (expect foo.children()[0].tagName).toEqual "NAME"
72
+ (expect foo.children()[1].tagName).toEqual "VALUE"
73
+ (expect ($ "string", foo).text()).toEqual "foo"
74
+ (expect pass.children().length).toEqual 2
75
+ (expect child.children().length).toEqual 2
76
+ (expect ($ "i4", pass).text()).toEqual "2"
77
+ done()
78
+
79
+ server.add "user", {name: "foo", pass: 2}, (iq, err, address) ->
80
+
81
+ it "can parse an error message", (done) ->
82
+ spyon @c, "send", (req) =>
83
+ res = $iq({type:'error', id: req.attr 'id'})
84
+ .c("add").c("error", code:403).t("My error message")
85
+ @c._dataRecv createRequest(res)
86
+ server.add "User", {name: "foo", pass: 2}, (iq, err, instanceId) ->
87
+ (expect err.message).toEqual "My error message"
88
+ (expect err.code).toEqual 403
89
+ done()
90
+
91
+ it "can parse an 'service-unavailable' error", (done) ->
92
+ spyon @c, "send", (req) =>
93
+ res = $iq({type:'error', id: req.attr 'id'})
94
+ .c("add").c("error", code:503)
95
+ @c._dataRecv createRequest(res)
96
+ server.add "User", {name: "foo", pass: 2}, (iq, err, instanceId) ->
97
+ (expect err.code).toEqual 503
98
+ (expect err.message).toEqual "JOAP server is unavailable"
99
+ done()
100
+
101
+ it "can parse the new instance id", (done) ->
102
+ spyon @c, "send", (req) =>
103
+ res = $iq({type:'result', id: req.attr 'id'})
104
+ .c("add").c("newAddress").t("user@example.org/markus")
105
+ @c._dataRecv createRequest(res)
106
+ server.add "User", {name: "foo", pass: 2}, (iq, err, instanceId) ->
107
+ (expect instanceId).toEqual "user@example.org/markus"
108
+ done()
109
+
110
+ it "can add a new instance addressed by a full JID", (done) ->
111
+ spyon @c, "send", (req) =>
112
+ res = $iq({type:'result', id: req.attr 'id'})
113
+ .c("add").c("newAddress").t("user@service.example.org/markus")
114
+ @c._dataRecv createRequest(res)
115
+ @c.joap.add "user@service.example.org", {name: "foo", pass: 2}, (iq, err, instanceId) ->
116
+ (expect instanceId).toEqual "user@service.example.org/markus"
117
+ done()
118
+
119
+ it "can edit an instance", (done) ->
120
+ spyon @c, "send", (iq) =>
121
+ (expect iq.attr "to").toEqual "user@service.example.com/myId"
122
+ (expect iq.attr "type").toEqual "set"
123
+ (expect ($ "edit",iq).attr "xmlns").toEqual "jabber:iq:joap"
124
+ ($ "attribute",iq).each ->
125
+ (expect ($ @).children().length).toEqual 2
126
+
127
+ res = $iq({type:'result', id: iq.attr 'id'}).c("edit")
128
+ @c._dataRecv createRequest(res)
129
+
130
+ server.edit "User", "myId",{ name:"x", age: 33 },(iq, err) ->
131
+ (expect typeof iq).toEqual "object"
132
+ (expect err).toBeFalsy()
133
+ done()
134
+
135
+ it "can edit an instance addressed by a full JID", (done) ->
136
+ spyon @c, "send", (iq) =>
137
+ (expect iq.attr "to").toEqual "user@service.example.com/myId"
138
+ res = $iq({type:'result', id: iq.attr 'id'}).c("edit")
139
+ @c._dataRecv createRequest(res)
140
+
141
+ @c.joap.edit "user@service.example.com/myId",{ name:"y", age: 66 },(iq, err) ->
142
+ (expect typeof iq).toEqual "object"
143
+ (expect err).toBeFalsy()
144
+ done()
145
+
146
+ it "can read an instance", (done) ->
147
+ spyon @c, "sendIQ", (iq) ->
148
+ (expect iq.attr "to").toEqual "user@service.example.com/myId"
149
+ (expect iq.attr "type").toEqual "get"
150
+ (expect ($ "read",iq).attr "xmlns").toEqual "jabber:iq:joap"
151
+ done()
152
+ server.read "User", "myId", (iq, err, obj) ->
153
+
154
+ it "can read from a full JID", (done) ->
155
+ spyon @c, "sendIQ", (iq) ->
156
+ (expect iq.attr "to").toEqual "user@service.example.com/myId"
157
+ done()
158
+ @c.joap.read "user@service.example.com/myId", (iq, err, obj) ->
159
+
160
+ it "can parse the read attributes", (done) ->
161
+ spyon @c, "send", (req) =>
162
+ res = $iq({type:'result', id: req.attr 'id'})
163
+ .c("read")
164
+ .c("attribute")
165
+ .c("name").t("prop").up()
166
+ .c("value").c("int").t('5').up().up()
167
+ .c("attribute")
168
+ .c("name").t("obj").up()
169
+ .c("value").c("struct")
170
+ .c("member")
171
+ .c("name").t("foo").up()
172
+ .c("value").c("string").t("bar").up().up().up().up().up()
173
+ .c("attribute")
174
+ .c("name").t("arr").up()
175
+ .c("value")
176
+ .c("array")
177
+ .c("data")
178
+ .c("value").c("boolean").t('1').up().up()
179
+ .c("value").c("double").t("-0.5")
180
+
181
+ @c._dataRecv createRequest(res)
182
+
183
+ server.read "User", "id",(iq, err, obj) ->
184
+ (expect obj.prop).toEqual 5
185
+ (expect obj.obj.foo).toEqual "bar"
186
+ (expect obj.arr).toEqual [ true, -0.5 ]
187
+ done()
188
+
189
+ it "can delete an instance", (done) ->
190
+ spyon @c, "send", (iq) =>
191
+ (expect iq.attr "to").toEqual "user@service.example.com/myId"
192
+ (expect iq.attr "type").toEqual "set"
193
+ (expect ($ "delete",iq).attr "xmlns").toEqual "jabber:iq:joap"
194
+ res = $iq({type:'result', id: iq.attr 'id'}).c("delete")
195
+ @c._dataRecv createRequest(res)
196
+
197
+ server.delete "User", "myId", (iq, err) ->
198
+ (expect typeof iq).toEqual "object"
199
+ (expect err).toBeFalsy()
200
+ done()
201
+
202
+ it "can delete an instance addressed by a full JID", (done) ->
203
+ spyon @c, "send", (iq) =>
204
+ (expect iq.attr "to").toEqual "user@service.example.com/myId"
205
+ res = $iq({type:'result', id: iq.attr 'id'}).c("delete")
206
+ @c._dataRecv createRequest(res)
207
+
208
+ @c.joap.delete "user@service.example.com/myId", (iq, err) ->
209
+ (expect typeof iq).toEqual "object"
210
+ (expect err).toBeFalsy()
211
+ done()
212
+
213
+ it "can search instances", (done) ->
214
+ spyon @c, "send", (iq) =>
215
+ (expect iq.attr "to").toEqual "user@service.example.com"
216
+ (expect iq.attr "type").toEqual "get"
217
+ (expect ($ "search",iq).attr "xmlns").toEqual "jabber:iq:joap"
218
+ res = $iq({type:'result', id: iq.attr 'id'}).c("search")
219
+ .c("item").t("Class@service.example.com/id0").up()
220
+ .c("item").t("Class@service.example.com/id2").up()
221
+ @c._dataRecv createRequest(res)
222
+
223
+ server.search "User", (iq, err, result) ->
224
+ (expect typeof iq).toEqual "object"
225
+ (expect result[0]).toEqual "class@service.example.com/id0"
226
+ (expect result[1]).toEqual "class@service.example.com/id2"
227
+ done()
228
+
229
+ it "can search instances addressed by a full JID", (done) ->
230
+ spyon @c, "send", (iq) =>
231
+ (expect iq.attr "to").toEqual "user@service.example.com"
232
+ res = $iq({type:'result', id: iq.attr 'id'}).c("search")
233
+ .c("item").t("Class@service.example.com/id0").up()
234
+ @c._dataRecv createRequest(res)
235
+
236
+ @c.joap.search "user@service.example.com", (iq, err, result) ->
237
+ (expect typeof iq).toEqual "object"
238
+ (expect result[0]).toEqual "class@service.example.com/id0"
239
+ done()
240
+
241
+ it "can send a describe request to a class", (done) ->
242
+ spyon @c, "send", (iq) =>
243
+ (expect iq.attr "to").toEqual "class@service.example.com"
244
+ (expect iq.attr "type").toEqual "get"
245
+ (expect ($ "describe", iq).attr "xmlns").toEqual "jabber:iq:joap"
246
+ res = $iq({type:'result', id: iq.attr 'id'}).c("describe")
247
+ .c("desc", "xml:lang":"en-US").t("Class description").up()
248
+ .c("attributeDescription", { writeable:false, required:true })
249
+ .c("name").t("myAttribute").up()
250
+ .c("type").t("int").up()
251
+ .c("desc", "xml:lang":"en-US").t("Foo").up()
252
+ .c("desc", "xml:lang":"de-DE").t("Alles mögliche").up().up()
253
+ .c("methodDescription", { allocation:"class"})
254
+ .c("name").t("methodname").up()
255
+ .c("returnType").t("boolean").up()
256
+ .c("desc", "xml:lang":"en-US").t("myAttribute").up().up()
257
+ .c("superclass").t("SuperClass@service.example.com").up()
258
+ .c("timestamp").t("2003-01-07T20:08:13Z").up()
259
+ @c._dataRecv createRequest(res)
260
+
261
+ server.describe "Class", (iq, err, result) ->
262
+ (expect typeof iq).toEqual "object"
263
+ (expect typeof result).toEqual "object"
264
+ (expect result.desc["en-US"]).toEqual "Class description"
265
+ (expect result.attributes.myAttribute.type).toEqual "int"
266
+ (expect result.attributes.myAttribute.desc["en-US"]).toEqual "Foo"
267
+ (expect result.superclass).toEqual "superclass@service.example.com"
268
+ done()
269
+
270
+ it "can send a describe request to the server", (done) ->
271
+ spyon @c, "send", (iq) =>
272
+ (expect iq.attr "to").toEqual "service.example.com"
273
+ done()
274
+ server.describe (iq, err, result) ->
275
+
276
+ it "can send a describe request to the server", (done) ->
277
+ spyon @c, "send", (iq) =>
278
+ (expect iq.attr "to").toEqual "service.example.com"
279
+ res = $iq({type:'result', id: iq.attr 'id'}).c("describe")
280
+ .c("desc", "xml:lang":"en-US").t("Server description").up()
281
+ @c._dataRecv createRequest(res)
282
+ @c.joap.describe "service.example.com" ,(iq, err, result) ->
283
+ done()
284
+
285
+ it "can send a describe requests to an instance", (done) ->
286
+ spyon @c, "send", (iq) =>
287
+ (expect iq.attr "to").toEqual "class@service.example.com/id"
288
+ res = $iq({type:'result', id: iq.attr 'id'}).c("describe")
289
+ .c("desc", "xml:lang":"en-US").t("Instance description").up()
290
+ @c._dataRecv createRequest(res)
291
+ server.describe "Class", "id", (iq, err, result) ->
292
+ done()
293
+
294
+ describe "joap object", ->
295
+
296
+ id = "class@service.example.com/id"
297
+
298
+ beforeEach ->
299
+ @obj = new @c.joap.JOAPObject id
300
+
301
+ it "can be created", ->
302
+
303
+ joapObj = new @c.joap.JOAPObject id
304
+ (expect joapObj.jid.toString()).toEqual id
305
+ (expect typeof joapObj.read).toEqual "function"
306
+ (expect typeof joapObj.edit).toEqual "function"
307
+ (expect typeof joapObj.describe).toEqual "function"
308
+
309
+ it "can read the remote state", (done) ->
310
+
311
+ spyon @c, "send", (req) =>
312
+ res = $iq({type:'result', id: req.attr 'id'})
313
+ .c("read")
314
+ .c("attribute")
315
+ .c("name").t("prop").up()
316
+ .c("value").c("int").t('5').up().up()
317
+
318
+ @c._dataRecv createRequest(res)
319
+
320
+ @obj.read (iq, err, obj) ->
321
+ (expect obj.prop).toEqual 5
322
+ done()
323
+
324
+ it "can edit a property", (done) ->
325
+ spyon @c, "send", (iq) =>
326
+ (expect ($ "edit",iq).attr "xmlns").toEqual "jabber:iq:joap"
327
+ (expect ($ "value",iq).text()).toEqual '33'
328
+
329
+ res = $iq({type:'result', id: iq.attr 'id'}).c("edit")
330
+ @c._dataRecv createRequest(res)
331
+
332
+ @obj.edit { age: 33 },(iq, err) ->
333
+ (expect typeof iq).toEqual "object"
334
+ (expect err).toBeFalsy()
335
+ done()
336
+
337
+ it "provied the describe method", (done) ->
338
+ spyon @c, "send", (iq) =>
339
+ (expect iq.attr "to").toEqual "class@service.example.com/id"
340
+ res = $iq({type:'result', id: iq.attr 'id'}).c("describe")
341
+ .c("desc", "xml:lang":"en-US").t("Instance description").up()
342
+ @c._dataRecv createRequest(res)
343
+ @obj.describe (iq, err, result) -> done()
344
+
345
+ describe "joap class", ->
346
+
347
+ clz = null
348
+
349
+ beforeEach ->
350
+ clz = new @c.joap.JOAPClass "class@service.example.com"
351
+
352
+ it "can be created", ->
353
+
354
+ (expect clz.jid.toString()).toEqual "class@service.example.com"
355
+ (expect typeof clz.read).toEqual "function"
356
+ (expect typeof clz.edit).toEqual "function"
357
+ (expect typeof clz.delete).toEqual "function"
358
+ (expect typeof clz.add).toEqual "function"
359
+ (expect typeof clz.search).toEqual "function"
360
+ (expect typeof clz.searchAndRead).toEqual "function"
361
+
362
+ it "can read an instance", (done) ->
363
+ spyon @c, "send", (req) =>
364
+ res = $iq({type:'result', id: req.attr 'id'})
365
+ .c("read")
366
+ .c("attribute")
367
+ .c("name").t("prop").up()
368
+ .c("value").c("int").t('3').up().up()
369
+
370
+ @c._dataRecv createRequest(res)
371
+
372
+ clz.read "123", (iq, err, obj) ->
373
+ (expect obj.prop).toEqual 3
374
+ done()
375
+
376
+ it "can search instances", (done) ->
377
+ spyon @c, "send", (iq) =>
378
+ res = $iq({type:'result', id: iq.attr 'id'}).c("search")
379
+ .c("item").t("class@service.example.com/id0").up()
380
+ .c("item").t("Class@service.example.com/id2").up()
381
+
382
+ @c._dataRecv createRequest(res)
383
+
384
+ clz.search (iq, err, ids) ->
385
+ (expect ids).toEqual [
386
+ "class@service.example.com/id0"
387
+ "class@service.example.com/id2" ]
388
+ done()
389
+
390
+ it "can search and read instances", (done) ->
391
+ x = 0
392
+ spyon @c, "send", (iq) =>
393
+ switch ($ iq).children()[0].tagName.toLowerCase()
394
+ when "search"
395
+ res = $iq({type:'result', id: iq.attr 'id'}).c("search")
396
+ .c("item").t("class@service.example.com/id0").up()
397
+ .c("item").t("class@service.example.com/id2").up()
398
+ @c._dataRecv createRequest(res)
399
+
400
+ when "read"
401
+ x++
402
+ res = $iq({type:'result', id: iq.attr 'id'})
403
+ .c("read")
404
+ .c("attribute")
405
+ .c("name").t("prop").up()
406
+ .c("value").c("int").t(x.toString()).up().up()
407
+ @c._dataRecv createRequest(res)
408
+
409
+ clz.searchAndRead (err, objects) ->
410
+ (expect objects instanceof Array).toBe true
411
+ (expect objects.length).toBe 2
412
+ (expect objects[0].prop).toBe 1
413
+ (expect objects[1].prop).toBe 2
414
+ done()
415
+
416
+ it "can edit a property", (done) ->
417
+ spyon @c, "send", (iq) =>
418
+ (expect ($ "edit",iq).attr "xmlns").toEqual "jabber:iq:joap"
419
+
420
+ res = $iq({type:'result', id: iq.attr 'id'}).c("edit")
421
+ @c._dataRecv createRequest(res)
422
+
423
+ clz.edit "//432", { age: 33 },(iq, err) ->
424
+ (expect typeof iq).toEqual "object"
425
+ (expect err).toBeFalsy()
426
+ done()
427
+
428
+ describe "joap rpc", ->
429
+
430
+ it "can send a request to an instance", (done) ->
431
+ spyon @c, "send", (iq) =>
432
+ (expect ($ "query", iq).attr "xmlns").toEqual "jabber:iq:rpc"
433
+ call = $ "methodCall", iq
434
+ (expect call.length).toEqual 1
435
+ (expect ($ "methodName", call).text()).toEqual "testMethod"
436
+ params = $ "params", call
437
+ (expect params.length).toEqual 1
438
+ res = $iq({type:'result', id: iq.attr 'id'}).c("query")
439
+ .c("methodResponse").c("params").c("param").c("value").c("int").t("2")
440
+ @c._dataRecv createRequest(res.tree())
441
+
442
+ server.methodCall "testMethod", "Class", "instance", [1, "x", false], (iq, err, result) ->
443
+ (expect err?).toEqual false
444
+ (expect result).toBe 2
445
+ done()
446
+
447
+ it "can send a request without parameters", (done) ->
448
+ spyon @c, "send", (iq) =>
449
+ call = $ "methodCall", iq
450
+ (expect call.length).toEqual 1
451
+ (expect ($ "methodName", call).text()).toEqual "myFunction"
452
+
453
+ res = $iq({type:'result', id: iq.attr 'id'}).c("query")
454
+ .c("methodResponse").c("params").c("param").c("value").c("int").t("3")
455
+ @c._dataRecv createRequest(res.tree())
456
+
457
+ server.methodCall "myFunction", (iq, err, result) ->
458
+ (expect err?).toEqual false
459
+ console.log result
460
+ (expect result).toBe 3
461
+ done()