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
ab1da2bd
Commit
ab1da2bd
authored
5 years ago
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
Factor some generally useful SpecWith
parent
98d6fe6a
No related branches found
Branches containing commit
No related tags found
1 merge request
!8
HTTP API for Voucher redemption
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
PaymentServer.cabal
+1
-0
1 addition, 0 deletions
PaymentServer.cabal
test/SpecStripe.hs
+10
-7
10 additions, 7 deletions
test/SpecStripe.hs
test/Util/Spec.hs
+32
-0
32 additions, 0 deletions
test/Util/Spec.hs
with
43 additions
and
7 deletions
PaymentServer.cabal
+
1
−
0
View file @
ab1da2bd
...
...
@@ -49,6 +49,7 @@ test-suite PaymentServer-test
, Util.WAI
, Util.Gen
, Util.JSON
, Util.Spec
build-depends: base
, PaymentServer
, hspec
...
...
This diff is collapsed.
Click to expand it.
test/SpecStripe.hs
+
10
−
7
View file @
ab1da2bd
...
...
@@ -14,6 +14,7 @@ import Data.Aeson
)
import
Test.Hspec
(
Spec
,
parallel
,
describe
,
it
)
...
...
@@ -72,6 +73,11 @@ import PaymentServer.Persistence
(
Voucher
,
memory
)
import
Util.Spec
(
wrongMethodNotAllowed
,
nonJSONUnsupportedMediaType
,
wrongJSONInvalidRequest
)
stripeAPI
::
Proxy
StripeAPI
stripeAPI
=
Proxy
...
...
@@ -80,13 +86,11 @@ app :: IO Application
app
=
serve
stripeAPI
.
stripeServer
<$>
memory
spec_webhook
::
Spec
spec_webhook
=
with
app
$
do
spec_webhook
=
with
app
$
parallel
$
do
describe
"error behavior of POST /webhook"
$
do
it
"responds to non-JSON Content-Type with 415 (Unsupported Media Type)"
$
post
"/webhook"
"xxx"
`
shouldRespondWith
`
415
it
"responds to JSON non-Event body with 400 (Invalid Request)"
$
postJSON
"/webhook"
"{}"
`
shouldRespondWith
`
400
wrongMethodNotAllowed
"GET"
"/webhook"
nonJSONUnsupportedMediaType
"/webhook"
wrongJSONInvalidRequest
"/webhook"
"{}"
-- I would like to make most or all of these into property tests. *This*
-- test shows how you can do it. Yay. The main thing (for me, anyway) to
...
...
@@ -109,7 +113,6 @@ spec_webhook = with app $ do
property
xtest_postWithEventBody
bodyMatcher
::
[
Network
.
HTTP
.
Types
.
Header
]
->
Body
->
Maybe
String
bodyMatcher
_
"{}"
=
Nothing
bodyMatcher
_
body
=
Just
$
show
body
...
...
This diff is collapsed.
Click to expand it.
test/Util/Spec.hs
0 → 100644
+
32
−
0
View file @
ab1da2bd
{-# LANGUAGE OverloadedStrings #-}
module
Util.Spec
(
wrongMethodNotAllowed
,
nonJSONUnsupportedMediaType
,
wrongJSONInvalidRequest
)
where
import
Test.Hspec
(
it
)
import
Test.Hspec.Wai
(
post
,
request
,
shouldRespondWith
)
import
Util.WAI
(
postJSON
)
wrongMethodNotAllowed
method
path
=
it
"responds to an unsupported method with 405 (Method Not Allowed)"
$
request
method
path
[]
""
`
shouldRespondWith
`
405
nonJSONUnsupportedMediaType
path
=
it
"responds to non-JSON Content-Type with 415 (Unsupported Media Type)"
$
post
path
"xxx"
`
shouldRespondWith
`
415
wrongJSONInvalidRequest
path
json
=
it
"responds to JSON body representing the wrong data with 400 (Invalid Request)"
$
postJSON
path
json
`
shouldRespondWith
`
400
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