@@ -78,8 +78,32 @@ spec = describe "Servant.JQuery" $ do
7878 generateJSSpec AxiosCustom (AX.generateAxiosJSWith (AX.defAxiosOptions { withCredentials = True }) customOptions)
7979
8080 angularSpec Angular
81+ axiosSpec
8182 --angularSpec AngularCustom
8283
84+axiosSpec :: Spec
85+axiosSpec = describe specLabel $ do
86+ it "should add withCredentials when needed" $ do
87+ let jsText = genJS withCredOpts $ listFromAPI (Proxy :: Proxy TestAPI)
88+ output jsText
89+ jsText `shouldContain` ("withCredentials: true")
90+ it "should add xsrfCookieName when needed" $ do
91+ let jsText = genJS cookieOpts $ listFromAPI (Proxy :: Proxy TestAPI)
92+ output jsText
93+ jsText `shouldContain` ("xsrfCookieName: 'MyXSRFcookie'")
94+ it "should add withCredentials when needed" $ do
95+ let jsText = genJS headerOpts $ listFromAPI (Proxy :: Proxy TestAPI)
96+ output jsText
97+ jsText `shouldContain` ("xsrfHeaderName: 'MyXSRFheader'")
98+ where
99+ specLabel = "Axios"
100+ output _ = return ()
101+ withCredOpts = AX.defAxiosOptions { AX.withCredentials = True }
102+ cookieOpts = AX.defAxiosOptions { AX.xsrfCookieName = Just "MyXSRFcookie" }
103+ headerOpts = AX.defAxiosOptions { AX.xsrfHeaderName = Just "MyXSRFheader" }
104+ genJS :: AxiosOptions -> [AjaxReq] -> String
105+ genJS opts req = concat $ map (AX.generateAxiosJS opts) req
106+
83107angularSpec :: TestNames -> Spec
84108angularSpec test = describe specLabel $ do
85109 it "should implement a service globally" $ do
@@ -97,7 +121,7 @@ angularSpec test = describe specLabel $ do
97121 output jsText
98122 jsText `shouldNotContain` "getsomething($http, "
99123 where
100− specLabel = "generateJS(" ++ (show test) ++ ")"
124+ specLabel = "AngularJS(" ++ (show test) ++ ")"
101125 output _ = return ()
102126 testName = "MyService"
103127 ngOpts = NG.defAngularOptions { NG.serviceName = testName }