Add tests

This commit is contained in:
Correl Roush 2018-01-17 17:22:39 -05:00
parent d3c60f8620
commit 5ef8751d51
5 changed files with 77 additions and 8 deletions

View file

@ -7,6 +7,7 @@ ELM_FILES = $(shell find . -type f -name '*.elm')
NODE_BIN = ./node_modules/.bin NODE_BIN = ./node_modules/.bin
ELM-MAKE = $(NODE_BIN)/elm-make ELM-MAKE = $(NODE_BIN)/elm-make
ELM-REACTOR = $(NODE_BIN)/elm-reactor ELM-REACTOR = $(NODE_BIN)/elm-reactor
ELM-TEST = $(NODE_BIN)/elm-test
ELMMAKE_FLAGS = --yes ELMMAKE_FLAGS = --yes
ifeq ($(DEBUG),1) ifeq ($(DEBUG),1)
@ -31,3 +32,6 @@ clean:
run: all run: all
$(ELM-REACTOR) $(ELM-REACTOR)
test:
$(ELM-TEST)

View file

@ -2,6 +2,7 @@
"name": "elm-pass", "name": "elm-pass",
"version": "1.0.0", "version": "1.0.0",
"dependencies": { "dependencies": {
"elm": "0.18" "elm": "0.18",
"elm-test": "0.18.12"
} }
} }

View file

@ -44,16 +44,11 @@ request : String -> Path -> Decoder a -> Client -> Http.Request a
request method path decoder client = request method path decoder client =
let let
url = url =
String.join "/" <| apiUrl client path
client.url
:: "api/v4"
:: path
in in
Http.request Http.request
{ method = method { method = method
, headers = , headers = apiHeaders client
Maybe.Extra.values
[ Maybe.map (Http.header "Private-Token") client.token ]
, url = url , url = url
, body = Http.emptyBody , body = Http.emptyBody
, expect = Http.expectJson decoder , expect = Http.expectJson decoder
@ -62,6 +57,20 @@ request method path decoder client =
} }
apiUrl : Client -> Path -> String
apiUrl client path =
String.join "/" <|
client.url
:: "api/v4"
:: path
apiHeaders : Client -> List Http.Header
apiHeaders client =
Maybe.Extra.values
[ Maybe.map (Http.header "Private-Token") client.token ]
get : Path -> Decoder a -> Client -> Http.Request a get : Path -> Decoder a -> Client -> Http.Request a
get = get =
request "GET" request "GET"

33
tests/GitlabTests.elm Normal file
View file

@ -0,0 +1,33 @@
module GitlabTests exposing (..)
import Expect
import Http
import Gitlab
import Test exposing (..)
suite : Test
suite =
let
clientWithoutToken =
Gitlab.Client "http://example.org" Nothing
clientWithToken =
Gitlab.Client "http://example.org" (Just "token")
in
describe "Gitlab"
[ test "Builds v4 API url" <|
\() ->
Expect.equal "http://example.org/api/v4/foo/bar" <|
Gitlab.apiUrl clientWithToken [ "foo", "bar" ]
, test "Includes private token in headers when available" <|
\() ->
Expect.true "Expected token header." <|
List.member (Http.header "Private-Token" "token") <|
Gitlab.apiHeaders clientWithToken
, test "Omits private token in headers when not available" <|
\() ->
Expect.false "Did not expect token header." <|
List.member (Http.header "Private-Token" "token") <|
Gitlab.apiHeaders clientWithoutToken
]

22
tests/elm-package.json Normal file
View file

@ -0,0 +1,22 @@
{
"version": "1.0.0",
"summary": "Test Suites",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"../src",
"."
],
"exposed-modules": [],
"dependencies": {
"NoRedInk/elm-decode-pipeline": "3.0.0 <= v < 4.0.0",
"eeue56/elm-html-test": "5.1.2 <= v < 6.0.0",
"elm-community/elm-test": "4.0.0 <= v < 5.0.0",
"elm-community/maybe-extra": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "5.1.1 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0",
"elm-lang/http": "1.0.0 <= v < 2.0.0",
"krisajenkins/remotedata": "4.3.3 <= v < 5.0.0"
},
"elm-version": "0.18.0 <= v < 0.19.0"
}