Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a few tests using clucumber and fix bugs exposed.

Now tests charge creation with an explicit card and a token.

Bugs exposed and fixed:

 * Declare that create-{charge,token,invoice-item} return the ID of
   objects created.
 * Use the correct resource to create a token.
  • Loading branch information...
commit 1fe6bfffafc56c8b4ace4a1c9ba8de838770379c 1 parent 98816b5
@antifuchs authored
View
3  .gitignore
@@ -1 +1,4 @@
*.fasl
+bin
+vendor/ruby
+.bundle
View
1  .rbenv-version
@@ -0,0 +1 @@
+1.8.7-p352
View
3  Gemfile
@@ -0,0 +1,3 @@
+source "http://rubygems.org"
+
+gem 'clucumber'
View
23 Gemfile.lock
@@ -0,0 +1,23 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ builder (3.0.0)
+ clucumber (0.4.1)
+ cucumber (~> 0.10.0)
+ cucumber (0.10.7)
+ builder (>= 2.1.2)
+ diff-lcs (>= 1.1.2)
+ gherkin (~> 2.4.0)
+ json (>= 1.4.6)
+ term-ansicolor (>= 1.0.5)
+ diff-lcs (1.1.3)
+ gherkin (2.4.21)
+ json (>= 1.4.6)
+ json (1.6.1)
+ term-ansicolor (1.0.7)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ clucumber
View
10 cl-stripe.lisp
@@ -173,7 +173,7 @@
;;; Charges
-(def-api-call :create (:charge :http-resource :charges)
+(def-api-call :create (:charge :http-resource :charges :return-id t)
(amount currency customer card description)
"https://stripe.com/api/docs#create_charge")
@@ -188,7 +188,7 @@
;;; Customers
-(def-api-call :create (:customer :http-resource :customers)
+(def-api-call :create (:customer :http-resource :customers :return-id t)
(card coupon email description plan trial-end)
"https://stripe.com/api/docs#create_customer")
@@ -206,7 +206,7 @@
;;; Card Tokens
-(def-api-call :create :token (card amount currency)
+(def-api-call :create (:token :http-resource :tokens :return-id t) (card amount currency)
"https://stripe.com/api/docs#create_token")
(def-api-call :retrieve (:token :id t) ()
@@ -250,7 +250,7 @@
;;; Invoice items
-(def-api-call :create (:invoice-item :http-resource :invoice-items)
+(def-api-call :create (:invoice-item :http-resource :invoice-items :return-id t)
(customer amount currency description)
"https://stripe.com/api/docs#create_invoiceitem")
@@ -264,4 +264,4 @@
"https://stripe.com/api/docs#delete_invoiceitem")
(def-api-call :list :invoice-items (customer count offset)
- "https://stripe.com/api/docs#list_invoiceitems")
+ "https://stripe.com/api/docs#list_invoiceitems")
View
24 features/charge.feature
@@ -0,0 +1,24 @@
+Feature: Charges
+
+ As a user of stripe,
+ I want to create charges
+ so I can get paid by my customers.
+
+Background:
+
+ When I use the API key "wOUwrSt8JrWsPyHCsfkCDhCCqGomv4kp"
+
+Scenario: Create a charge with a credit card
+
+ When I charge $20 to a random credit card
+
+ Then the charge should exist
+ And the charge should be for $20
+
+Scenario: Create a charge with a token
+
+ When I create a token for a random credit card
+ And I charge ct3033 to the token
+
+ Then the charge should exist
+ And the charge should be for ct3033
View
2  features/step_definitions/api_steps.lisp
@@ -0,0 +1,2 @@
+(When* #?{^I use the API key "([^"]*)"$} (key)
+ (stripe:set-default-api-key key))
View
10 features/step_definitions/card_steps.lisp
@@ -0,0 +1,10 @@
+(When* #?{^I create a token for a random credit card$} ()
+ (setf (var :card) *random-card*
+ (var :amount) nil
+ (var :currency) nil)
+ (multiple-value-bind (token id)
+ (stripe:create-token :card (var :card))
+ (assert (stringp id) (id)
+ "ID is not a string: ~s" id)
+ (setf (var :token) token
+ (var :token-id) id)))
View
49 features/step_definitions/charge_steps.lisp
@@ -0,0 +1,49 @@
+;; -*- lisp -*-
+
+(defun lookup-currency-symbol (currency-symbol)
+ (values
+ (cdr (assoc currency-symbol '(("$" . "usd")
+ ("ct" . "usd"))
+ :test 'string-equal))
+ (if (string-equal currency-symbol "$")
+ 100
+ 1)))
+
+;; TODO: generate the card number randomly
+(defvar *random-card* (list :number "4242424242424242" :exp_month "12" :exp_year "2012" :cvc "123"
+ :name "Tester Oberloisl"
+ :address-line1 "555 Random Avenue" :address-line2 "Apt 9"
+ :address-zip "55959" :address-state "Ohai-o"
+ :address_country "USA"))
+
+(Then* #?{^the charge should exist$} ()
+ (assert (nth-value 1 (stripe:retrieve-charge (var :charge-id)))))
+
+(Then* #?{^the charge should be for ([^0-9]+)\s*([0-9]+)$} (currency-symbol amount)
+ (let ((amount (parse-integer amount)))
+ (multiple-value-bind (currency multiplier) (lookup-currency-symbol currency-symbol)
+ (assert (string-equal (stripe:sstruct-get (var :charge) :currency) currency) ()
+ "Currencies are not equal: ~s != ~s" (stripe:sstruct-get :currency) currency)
+ (assert (= (stripe:sstruct-get (var :charge) :amount) (* amount multiplier)) ()
+ "Amounts are not equal: ~s != ~s"
+ (/ (stripe:sstruct-get (var :charge) :amount) multiplier) amount))))
+
+(When* #?{^I charge ([^0-9]+)\s*([0-9]+) to (a random credit card|the token)$} (currency-symbol amount what)
+ (if (string= what "a random credit card")
+ (setf (var :card) *random-card*)
+ (setf (var :card) (var :token-id)))
+ (multiple-value-bind (currency multiplier) (lookup-currency-symbol currency-symbol)
+ (setf (var :currency) currency)
+ (setf (var :amount) (parse-integer amount :junk-allowed nil))
+ (setf (var :amount) (* multiplier (var :amount))))
+
+ (multiple-value-bind (charge id)
+ (stripe:create-charge :amount (var :amount)
+ :currency (var :currency)
+ :description (format nil "Cucumber test charge ~a" (get-universal-time))
+ :card (var :card))
+ (assert (stringp id) (id)
+ "ID is not a string: ~s" id)
+ (setf (var :charge) charge
+ (var :charge-id) id)))
+
View
2  features/step_definitions/clucumber.wire
@@ -0,0 +1,2 @@
+host: 127.0.0.1
+port: <%= ENV["CLUCUMBER_PORT"] || 42427 %>
View
13 features/support/env.rb
@@ -0,0 +1,13 @@
+require 'clucumber'
+begin
+ puts "Launching..."
+ (@main_clucumber = ClucumberSubprocess.launch(File.expand_path("../", File.dirname(__FILE__)))).listen <<-LISP
+ (load #p"#{File.expand_path("../../cl-stripe.asd", File.dirname(__FILE__))}")
+ (ql:quickload :cl-stripe)
+ LISP
+ STDERR.puts(@main_clucumber.output)
+rescue PTY::ChildExited => e
+ STDERR.puts "Failure: #{@main_clucumber.inspect}: #{e.inspect}!"
+ STDERR.puts(@main_clucumber && @main_clucumber.output)
+ exit 1
+end
Please sign in to comment.
Something went wrong with that request. Please try again.