This repository has been archived by the owner on May 28, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
11 changed files
with
135 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
*.fasl | ||
bin | ||
vendor/ruby | ||
.bundle |
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 @@ | ||
1.8.7-p352 |
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,3 @@ | ||
source "http://rubygems.org" | ||
|
||
gem 'clucumber' |
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,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 |
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,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 |
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,2 @@ | ||
(When* #?{^I use the API key "([^"]*)"$} (key) | ||
(stripe:set-default-api-key key)) |
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,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))) |
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,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))) | ||
|
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,2 @@ | ||
host: 127.0.0.1 | ||
port: <%= ENV["CLUCUMBER_PORT"] || 42427 %> |
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,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 |