git.iko.soy/haskell-servant/servant-elm
on master help sign in
Fix tests
commita9d70354d95b836b3f0d6eaed123bcd7b2bac4fa authorKostiantyn Rybnikov <k-bx@k-bx.com> dateTue 28 May 2019, 16:26 (7 years ago) parent7d7916e
14 files changed+81−86
src/Servant/Elm/Internal/Generate.hs+4 test/CompileSpec.hs+2−2 test/elm-sources/elm.json+1−1 test/elm-sources/getBooksByIdSource.elm+6−6 test/elm-sources/getBooksByTitleSource.elm+6−6 test/elm-sources/getBooksSource.elm+6−6 test/elm-sources/getNothingSource.elm+9−12 test/elm-sources/getOneSource.elm+6−6 test/elm-sources/getOneWithDynamicUrlSource.elm+5−5 test/elm-sources/getWithaheaderSource.elm+6−6 test/elm-sources/getWitharesponseheaderSource.elm+6−6 test/elm-sources/postBooksSource.elm+9−12 test/elm-sources/postTwoSource.elm+6−6 test/elm-sources/putNothingSource.elm+9−12
src/Servant/Elm/Internal/Generate.hs+4
@@ -531,6 +531,10 @@ renderDecoderName elmTypeExpr =
531531 case elmTypeExpr of
532532 ETyApp (ETyCon (ETCon "List")) t ->
533533 parens ("Json.Decode.list " <> parens (renderDecoderName t))
534+ ETyApp (ETyCon (ETCon "Maybe")) t ->
535+ parens ("Json.Decode.maybe " <> parens (renderDecoderName t))
536+ ETyCon (ETCon "Int") -> "Json.Decode.int"
537+ ETyCon (ETCon "String") -> "Json.Decode.string"
534538 _ -> ("jsonDec" <> stext (T.pack (renderElm elmTypeExpr)))
535539
536540
test/CompileSpec.hs+2−2
@@ -70,7 +70,7 @@ spec = do
7070 -- ]
7171 -- (Proxy :: Proxy TestApi)
7272 -- -- Useful for locally checking out sources in your tmp dir
73− -- callCommand "cp -r . /home/kb/tmp/servelmtest"
73+ callCommand "cp -r . /home/kb/tmp/servelmtest"
7474 runProcess_ "elm make Generated/BooksApi.elm --output api.js"
7575
7676
@@ -101,7 +101,7 @@ createCache = do
101101 "direct": {
102102 "elm/core": "1.0.2",
103103 "elm/json": "1.1.3",
104− "elm/http": "1.0.0",
104+ "elm/http": "2.0.0",
105105 "elm/url": "1.0.0",
106106 "bartavelle/json-helpers": "2.0.2"
107107 },
test/elm-sources/elm.json+1−1
@@ -12,7 +12,7 @@
1212 "direct": {
1313 "elm/core": "1.0.2",
1414 "elm/json": "1.1.3",
15− "elm/http": "1.0.0",
15+ "elm/http": "2.0.0",
1616 "elm/url": "1.0.0",
1717 "bartavelle/json-helpers": "2.0.2"
1818 },
test/elm-sources/getBooksByIdSource.elm+6−6
@@ -8,8 +8,8 @@ type Book = Book
88jsonDecBook : Json.Decode.Decoder Book
99jsonDecBook = Debug.todo ""
1010
11−getBooksById : Int -> Http.Request Book
12−getBooksById capture_id =
11+getBooksById : Int -> (Result Http.Error (Book) -> msg) -> Cmd msg
12+getBooksById capture_id toMsg =
1313 let
1414 params =
1515 List.filterMap identity
@@ -22,7 +22,7 @@ getBooksById capture_id =
2222 , headers =
2323 []
2424 , url =
25− Url.Builder.absolute
25+ Url.Builder.crossOrigin ""
2626 [ "books"
2727 , capture_id |> String.fromInt
2828 ]
@@ -30,9 +30,9 @@ getBooksById capture_id =
3030 , body =
3131 Http.emptyBody
3232 , expect =
33− Http.expectJson <| jsonDecBook
33+ Http.expectJson toMsg jsonDecBook
3434 , timeout =
3535 Nothing
36− , withCredentials =
37− False
36+ , tracker =
37+ Nothing
3838 }
test/elm-sources/getBooksByTitleSource.elm+6−6
@@ -7,8 +7,8 @@ import Json.Decode as J
77type alias Book = {}
88jsonDecBook = J.succeed {}
99
10−getBooksByTitle : String -> Http.Request Book
11−getBooksByTitle capture_title =
10+getBooksByTitle : String -> (Result Http.Error (Book) -> msg) -> Cmd msg
11+getBooksByTitle capture_title toMsg =
1212 let
1313 params =
1414 List.filterMap identity
@@ -21,7 +21,7 @@ getBooksByTitle capture_title =
2121 , headers =
2222 []
2323 , url =
24− Url.Builder.absolute
24+ Url.Builder.crossOrigin ""
2525 [ "books"
2626 , capture_title
2727 ]
@@ -29,9 +29,9 @@ getBooksByTitle capture_title =
2929 , body =
3030 Http.emptyBody
3131 , expect =
32− Http.expectJson <| jsonDecBook
32+ Http.expectJson toMsg jsonDecBook
3333 , timeout =
3434 Nothing
35− , withCredentials =
36− False
35+ , tracker =
36+ Nothing
3737 }
test/elm-sources/getBooksSource.elm+6−6
@@ -16,8 +16,8 @@ maybeBoolToIntStr mx =
1616
1717jsonDecBook = J.succeed {}
1818
19−getBooks : Bool -> (Maybe String) -> (Maybe Int) -> String -> (List (Maybe Bool)) -> Http.Request (List Book)
20−getBooks query_published query_sort query_year query_category query_filters =
19+getBooks : Bool -> (Maybe String) -> (Maybe Int) -> String -> (List (Maybe Bool)) -> (Result Http.Error ((List Book)) -> msg) -> Cmd msg
20+getBooks query_published query_sort query_year query_category query_filters toMsg =
2121 let
2222 params =
2323 List.filterMap identity
@@ -42,16 +42,16 @@ getBooks query_published query_sort query_year query_category query_filters =
4242 , headers =
4343 []
4444 , url =
45− Url.Builder.absolute
45+ Url.Builder.crossOrigin ""
4646 [ "books"
4747 ]
4848 params
4949 , body =
5050 Http.emptyBody
5151 , expect =
52− Http.expectJson <| Json.Decode.list (jsonDecBook)
52+ Http.expectJson toMsg (Json.Decode.list (jsonDecBook))
5353 , timeout =
5454 Nothing
55− , withCredentials =
56− False
55+ , tracker =
56+ Nothing
5757 }
test/elm-sources/getNothingSource.elm+9−12
@@ -4,8 +4,8 @@ import Http
44import Url.Builder
55
66
7−getNothing : Http.Request ()
8−getNothing =
7+getNothing : (Result Http.Error (()) -> msg) -> Cmd msg
8+getNothing toMsg =
99 let
1010 params =
1111 List.filterMap identity
@@ -18,22 +18,19 @@ getNothing =
1818 , headers =
1919 []
2020 , url =
21− Url.Builder.absolute
21+ Url.Builder.crossOrigin ""
2222 [ "nothing"
2323 ]
2424 params
2525 , body =
2626 Http.emptyBody
2727 , expect =
28− Http.expectStringResponse
29− (\ rsp ->
30− if String.isEmpty rsp.body then
31− Ok ()
32− else
33− Err "Expected the response body to be empty"
34− )
28+ Http.expectString
29+ (\x -> case x of
30+ Err e -> toMsg (Err e)
31+ Ok _ -> toMsg (Ok ()))
3532 , timeout =
3633 Nothing
37− , withCredentials =
38− False
34+ , tracker =
35+ Nothing
3936 }
test/elm-sources/getOneSource.elm+6−6
@@ -5,8 +5,8 @@ import Json.Decode exposing (..)
55import Url.Builder
66
77
8−getOne : Http.Request Int
9−getOne =
8+getOne : (Result Http.Error (Int) -> msg) -> Cmd msg
9+getOne toMsg =
1010 let
1111 params =
1212 List.filterMap identity
@@ -19,16 +19,16 @@ getOne =
1919 , headers =
2020 []
2121 , url =
22− Url.Builder.absolute
22+ Url.Builder.crossOrigin ""
2323 [ "one"
2424 ]
2525 params
2626 , body =
2727 Http.emptyBody
2828 , expect =
29− Http.expectJson <| Json.Decode.int
29+ Http.expectJson toMsg Json.Decode.int
3030 , timeout =
3131 Nothing
32− , withCredentials =
33− False
32+ , tracker =
33+ Nothing
3434 }
test/elm-sources/getOneWithDynamicUrlSource.elm+5−5
@@ -5,8 +5,8 @@ import Url.Builder
55import Json.Decode exposing (..)
66
77
8−getOne : String -> Http.Request Int
9−getOne urlBase =
8+getOne : String -> (Result Http.Error (Int) -> msg) -> Cmd msg
9+getOne urlBase toMsg =
1010 let
1111 params =
1212 List.filterMap identity
@@ -26,9 +26,9 @@ getOne urlBase =
2626 , body =
2727 Http.emptyBody
2828 , expect =
29− Http.expectJson <| Json.Decode.int
29+ Http.expectJson toMsg Json.Decode.int
3030 , timeout =
3131 Nothing
32− , withCredentials =
33− False
32+ , tracker =
33+ Nothing
3434 }
test/elm-sources/getWithaheaderSource.elm+6−6
@@ -5,8 +5,8 @@ import Url.Builder
55import Json.Decode exposing (..)
66
77
8−getWithaheader : (Maybe String) -> (Maybe Int) -> String -> Int -> Http.Request String
9−getWithaheader header_myStringHeader header_MyIntHeader header_MyRequiredStringHeader header_MyRequiredIntHeader =
8+getWithaheader : (Maybe String) -> (Maybe Int) -> String -> Int -> (Result Http.Error (String) -> msg) -> Cmd msg
9+getWithaheader header_myStringHeader header_MyIntHeader header_MyRequiredStringHeader header_MyRequiredIntHeader toMsg =
1010 let
1111 params =
1212 List.filterMap identity
@@ -24,16 +24,16 @@ getWithaheader header_myStringHeader header_MyIntHeader header_MyRequiredStringH
2424 , Maybe.map (Http.header "MyRequiredIntHeader" << String.fromInt) (Just header_MyRequiredIntHeader)
2525 ]
2626 , url =
27− Url.Builder.absolute
27+ Url.Builder.crossOrigin ""
2828 [ "with-a-header"
2929 ]
3030 params
3131 , body =
3232 Http.emptyBody
3333 , expect =
34− Http.expectJson <| Json.Decode.string
34+ Http.expectJson toMsg Json.Decode.string
3535 , timeout =
3636 Nothing
37− , withCredentials =
38− False
37+ , tracker =
38+ Nothing
3939 }
test/elm-sources/getWitharesponseheaderSource.elm+6−6
@@ -5,8 +5,8 @@ import Url.Builder
55import Json.Decode exposing (..)
66
77
8−getWitharesponseheader : Http.Request String
9−getWitharesponseheader =
8+getWitharesponseheader : (Result Http.Error (String) -> msg) -> Cmd msg
9+getWitharesponseheader toMsg =
1010 let
1111 params =
1212 List.filterMap identity
@@ -19,16 +19,16 @@ getWitharesponseheader =
1919 , headers =
2020 []
2121 , url =
22− Url.Builder.absolute
22+ Url.Builder.crossOrigin ""
2323 [ "with-a-response-header"
2424 ]
2525 params
2626 , body =
2727 Http.emptyBody
2828 , expect =
29− Http.expectJson <| Json.Decode.string
29+ Http.expectJson toMsg Json.Decode.string
3030 , timeout =
3131 Nothing
32− , withCredentials =
33− False
32+ , tracker =
33+ Nothing
3434 }
test/elm-sources/postBooksSource.elm+9−12
@@ -7,8 +7,8 @@ import Json.Encode as Enc
77type alias Book = {}
88jsonEncBook = \b -> Enc.object []
99
10−postBooks : Book -> Http.Request ()
11−postBooks body =
10+postBooks : Book -> (Result Http.Error (()) -> msg) -> Cmd msg
11+postBooks body toMsg =
1212 let
1313 params =
1414 List.filterMap identity
@@ -21,22 +21,19 @@ postBooks body =
2121 , headers =
2222 []
2323 , url =
24− Url.Builder.absolute
24+ Url.Builder.crossOrigin ""
2525 [ "books"
2626 ]
2727 params
2828 , body =
2929 Http.jsonBody (jsonEncBook body)
3030 , expect =
31− Http.expectStringResponse
32− (\ rsp ->
33− if String.isEmpty rsp.body then
34− Ok ()
35− else
36− Err "Expected the response body to be empty"
37− )
31+ Http.expectString
32+ (\x -> case x of
33+ Err e -> toMsg (Err e)
34+ Ok _ -> toMsg (Ok ()))
3835 , timeout =
3936 Nothing
40− , withCredentials =
41− False
37+ , tracker =
38+ Nothing
4239 }
test/elm-sources/postTwoSource.elm+6−6
@@ -6,8 +6,8 @@ import Json.Encode
66import Url.Builder
77
88
9−postTwo : String -> Http.Request (Maybe Int)
10−postTwo body =
9+postTwo : String -> (Result Http.Error ((Maybe Int)) -> msg) -> Cmd msg
10+postTwo body toMsg =
1111 let
1212 params =
1313 List.filterMap identity
@@ -20,16 +20,16 @@ postTwo body =
2020 , headers =
2121 []
2222 , url =
23− Url.Builder.absolute
23+ Url.Builder.crossOrigin ""
2424 [ "two"
2525 ]
2626 params
2727 , body =
2828 Http.jsonBody (Json.Encode.string body)
2929 , expect =
30− Http.expectJson <| Json.Decode.maybe (Json.Decode.int)
30+ Http.expectJson toMsg (Json.Decode.maybe (Json.Decode.int))
3131 , timeout =
3232 Nothing
33− , withCredentials =
34− False
33+ , tracker =
34+ Nothing
3535 }
test/elm-sources/putNothingSource.elm+9−12
@@ -4,8 +4,8 @@ import Http
44import Url.Builder
55
66
7−putNothing : Http.Request ()
8−putNothing =
7+putNothing : (Result Http.Error (()) -> msg) -> Cmd msg
8+putNothing toMsg =
99 let
1010 params =
1111 List.filterMap identity
@@ -18,22 +18,19 @@ putNothing =
1818 , headers =
1919 []
2020 , url =
21− Url.Builder.absolute
21+ Url.Builder.crossOrigin ""
2222 [ "nothing"
2323 ]
2424 params
2525 , body =
2626 Http.emptyBody
2727 , expect =
28− Http.expectStringResponse
29− (\ rsp ->
30− if String.isEmpty rsp.body then
31− Ok ()
32− else
33− Err "Expected the response body to be empty"
34− )
28+ Http.expectString
29+ (\x -> case x of
30+ Err e -> toMsg (Err e)
31+ Ok _ -> toMsg (Ok ()))
3532 , timeout =
3633 Nothing
37− , withCredentials =
38− False
34+ , tracker =
35+ Nothing
3936 }