Update tests for Axios
This commit is contained in:
parent
2e2eac6543
commit
3ff1f5c953
2 changed files with 10 additions and 3 deletions
|
@ -24,7 +24,9 @@ generateAxiosJSWith :: CommonGeneratorOptions -> AjaxReq -> String
|
||||||
generateAxiosJSWith opts req = "\n" <>
|
generateAxiosJSWith opts req = "\n" <>
|
||||||
fname <> " = function(" <> argsStr <> ")\n"
|
fname <> " = function(" <> argsStr <> ")\n"
|
||||||
<> "{\n"
|
<> "{\n"
|
||||||
<> " return axios." <> method <> "(" <> url <> ",\n"
|
<> " return axios(" <> url <> ",\n"
|
||||||
|
<> " {\n"
|
||||||
|
<> " method: '" <> method <> "'\n"
|
||||||
<> dataBody
|
<> dataBody
|
||||||
<> reqheaders
|
<> reqheaders
|
||||||
<> " });\n"
|
<> " });\n"
|
||||||
|
@ -76,7 +78,7 @@ generateAxiosJSWith opts req = "\n" <>
|
||||||
method = map toLower $ req ^. reqMethod
|
method = map toLower $ req ^. reqMethod
|
||||||
url = if url' == "'" then "'/'" else url'
|
url = if url' == "'" then "'/'" else url'
|
||||||
url' = "'"
|
url' = "'"
|
||||||
++ urlPrefix opts
|
-- ++ urlPrefix opts
|
||||||
++ urlArgs
|
++ urlArgs
|
||||||
++ queryArgs
|
++ queryArgs
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import Servant.JS
|
||||||
import qualified Servant.JS.Vanilla as JS
|
import qualified Servant.JS.Vanilla as JS
|
||||||
import qualified Servant.JS.JQuery as JQ
|
import qualified Servant.JS.JQuery as JQ
|
||||||
import qualified Servant.JS.Angular as NG
|
import qualified Servant.JS.Angular as NG
|
||||||
|
import qualified Servant.JS.Axios as AX
|
||||||
import Servant.JSSpec.CustomHeaders
|
import Servant.JSSpec.CustomHeaders
|
||||||
|
|
||||||
type TestAPI = "simple" :> ReqBody '[JSON,FormUrlEncoded] String :> Post '[JSON] Bool
|
type TestAPI = "simple" :> ReqBody '[JSON,FormUrlEncoded] String :> Post '[JSON] Bool
|
||||||
|
@ -55,6 +56,8 @@ data TestNames = Vanilla
|
||||||
| JQueryCustom
|
| JQueryCustom
|
||||||
| Angular
|
| Angular
|
||||||
| AngularCustom
|
| AngularCustom
|
||||||
|
| Axios
|
||||||
|
| AxiosCustom
|
||||||
deriving (Show, Eq)
|
deriving (Show, Eq)
|
||||||
|
|
||||||
customOptions :: CommonGeneratorOptions
|
customOptions :: CommonGeneratorOptions
|
||||||
|
@ -71,6 +74,8 @@ spec = describe "Servant.JQuery" $ do
|
||||||
generateJSSpec JQueryCustom (JQ.generateJQueryJSWith customOptions)
|
generateJSSpec JQueryCustom (JQ.generateJQueryJSWith customOptions)
|
||||||
generateJSSpec Angular (NG.generateAngularJS NG.defAngularOptions)
|
generateJSSpec Angular (NG.generateAngularJS NG.defAngularOptions)
|
||||||
generateJSSpec AngularCustom (NG.generateAngularJSWith NG.defAngularOptions customOptions)
|
generateJSSpec AngularCustom (NG.generateAngularJSWith NG.defAngularOptions customOptions)
|
||||||
|
generateJSSpec Axios AX.generateAxiosJS
|
||||||
|
generateJSSpec AxiosCustom (AX.generateAxiosJSWith customOptions)
|
||||||
|
|
||||||
angularSpec Angular
|
angularSpec Angular
|
||||||
angularSpec AngularCustom
|
angularSpec AngularCustom
|
||||||
|
@ -143,7 +148,7 @@ generateJSSpec n gen = describe specLabel $ do
|
||||||
parseFromString jsStr `shouldSatisfy` isRight
|
parseFromString jsStr `shouldSatisfy` isRight
|
||||||
where
|
where
|
||||||
specLabel = "generateJS(" ++ (show n) ++ ")"
|
specLabel = "generateJS(" ++ (show n) ++ ")"
|
||||||
output _ = return ()
|
output = putStrLn
|
||||||
genJS req = gen req
|
genJS req = gen req
|
||||||
header :: TestNames -> String -> String -> String
|
header :: TestNames -> String -> String -> String
|
||||||
header v headerName headerValue
|
header v headerName headerValue
|
||||||
|
|
Loading…
Add table
Reference in a new issue