Skip to content

Commit

Permalink
test: expected cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
tomanagle committed Mar 30, 2024
1 parent e6b3ad0 commit 50efaa8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/handlers/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestLogin(t *testing.T) {
comparePasswordAndHashResult bool
getUserError error
createSessionResult *store.Session
expectedCookie *http.Cookie
}{
{
name: "success",
Expand All @@ -36,6 +37,11 @@ func TestLogin(t *testing.T) {
getUserResult: user,
createSessionResult: &store.Session{UserID: 1, SessionID: "sessionId"},
expectedStatusCode: http.StatusOK,
expectedCookie: &http.Cookie{
Name: "session",
Value: "sessionId",
HttpOnly: true,
},
},
{
name: "fail - user not found",
Expand Down Expand Up @@ -87,6 +93,18 @@ func TestLogin(t *testing.T) {

assert.Equal(tc.expectedStatusCode, rr.Code)

cookies := rr.Result().Cookies()
if tc.expectedCookie != nil {

sessionCookie := cookies[0]

assert.Equal(tc.expectedCookie.Name, sessionCookie.Name)
assert.Equal(tc.expectedCookie.Value, sessionCookie.Value)
assert.Equal(tc.expectedCookie.HttpOnly, sessionCookie.HttpOnly)
} else {
assert.Empty(cookies)
}

userStore.AssertExpectations(t)
passwordHash.AssertExpectations(t)
sessionStore.AssertExpectations(t)
Expand Down

0 comments on commit 50efaa8

Please sign in to comment.