Skip to content

Commit

Permalink
fix: check contest timeEnd nil
Browse files Browse the repository at this point in the history
  • Loading branch information
Tennessine699 committed Dec 14, 2024
1 parent 3a12ce0 commit 0c1df6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/infrastructure/repository/contest_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (r *ContestRepository) UpdateContest(ctx context.Context, contestID uuid.UU
if v, ok := args.Since.V(); ok {
changes["since"] = v
}
if v, ok := args.Until.V(); ok == untilEmpty || v != origin.Until {
if v, ok := args.Until.V(); ok == untilEmpty || !v.Equal(origin.Until) {
changes["until"] = v
}

Expand Down
9 changes: 7 additions & 2 deletions internal/infrastructure/repository/contest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func Test_UpdateContest(t *testing.T) {

t.Run("update no fields", func(t *testing.T) {
args := &repository.UpdateContestArgs{}
args.Until = optional.New(contest.TimeEnd, contest.TimeEnd == time.Time{})
args.Until = optional.New(contest.TimeEnd, contest.TimeEnd.Equal(time.Time{}))
err := repo.UpdateContest(context.Background(), contest.ID, args)
assert.NoError(t, err)

Expand All @@ -136,14 +136,19 @@ func Test_UpdateContest(t *testing.T) {

t.Run("update until to nil", func(t *testing.T) {
argWithUntil := random.CreateContestArgs()
argWithUntil.Until = random.UpdateContestArgs().Since
// CreateContestArgsのUntilは5割で"未定"なのでsinceの1時間後を代入する
argWithUntil.Until = optional.From(argWithUntil.Since.Add(time.Hour))
contest, err := repo.CreateContest(context.Background(), argWithUntil)
assert.NoError(t, err)

argWithoutUntil := random.UpdateContestArgs()
argWithoutUntil.Until = optional.Of[time.Time]{}
err = repo.UpdateContest(context.Background(), contest.ID, argWithoutUntil)
assert.NoError(t, err)

contest, err = repo.GetContest(context.Background(), contest.ID)
assert.NoError(t, err)
assert.Equal(t, contest.TimeEnd, time.Time{})
})

t.Run("update failed: not contest id", func(t *testing.T) {
Expand Down

0 comments on commit 0c1df6d

Please sign in to comment.