From 0c1df6d9857c329d34413c0c6ed2c6719f25979a Mon Sep 17 00:00:00 2001 From: Tennessine699 Date: Sat, 14 Dec 2024 22:36:07 +0900 Subject: [PATCH] fix: check contest timeEnd nil --- internal/infrastructure/repository/contest_impl.go | 2 +- internal/infrastructure/repository/contest_test.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/infrastructure/repository/contest_impl.go b/internal/infrastructure/repository/contest_impl.go index 82c90c34..ccff53b8 100644 --- a/internal/infrastructure/repository/contest_impl.go +++ b/internal/infrastructure/repository/contest_impl.go @@ -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 } diff --git a/internal/infrastructure/repository/contest_test.go b/internal/infrastructure/repository/contest_test.go index d1532de0..628c43f1 100644 --- a/internal/infrastructure/repository/contest_test.go +++ b/internal/infrastructure/repository/contest_test.go @@ -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) @@ -136,7 +136,8 @@ 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) @@ -144,6 +145,10 @@ func Test_UpdateContest(t *testing.T) { 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) {