on master help sign in
Upgrading tests for Axios
915ed65Freezeboy
servant-js/test/Servant/JSSpec.hs+25−1
@@ -78,8 +78,32 @@ spec = describe "Servant.JQuery" $ do
78 generateJSSpec AxiosCustom (AX.generateAxiosJSWith (AX.defAxiosOptions { withCredentials = True }) customOptions)
78 generateJSSpec AxiosCustom (AX.generateAxiosJSWith (AX.defAxiosOptions { withCredentials = True }) customOptions)
79
79
80 angularSpec Angular
80 angularSpec Angular
81+ axiosSpec
81 --angularSpec AngularCustom
82 --angularSpec AngularCustom
82
83
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+
83angularSpec :: TestNames -> Spec
107angularSpec :: TestNames -> Spec
84angularSpec test = describe specLabel $ do
108angularSpec test = describe specLabel $ do
85 it "should implement a service globally" $ do
109 it "should implement a service globally" $ do
@@ -97,7 +121,7 @@ angularSpec test = describe specLabel $ do
97 output jsText
121 output jsText
98 jsText `shouldNotContain` "getsomething($http, "
122 jsText `shouldNotContain` "getsomething($http, "
99 where
123 where
100− specLabel = "generateJS(" ++ (show test) ++ ")"
124+ specLabel = "AngularJS(" ++ (show test) ++ ")"
101 output _ = return ()
125 output _ = return ()
102 testName = "MyService"
126 testName = "MyService"
103 ngOpts = NG.defAngularOptions { NG.serviceName = testName }
127 ngOpts = NG.defAngularOptions { NG.serviceName = testName }