Skip to content

Commit

Permalink
change 'expect return' model.User to User
Browse files Browse the repository at this point in the history
  • Loading branch information
Hueter57 committed Nov 14, 2024
1 parent c83bbe0 commit 17f5360
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
14 changes: 7 additions & 7 deletions model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 20 additions & 7 deletions router/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand All @@ -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().
Expand Down

0 comments on commit 17f5360

Please sign in to comment.