Skip to content

Commit

Permalink
fix callback errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sethpollack committed Feb 8, 2015
1 parent 29eb2e6 commit 20a27ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
7 changes: 4 additions & 3 deletions lib/bugzscout.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ function BugzScout(options) {
}

BugzScout.prototype.submit = function(options, cb) {

if (!options.description) {return cb(Error("You have to provide a description"));}
if (cb && !options.description) {return cb(Error("You have to provide a description"));}

this.domain = options.domain || this.domain;
this.user = options.user || this.user;
Expand Down Expand Up @@ -53,7 +52,9 @@ BugzScout.prototype.submit = function(options, cb) {
if(error){error = error[1];}
var success = /<Success>(.*)<\/Success>/.exec(body);
if(success){success = success[1];}
cb(err || error, success);
if(cb){
cb(err || error, success);
}
});

};
Expand Down
29 changes: 19 additions & 10 deletions test/bugzscout_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ describe("bugzscout", function() {
user: "my user",
project: "my project",
area: "my area",
description: "testing 123"
});
}).to.throw(Error);
}).to.throw(/You have to provide a domain/);

});

Expand All @@ -25,9 +24,8 @@ describe("bugzscout", function() {
domain: "http://your.fogbugz.url/scoutSubmit.asp",
project: "my project",
area: "my area",
description: "testing 123"
});
}).to.throw(Error);
}).to.throw(/You have to provide a user name/);

});

Expand All @@ -37,9 +35,8 @@ describe("bugzscout", function() {
domain: "http://your.fogbugz.url/scoutSubmit.asp",
user: "my user",
area: "my area",
description: "testing 123"
});
}).to.throw(Error);
}).to.throw(/You must provide a FogBugz project/);
});

it("should fail without a area", function() {
Expand All @@ -48,9 +45,8 @@ describe("bugzscout", function() {
domain: "http://your.fogbugz.url",
project: "my project",
user: "my user",
description: "testing 123"
});
}).to.throw(Error);
}).to.throw(/You have to provide an area/);
});
});

Expand Down Expand Up @@ -103,10 +99,23 @@ describe("bugzscout", function() {
area: "my area",
});

bugzscout.submit({}, function(e, r){
expect(e).to.match(/You have to provide a description/);
});

});

it('should not blow up if a callback is not passed in', function(){
var bugzscout = new BugzScout({
domain: "http://your.fogbugz.url",
project: "my project",
user: "my user",
area: "my area",
});

expect(function() {
bugzscout.submit({});
}).to.throw(Error);

}).to.not.throw();
});

});
Expand Down

0 comments on commit 20a27ad

Please sign in to comment.