Many updatesg

This commit is contained in:
Richard Feldman
2016-06-25 06:47:45 -07:00
parent c8e9a117f5
commit af196d2bba
24 changed files with 132 additions and 129 deletions

View File

@@ -1,49 +1,55 @@
module Tests (..) where
port module Main exposing (..)
import ElmTest exposing (..)
import Test exposing (..)
import Expect exposing (Expectation)
import ElmHub exposing (responseDecoder)
import Json.Decode exposing (decodeString)
import Json.Decode exposing (decodeString, Value)
import Test.Runner.Node as Runner
all : Test
all =
suite
"Decoding responses from GitHub"
[ test "they can decode empty responses"
<| let
emptyResponse =
"""{ "items": [] }"""
in
assertEqual
({- TODO: what goes here? -})
(decodeString responseDecoder emptyResponse)
, test "they can decode responses with results in them"
<| let
response =
"""{ "items": [
/* TODO: dummy JSON goes here */
] }"""
in
assertEqual
(Ok
[ { id = 5, name = "foo", stars = 42 }
, { id = 3, name = "bar", stars = 77 }
]
)
(decodeString responseDecoder response)
, test "they result in an error for invalid JSON"
<| let
response =
"""{ "pizza": [] }"""
main : Program Never
main =
describe "Decoding responses from GitHub"
[ test "they can decode empty responses"
<| \() ->
let
emptyResponse =
"""{ "items": [] }"""
in
Expect.equal (Ok [])
(decodeString responseDecoder emptyResponse)
, test "they can decode responses with results in them"
<| \() ->
let
response =
"""{ "items": [
/* TODO: dummy JSON goes here */
] }"""
in
Expect.equal
(Ok
[ { id = 5, name = "foo", stars = 42 }
, { id = 3, name = "bar", stars = 77 }
]
)
(decodeString responseDecoder response)
, test "they result in an error for invalid JSON"
<| \() ->
let
response =
"""{ "pizza": [] }"""
isErrorResult result =
-- TODO return True if the given Result is an Err of some sort,
-- and False if it is an Ok of some sort.
--
-- Result docs: http://package.elm-lang.org/packages/elm-lang/core/3.0.0/Result
False
in
assertEqual
True
(isErrorResult (decodeString responseDecoder response))
]
isErrorResult result =
-- TODO return True if the given Result is an Err of some sort,
-- and False if it is an Ok of some sort.
--
-- Result docs: http://package.elm-lang.org/packages/elm-lang/core/3.0.0/Result
False
in
Expect.true "Expected decoding an invalid response to return an Err."
(isErrorResult (decodeString responseDecoder response))
]
|> Runner.run emit
port emit : ( String, Value ) -> Cmd msg