This repository has been archived by the owner on Dec 20, 2017. It is now read-only.
forked from technoweenie/nubnub
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de5455f
commit 8f017b3
Showing
2 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
assert = require 'assert' | ||
http = require 'http' | ||
url = require 'url' | ||
query = require 'querystring' | ||
nub = require '../src' | ||
|
||
port = 9999 | ||
server = http.createServer (req, resp) -> | ||
body = '' | ||
req.on 'data', (chunk) -> body += chunk | ||
|
||
req.on 'end', -> | ||
req_url = url.parse req.url, true | ||
|
||
switch req_url.query.testing | ||
when 'json' | ||
assert.equal "[{\"abc\":1}]", body | ||
resp.writeHead 200 | ||
resp.end "ok" | ||
when 'error' | ||
resp.writeHead 500 | ||
resp.end() | ||
|
||
req = | ||
'hub.callback': 'http://localhost:9999?testing=json' | ||
'hub.mode': 'subscribe' | ||
'hub.topic': 'http://server.com/foo' | ||
'hub.verify': 'sync' | ||
'hub.lease_seconds': '1000' | ||
sub = nub.subscribe(query.stringify(req)) | ||
|
||
server.listen(port) | ||
|
||
calls = 2 | ||
|
||
# successful publishing | ||
sub.publish [{abc: 1}], {format: 'json'}, (err, resp) -> | ||
assert.equal null, err | ||
done() | ||
|
||
# errored | ||
sub.callback = sub.callback.replace(/json/, 'error') | ||
sub.publish [{abc: 1}], {format: 'json'}, (err, resp) -> | ||
assert.equal 'bad status', err.error | ||
done() | ||
|
||
done = -> | ||
calls -= 1 | ||
if calls == 0 | ||
server.close() | ||
|
||
process.on 'exit', -> console.log 'done' |