@@ -16,6 +16,7 @@ suite =
1616 , nullDecoderTests
1717 , serverErrorDecoderTests
1818 , getErrorMessageTests
19+ , urlWithQueryStringTests
1920 ]
2021
2122
@@ -237,3 +238,65 @@ getErrorMessageTests =
237238 |> Engage . Http . getErrorMessage { localization = Engage . Localization . empty }
238239 |> Expect . equal " It wasn't found"
239240 ]
241+
242+
243+ urlWithQueryStringTests : Test
244+ urlWithQueryStringTests =
245+ describe " urlWithQueryString"
246+ [ test " empty" <|
247+ \ _ ->
248+ Engage . Http . urlWithQueryString " " " " []
249+ |> Expect . equal " /"
250+ , test " relative base" <|
251+ \ _ ->
252+ Engage . Http . urlWithQueryString " /api/" " " []
253+ |> Expect . equal " /api/"
254+ , test " relative base ensures ends with slash" <|
255+ \ _ ->
256+ Engage . Http . urlWithQueryString " /api" " " []
257+ |> Expect . equal " /api/"
258+ , test " relative base with path separated by slash" <|
259+ \ _ ->
260+ Engage . Http . urlWithQueryString " /api" " cat/blog" []
261+ |> Expect . equal " /api/cat/blog"
262+ , test " relative multi-part base with path separated by slash" <|
263+ \ _ ->
264+ Engage . Http . urlWithQueryString " /DesktopModules/MyCompany/API/MyModule" " cat/blog" []
265+ |> Expect . equal " /DesktopModules/MyCompany/API/MyModule/cat/blog"
266+ , test " absolute base" <|
267+ \ _ ->
268+ Engage . Http . urlWithQueryString " https://example.com/" " " []
269+ |> Expect . equal " https://example.com/"
270+ , test " absolute base ensures ends with slash" <|
271+ \ _ ->
272+ Engage . Http . urlWithQueryString " https://example.com" " " []
273+ |> Expect . equal " https://example.com/"
274+ , test " absolute base with path separated by slash" <|
275+ \ _ ->
276+ Engage . Http . urlWithQueryString " https://example.com" " cat/blog" []
277+ |> Expect . equal " https://example.com/cat/blog"
278+ , test " absolute multi-part base with path separated by slash" <|
279+ \ _ ->
280+ Engage . Http . urlWithQueryString " https://example.com/DesktopModules/MyCompany/API/MyModule" " cat/blog" []
281+ |> Expect . equal " https://example.com/DesktopModules/MyCompany/API/MyModule/cat/blog"
282+ , test " no methodName - single query-string added with question mark" <|
283+ \ _ ->
284+ Engage . Http . urlWithQueryString " https://example.com/API/MyModule" " " [ ( " page" , " 1" ) ]
285+ |> Expect . equal " https://example.com/API/MyModule/?page=1"
286+ , test " with methodName - single query-string added with question mark" <|
287+ \ _ ->
288+ Engage . Http . urlWithQueryString " https://example.com/API/MyModule" " elevate" [ ( " page" , " 1" ) ]
289+ |> Expect . equal " https://example.com/API/MyModule/elevate?page=1"
290+ , test " no methodName - many query-strings" <|
291+ \ _ ->
292+ Engage . Http . urlWithQueryString " https://example.com/API/MyModule" " " [ ( " page" , " 1" ) , ( " name" , " fang" ) , ( " type" , " page" ) , ( " author" , " b" ) , ( " choice" , " 0" ) ]
293+ |> Expect . equal " https://example.com/API/MyModule/?page=1&name=fang&type=page&author=b&choice=0"
294+ , test " with methodName - many query-strings" <|
295+ \ _ ->
296+ Engage . Http . urlWithQueryString " https://example.com/API/MyModule" " elevate" [ ( " name" , " fang" ) , ( " type" , " page" ) , ( " author" , " b" ) , ( " choice" , " 0" ) ]
297+ |> Expect . equal " https://example.com/API/MyModule/elevate?name=fang&type=page&author=b&choice=0"
298+ , test " query string values encoded" <|
299+ \ _ ->
300+ Engage . Http . urlWithQueryString " https://example.com/" " " [ ( " name" , " Brené Brown" ) , ( " type" , " one & done" ) , ( " other" , " b (or c)" ) ]
301+ |> Expect . equal " https://example.com/?name=Bren%C3%A9%20Brown&type=one%20%26%20done&other=b%20(or%20c)"
302+ ]
0 commit comments