Work around lacking Eq instance for HeaderArg
This commit is contained in:
parent
7d9523eed1
commit
61fe932d0a
1 changed files with 70 additions and 44 deletions
|
@ -26,7 +26,7 @@ spec = describe "Servant.Foreign" $ do
|
||||||
listFromAPISpec
|
listFromAPISpec
|
||||||
|
|
||||||
camelCaseSpec :: Spec
|
camelCaseSpec :: Spec
|
||||||
camelCaseSpec = describe "camelCase" $ do
|
camelCaseSpec = describe "camelCase" $
|
||||||
it "converts FunctionNames to camelCase" $ do
|
it "converts FunctionNames to camelCase" $ do
|
||||||
camelCase ["post", "counter", "inc"] `shouldBe` "postCounterInc"
|
camelCase ["post", "counter", "inc"] `shouldBe` "postCounterInc"
|
||||||
camelCase ["get", "hyphen-ated", "counter"] `shouldBe` "getHyphenatedCounter"
|
camelCase ["get", "hyphen-ated", "counter"] `shouldBe` "getHyphenatedCounter"
|
||||||
|
@ -57,13 +57,28 @@ testApi = listFromAPI (Proxy :: Proxy LangX) (Proxy :: Proxy TestApi)
|
||||||
|
|
||||||
listFromAPISpec :: Spec
|
listFromAPISpec :: Spec
|
||||||
listFromAPISpec = describe "listFromAPI" $ do
|
listFromAPISpec = describe "listFromAPI" $ do
|
||||||
it "generates 4 endpoints for TestApi" $ do
|
it "generates 4 endpoints for TestApi" $
|
||||||
length testApi `shouldBe` 4
|
length testApi `shouldBe` 4
|
||||||
|
|
||||||
let [getReq, postReq, putReq, deleteReq] = testApi
|
let [getReq, postReq, putReq, deleteReq] = testApi
|
||||||
|
|
||||||
|
let reqEq req1 req2 = do
|
||||||
|
_reqUrl req1 `shouldBe` _reqUrl req2
|
||||||
|
_reqMethod req1 `shouldBe` _reqMethod req2
|
||||||
|
_reqBody req1 `shouldBe` _reqBody req2
|
||||||
|
_reqReturnType req1 `shouldBe` _reqReturnType req2
|
||||||
|
_funcName req1 `shouldBe` _funcName req2
|
||||||
|
|
||||||
|
let h = case (_reqHeaders req1, _reqHeaders req2) of
|
||||||
|
([], []) -> True
|
||||||
|
([HeaderArg a], [HeaderArg b]) -> a == b
|
||||||
|
_ -> False
|
||||||
|
|
||||||
|
h `shouldBe` True
|
||||||
|
|
||||||
it "collects all info for get request" $ do
|
it "collects all info for get request" $ do
|
||||||
shouldBe getReq $ defReq
|
let req1 = getReq
|
||||||
|
req2 = defReq
|
||||||
{ _reqUrl = Url
|
{ _reqUrl = Url
|
||||||
[ Segment $ Static "test" ]
|
[ Segment $ Static "test" ]
|
||||||
[ QueryArg ("flag", "boolX") Flag ]
|
[ QueryArg ("flag", "boolX") Flag ]
|
||||||
|
@ -74,8 +89,12 @@ listFromAPISpec = describe "listFromAPI" $ do
|
||||||
, _funcName = ["get", "test"]
|
, _funcName = ["get", "test"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reqEq req1 req2
|
||||||
|
|
||||||
|
|
||||||
it "collects all info for post request" $ do
|
it "collects all info for post request" $ do
|
||||||
shouldBe postReq $ defReq
|
let req1 = getReq
|
||||||
|
req2 = defReq
|
||||||
{ _reqUrl = Url
|
{ _reqUrl = Url
|
||||||
[ Segment $ Static "test" ]
|
[ Segment $ Static "test" ]
|
||||||
[ QueryArg ("param", "intX") Normal ]
|
[ QueryArg ("param", "intX") Normal ]
|
||||||
|
@ -86,8 +105,11 @@ listFromAPISpec = describe "listFromAPI" $ do
|
||||||
, _funcName = ["post", "test"]
|
, _funcName = ["post", "test"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reqEq req1 req2
|
||||||
|
|
||||||
it "collects all info for put request" $ do
|
it "collects all info for put request" $ do
|
||||||
shouldBe putReq $ defReq
|
let req1 = getReq
|
||||||
|
req2 = defReq
|
||||||
{ _reqUrl = Url
|
{ _reqUrl = Url
|
||||||
[ Segment $ Static "test" ]
|
[ Segment $ Static "test" ]
|
||||||
-- Shoud this be |intX| or |listX of intX| ?
|
-- Shoud this be |intX| or |listX of intX| ?
|
||||||
|
@ -99,8 +121,11 @@ listFromAPISpec = describe "listFromAPI" $ do
|
||||||
, _funcName = ["put", "test"]
|
, _funcName = ["put", "test"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reqEq req1 req2
|
||||||
|
|
||||||
it "collects all info for delete request" $ do
|
it "collects all info for delete request" $ do
|
||||||
shouldBe deleteReq $ defReq
|
let req1 = getReq
|
||||||
|
req2 = defReq
|
||||||
{ _reqUrl = Url
|
{ _reqUrl = Url
|
||||||
[ Segment $ Static "test"
|
[ Segment $ Static "test"
|
||||||
, Segment $ Cap ("id", "intX") ]
|
, Segment $ Cap ("id", "intX") ]
|
||||||
|
@ -112,3 +137,4 @@ listFromAPISpec = describe "listFromAPI" $ do
|
||||||
, _funcName = ["delete", "test", "by", "id"]
|
, _funcName = ["delete", "test", "by", "id"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reqEq req1 req2
|
||||||
|
|
Loading…
Reference in a new issue