Skip to content

Commit

Permalink
Added test and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
gflandre committed Jan 28, 2013
1 parent 8077a2d commit b6a22a5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Access to the [Stripe](https://stripe.com/) [API](https://stripe.com/docs/api).
{ email: '[email protected]' },
function(err, customer) {
if (err) {
console.log("Couldn't create the customer record");
console.log(err.message);
return;
}
console.log("customer id", customer.id);
Expand All @@ -28,7 +28,7 @@ Access to the [Stripe](https://stripe.com/) [API](https://stripe.com/docs/api).
## API

All methods takes a callback as their last parameter. The callback is
called with an error code (if any) and then the response.
called with a Javascript `Error` (if any) and then the response.

* `stripe.charges` - create, retrieve, refund and list charges
* `.create(charge)` - [create a charge](https://stripe.com/docs/api#create_charge)
Expand Down
26 changes: 26 additions & 0 deletions test/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var vows = require('vows'),
assert = require('assert'),
sys = require('sys');

var api_key = process.env.STRIPE_API;

if (!api_key) {
sys.puts('To run vows, you must have a STRIPE_API environment variable with a test api key');
process.exit(2)
}

var stripe = require('./../lib/main.js')(api_key);

vows.describe("Error handling").addBatch({
'Retrieve non-existing plan' : {
topic: function() {
stripe.plans.retrieve("unknown_plan_" + Date.now(), this.callback);
},
'returns an error' : function(err, response) {
assert.isNull(response);
assert.instanceOf(err, Error);
assert.equal(err.name, 'invalid_request_error');
assert.isNotNull(err.message);
},
},
}).export(module, {error: false});

0 comments on commit b6a22a5

Please sign in to comment.