From 17f536008431e80a960ec39f68844e2d7bc39853 Mon Sep 17 00:00:00 2001 From: Hueter Date: Fri, 15 Nov 2024 01:49:54 +0900 Subject: [PATCH] change 'expect return' model.User to User --- model/user.go | 14 +++++++------- router/user_test.go | 27 ++++++++++++++++++++------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/model/user.go b/model/user.go index c75554d3..f8252ca2 100644 --- a/model/user.go +++ b/model/user.go @@ -9,13 +9,13 @@ import ( ) type User struct { - 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"` + ID uuid.UUID + Name string + DisplayName string + Admin bool + CreatedAt time.Time + UpdatedAt time.Time + DeletedAt *time.Time } type UserRepository interface { diff --git a/router/user_test.go b/router/user_test.go index b08047ac..2d216cd6 100644 --- a/router/user_test.go +++ b/router/user_test.go @@ -22,6 +22,18 @@ import ( "github.com/traPtitech/Jomon/testutil/random" ) +func userFromModelUser(u model.User) User { + return User{ + ID: u.ID, + Name: u.Name, + DisplayName: u.DisplayName, + Admin: u.Admin, + CreatedAt: u.CreatedAt, + UpdatedAt: u.UpdatedAt, + DeletedAt: u.DeletedAt, + } +} + func TestHandlers_GetUsers(t *testing.T) { t.Parallel() @@ -289,14 +301,14 @@ func TestHandlers_GetMe(t *testing.T) { t.Run("Success", func(t *testing.T) { t.Parallel() ctrl := gomock.NewController(t) - accessUser := makeUser(t, random.Numeric(t, 2) == 1) + accessModelUser := makeUser(t, random.Numeric(t, 2) == 1) user := User{ - ID: accessUser.ID, - Name: accessUser.Name, - DisplayName: accessUser.DisplayName, - Admin: accessUser.Admin, - CreatedAt: accessUser.CreatedAt, - UpdatedAt: accessUser.UpdatedAt, + ID: accessModelUser.ID, + Name: accessModelUser.Name, + DisplayName: accessModelUser.DisplayName, + Admin: accessModelUser.Admin, + CreatedAt: accessModelUser.CreatedAt, + UpdatedAt: accessModelUser.UpdatedAt, } bodyAccessUser, err := json.Marshal(user) assert.NoError(t, err) @@ -320,6 +332,7 @@ func TestHandlers_GetMe(t *testing.T) { require.NoError(t, err) sess.Values[sessionUserKey] = user require.NoError(t, sess.Save(c.Request(), c.Response())) + accessUser := userFromModelUser(*accessModelUser) h.Repository.MockUserRepository. EXPECT().