From c83bbe0515fee9bb5f4ae1460f0dda1b837dd0fb Mon Sep 17 00:00:00 2001 From: Hueter Date: Thu, 14 Nov 2024 23:15:52 +0900 Subject: [PATCH] fix test in TestHandlers_GetMe --- model/user.go | 14 +++++++------- router/user_test.go | 7 ++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/model/user.go b/model/user.go index f8252ca2..c75554d3 100644 --- a/model/user.go +++ b/model/user.go @@ -9,13 +9,13 @@ import ( ) type User struct { - ID uuid.UUID - Name string - DisplayName string - Admin bool - CreatedAt time.Time - UpdatedAt time.Time - DeletedAt *time.Time + ID uuid.UUID `json:"id"` + Name string `json:"name"` + DisplayName string `json:"display_name"` + Admin bool `json:"admin"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt *time.Time `json:"deleted_at"` } type UserRepository interface { diff --git a/router/user_test.go b/router/user_test.go index b5f28adb..b08047ac 100644 --- a/router/user_test.go +++ b/router/user_test.go @@ -289,7 +289,7 @@ func TestHandlers_GetMe(t *testing.T) { t.Run("Success", func(t *testing.T) { t.Parallel() ctrl := gomock.NewController(t) - accessUser := makeUser(t, false) + accessUser := makeUser(t, random.Numeric(t, 2) == 1) user := User{ ID: accessUser.ID, Name: accessUser.Name, @@ -321,6 +321,11 @@ func TestHandlers_GetMe(t *testing.T) { sess.Values[sessionUserKey] = user require.NoError(t, sess.Save(c.Request(), c.Response())) + h.Repository.MockUserRepository. + EXPECT(). + GetUserByID(c.Request().Context(), user.ID). + Return(accessUser, nil) + err = h.Handlers.GetMe(c) if assert.NoError(t, err) { assert.Equal(t, http.StatusOK, rec.Code)