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,58 +57,84 @@ 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
|
||||||
{ _reqUrl = Url
|
req2 = defReq
|
||||||
[ Segment $ Static "test" ]
|
{ _reqUrl = Url
|
||||||
[ QueryArg ("flag", "boolX") Flag ]
|
[ Segment $ Static "test" ]
|
||||||
, _reqMethod = "GET"
|
[ QueryArg ("flag", "boolX") Flag ]
|
||||||
, _reqHeaders = [HeaderArg ("header", "listX of stringX")]
|
, _reqMethod = "GET"
|
||||||
, _reqBody = Nothing
|
, _reqHeaders = [HeaderArg ("header", "listX of stringX")]
|
||||||
, _reqReturnType = "intX"
|
, _reqBody = Nothing
|
||||||
, _funcName = ["get", "test"]
|
, _reqReturnType = "intX"
|
||||||
}
|
, _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
|
||||||
{ _reqUrl = Url
|
req2 = defReq
|
||||||
[ Segment $ Static "test" ]
|
{ _reqUrl = Url
|
||||||
[ QueryArg ("param", "intX") Normal ]
|
[ Segment $ Static "test" ]
|
||||||
, _reqMethod = "POST"
|
[ QueryArg ("param", "intX") Normal ]
|
||||||
, _reqHeaders = []
|
, _reqMethod = "POST"
|
||||||
, _reqBody = Just "listX of stringX"
|
, _reqHeaders = []
|
||||||
, _reqReturnType = "voidX"
|
, _reqBody = Just "listX of stringX"
|
||||||
, _funcName = ["post", "test"]
|
, _reqReturnType = "voidX"
|
||||||
}
|
, _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
|
||||||
{ _reqUrl = Url
|
req2 = defReq
|
||||||
[ Segment $ Static "test" ]
|
{ _reqUrl = Url
|
||||||
-- Shoud this be |intX| or |listX of intX| ?
|
[ Segment $ Static "test" ]
|
||||||
[ QueryArg ("params", "listX of intX") List ]
|
-- Shoud this be |intX| or |listX of intX| ?
|
||||||
, _reqMethod = "PUT"
|
[ QueryArg ("params", "listX of intX") List ]
|
||||||
, _reqHeaders = []
|
, _reqMethod = "PUT"
|
||||||
, _reqBody = Just "stringX"
|
, _reqHeaders = []
|
||||||
, _reqReturnType = "voidX"
|
, _reqBody = Just "stringX"
|
||||||
, _funcName = ["put", "test"]
|
, _reqReturnType = "voidX"
|
||||||
}
|
, _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
|
||||||
{ _reqUrl = Url
|
req2 = defReq
|
||||||
[ Segment $ Static "test"
|
{ _reqUrl = Url
|
||||||
, Segment $ Cap ("id", "intX") ]
|
[ Segment $ Static "test"
|
||||||
[]
|
, Segment $ Cap ("id", "intX") ]
|
||||||
, _reqMethod = "DELETE"
|
[]
|
||||||
, _reqHeaders = []
|
, _reqMethod = "DELETE"
|
||||||
, _reqBody = Nothing
|
, _reqHeaders = []
|
||||||
, _reqReturnType = "voidX"
|
, _reqBody = Nothing
|
||||||
, _funcName = ["delete", "test", "by", "id"]
|
, _reqReturnType = "voidX"
|
||||||
}
|
, _funcName = ["delete", "test", "by", "id"]
|
||||||
|
}
|
||||||
|
|
||||||
|
reqEq req1 req2
|
||||||
|
|
Loading…
Reference in a new issue