Skip to content

Commit

Permalink
Updated tests and pubsub error response.
Browse files Browse the repository at this point in the history
  • Loading branch information
DBeath committed Feb 21, 2014
1 parent 9602531 commit 4df65ad
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ PubSubHubbub.prototype._onPostRequest = function(req, res){
* @param {String} message Error message to display
*/
PubSubHubbub.prototype._sendError = function(req, res, code, message){
res.writeHead(500, {"Content-Type": "text/html"});
res.writeHead(code, {"Content-Type": "text/html"});
res.end("<!DOCTYPE html>\n"+
"<html>\n"+
" <head>\n"+
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
REPORTER = dot
REPORTER = spec
test:
@NODE_ENV=test ./node_modules/.bin/mocha \
--reporter $(REPORTER) \
Expand Down
40 changes: 29 additions & 11 deletions test/pubsubhubbub.test.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,56 @@
var expect = require('chai').expect,
http = require('http'),
request = require('request'),
crypto = require('crypto'),
supertest = require('supertest'),
pubSubHubbub = require("../index");

var pubsub = pubSubHubbub.createServer({
callbackUrl: "http://kreata.ee:1337",
callbackUrl: "http://localhost:8000/callback",
secret: "MyTopSecret",
username: "Test",
password: "P@ssw0rd"
});

var topic = 'http://test.com/feed',
encrypted_secret = crypto.createHmac("sha1", pubsub.secret).update(topic).digest("hex");

var notification = function(){
var options = {
url: 'http://localhost:8000',
headers: {
'X-Hub-Signature': encrypted_secret,
'X-PubSubHubbub-Callback': 'http://localhost:8000/callback',
'hub.topic': 'http://test.com',
'link': 'rel=hub"http://localhost/hub";rel=self"http://test.com"'
}
}
return request.post(options);
}

describe('pubsubhubbub', function() {
before(function() {
pubsub.listen(8000);
});

it('should see post', function(done){
request.post(notification(), function(err, res, body){
expect(res.statusCode).to.equal(200);
});
});

after(function() {
pubsub.close();
pubsub.server.close();
});
});

suite("Pubsubhubbub tests", function() {
var pubsub = pubSubHubbub.createServer({
callbackUrl: "http://kreata.ee:1337",
secret: "MyTopSecret",
username: "Test",
password: "P@ssw0rd"
});

test("should exist", function() {
test("pubsub should exist", function() {
expect(pubsub).to.exist;
});

test("options passed correctly", function() {
expect(pubsub.callbackUrl).to.equal("http://kreata.ee:1337");
expect(pubsub.callbackUrl).to.equal("http://localhost:8000/callback");
expect(pubsub.secret).to.equal("MyTopSecret");
});

Expand Down

0 comments on commit 4df65ad

Please sign in to comment.