Skip to content

Commit 8bfb13c

Browse files
committed
WIP test for checking email confirmation code
1 parent 241fdd4 commit 8bfb13c

3 files changed

Lines changed: 27 additions & 9 deletions

File tree

src/Route/Session.gren

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ confirmEmail :
6767
}
6868
-> Task Never Response
6969
confirmEmail { db, requestData, response } =
70-
Task.succeed response
71-
--Route.Error.invalidRequestData response "Invalid token"
70+
--Task.succeed response
71+
Route.Error.invalidRequestData response "Invalid token"
7272

7373

7474
-- ACTIONS

src/Test/E2E/Helper.gren

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Test.E2E.Helper exposing
22
( createSession
33
, expectBadStatus
44
, expectJson
5+
, expectStringContains
56
, initDb
67
, get
78
, post
@@ -40,11 +41,11 @@ url path =
4041

4142

4243

43-
get : HttpClient.Permission -> String -> Task HttpClient.Error (HttpClient.Response {})
44+
get : HttpClient.Permission -> String -> Task HttpClient.Error (HttpClient.Response String)
4445
get httpPerm path =
4546
url path
4647
|> HttpClient.get
47-
|> HttpClient.expectAnything
48+
|> HttpClient.expectString
4849
|> HttpClient.send httpPerm
4950

5051

@@ -109,3 +110,15 @@ createSession { db, secureContext } =
109110
, user = user
110111
}
111112
)
113+
114+
115+
-- STRINGS
116+
117+
expectStringContains : String -> String -> Expectation
118+
expectStringContains expected actual =
119+
if String.contains expected actual then
120+
Expect.pass
121+
else
122+
"Expected \"" ++ actual ++ "\" to contain \"" ++ expected ++ "\""
123+
|> Expect.fail
124+

src/Test/E2E/Route/Session.gren

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,27 @@ tests httpPerm secureContext =
100100
}
101101

102102
httpGet token =
103-
Route.Session.confirmEmailPath { token = Just token }
103+
Route.Session.confirmEmailPath { token = token }
104104
|> Helper.get httpPerm
105105

106106
in
107-
[ awaitError "GET with bad token" (httpGet "bad token") <| \responseError ->
108-
test "is auth error" <| \_ ->
107+
[ awaitError "GET with missing token" (httpGet Nothing) <| \responseError ->
108+
test "is client error" <| \_ ->
109+
expectBadStatus 400 responseError
110+
111+
, awaitError "GET with bad token" (httpGet (Just "bad token")) <| \responseError ->
112+
test "is client error" <| \_ ->
109113
expectBadStatus 400 responseError
110114

111115
, await "create test session" createTestSession <| \session ->
112-
await "GET with good token" (httpGet session.emailConfirmationToken) <|
116+
await "GET with good token" (httpGet (Just session.emailConfirmationToken)) <|
113117
\response ->
114118
concat
115119
[ test "is success" <| \_ ->
116120
Expect.equal 200 response.statusCode
117121
, test "responds with confirmation code" <| \_ ->
118-
Expect.fail "TODO: check response for confirmation code"
122+
response.data
123+
|> Helper.expectStringContains "TODO: real code"
119124
]
120125
]
121126
]

0 commit comments

Comments
 (0)