Upgrading tests for Axios
This commit is contained in:
parent
60d94be0e9
commit
915ed652e1
1 changed files with 25 additions and 1 deletions
|
@ -78,8 +78,32 @@ spec = describe "Servant.JQuery" $ do
|
||||||
generateJSSpec AxiosCustom (AX.generateAxiosJSWith (AX.defAxiosOptions { withCredentials = True }) customOptions)
|
generateJSSpec AxiosCustom (AX.generateAxiosJSWith (AX.defAxiosOptions { withCredentials = True }) customOptions)
|
||||||
|
|
||||||
angularSpec Angular
|
angularSpec Angular
|
||||||
|
axiosSpec
|
||||||
--angularSpec AngularCustom
|
--angularSpec AngularCustom
|
||||||
|
|
||||||
|
axiosSpec :: Spec
|
||||||
|
axiosSpec = describe specLabel $ do
|
||||||
|
it "should add withCredentials when needed" $ do
|
||||||
|
let jsText = genJS withCredOpts $ listFromAPI (Proxy :: Proxy TestAPI)
|
||||||
|
output jsText
|
||||||
|
jsText `shouldContain` ("withCredentials: true")
|
||||||
|
it "should add xsrfCookieName when needed" $ do
|
||||||
|
let jsText = genJS cookieOpts $ listFromAPI (Proxy :: Proxy TestAPI)
|
||||||
|
output jsText
|
||||||
|
jsText `shouldContain` ("xsrfCookieName: 'MyXSRFcookie'")
|
||||||
|
it "should add withCredentials when needed" $ do
|
||||||
|
let jsText = genJS headerOpts $ listFromAPI (Proxy :: Proxy TestAPI)
|
||||||
|
output jsText
|
||||||
|
jsText `shouldContain` ("xsrfHeaderName: 'MyXSRFheader'")
|
||||||
|
where
|
||||||
|
specLabel = "Axios"
|
||||||
|
output _ = return ()
|
||||||
|
withCredOpts = AX.defAxiosOptions { AX.withCredentials = True }
|
||||||
|
cookieOpts = AX.defAxiosOptions { AX.xsrfCookieName = Just "MyXSRFcookie" }
|
||||||
|
headerOpts = AX.defAxiosOptions { AX.xsrfHeaderName = Just "MyXSRFheader" }
|
||||||
|
genJS :: AxiosOptions -> [AjaxReq] -> String
|
||||||
|
genJS opts req = concat $ map (AX.generateAxiosJS opts) req
|
||||||
|
|
||||||
angularSpec :: TestNames -> Spec
|
angularSpec :: TestNames -> Spec
|
||||||
angularSpec test = describe specLabel $ do
|
angularSpec test = describe specLabel $ do
|
||||||
it "should implement a service globally" $ do
|
it "should implement a service globally" $ do
|
||||||
|
@ -97,7 +121,7 @@ angularSpec test = describe specLabel $ do
|
||||||
output jsText
|
output jsText
|
||||||
jsText `shouldNotContain` "getsomething($http, "
|
jsText `shouldNotContain` "getsomething($http, "
|
||||||
where
|
where
|
||||||
specLabel = "generateJS(" ++ (show test) ++ ")"
|
specLabel = "AngularJS(" ++ (show test) ++ ")"
|
||||||
output _ = return ()
|
output _ = return ()
|
||||||
testName = "MyService"
|
testName = "MyService"
|
||||||
ngOpts = NG.defAngularOptions { NG.serviceName = testName }
|
ngOpts = NG.defAngularOptions { NG.serviceName = testName }
|
||||||
|
|
Loading…
Add table
Reference in a new issue