Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PaymentServer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Administrator
PaymentServer
Commits
29d9d7a2
Commit
29d9d7a2
authored
4 years ago
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
Test one more failure codepath
parent
c277c6e8
No related branches found
No related tags found
1 merge request
!87
Add tests for CORS behavior
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/FakeStripe.hs
+19
-0
19 additions, 0 deletions
test/FakeStripe.hs
test/Stripe.hs
+13
-6
13 additions, 6 deletions
test/Stripe.hs
with
32 additions
and
6 deletions
test/FakeStripe.hs
+
19
−
0
View file @
29d9d7a2
...
...
@@ -4,6 +4,7 @@
module
FakeStripe
(
withFakeStripe
,
chargeOkay
,
chargeFailed
)
where
import
Text.RawString.QQ
...
...
@@ -23,6 +24,7 @@ import Data.Time.Calendar
import
Network.HTTP.Types
(
status200
,
status400
)
import
Network.Wai
...
...
@@ -41,6 +43,17 @@ import Web.Stripe.Client
,
Endpoint
(
Endpoint
)
)
anError
::
ByteString
anError
=
[
r
|
{
"error": {
"type": "card_error",
"code": "expired_card",
"message": "Your card is expired."
}
}
|]
aCharge
::
ByteString
aCharge
=
[
r
|
{
...
...
@@ -138,11 +151,17 @@ aCharge = [r|
}
|]
-- Accept a charge creation and respond in the affirmative.
chargeOkay
::
Application
chargeOkay
req
respond
=
respond
.
responseLBS
status200
[]
$
aCharge
chargeFailed
::
Application
chargeFailed
req
respond
=
respond
.
responseLBS
status400
[]
$
anError
-- Pass a Stripe-flavored configuration for a running Wai application to a
-- function and evaluate the resulting IO action.
withFakeStripe
::
IO
Application
->
(
StripeConfig
->
IO
a
)
->
IO
a
...
...
This diff is collapsed.
Click to expand it.
test/Stripe.hs
+
13
−
6
View file @
29d9d7a2
...
...
@@ -70,6 +70,7 @@ import PaymentServer.Server
import
FakeStripe
(
withFakeStripe
,
chargeOkay
,
chargeFailed
)
tests
::
TestTree
...
...
@@ -82,13 +83,19 @@ corsTests :: TestTree
corsTests
=
testGroup
"CORS"
[
testCase
"a request with the wrong content-type receives a CORS-enabled response"
$
assertCORSHeader
"POST"
textPlain
validChargeBytes
assertCORSHeader
chargeOkay
"POST"
textPlain
validChargeBytes
,
testCase
"a request without a valid charge in the body receives a CORS-enabled response"
$
assertCORSHeader
"POST"
applicationJSON
invalidChargeBytes
assertCORSHeader
chargeOkay
"POST"
applicationJSON
invalidChargeBytes
,
testCase
"a request with the wrong request method receives a CORS-enabled response"
$
assertCORSHeader
"GET"
applicationJSON
validChargeBytes
assertCORSHeader
chargeOkay
"GET"
applicationJSON
validChargeBytes
,
testCase
"a request associated with an error from Stripe receives a CORS-enabled response"
$
assertCORSHeader
chargeFailed
"POST"
applicationJSON
validChargeBytes
,
testCase
"a request with a valid charge in the body receives a CORS-enabled response"
$
assertCORSHeader
"POST"
applicationJSON
validChargeBytes
assertCORSHeader
chargeOkay
"POST"
applicationJSON
validChargeBytes
]
where
textPlain
=
[(
"content-type"
,
"text/plain"
)]
...
...
@@ -96,8 +103,8 @@ corsTests =
validChargeBytes
=
"{
\"
token
\"
:
\"
abcdef
\"
,
\"
voucher
\"
:
\"
lmnopqrst
\"
,
\"
amount
\"
:
\"
650
\"
,
\"
currency
\"
:
\"
USD
\"
}"
invalidChargeBytes
=
"[1, 2, 3]"
assertCORSHeader
method
headers
body
=
withFakeStripe
(
return
chargeOkay
)
$
assertCORSHeader
stripeResponse
method
headers
body
=
withFakeStripe
(
return
stripeResponse
)
$
\
stripeConfig
->
do
db
<-
memory
let
origins
=
[
"example.invalid"
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment