package store import ( "context" "testing" "time" "git.avsdev.uk/Go/job-search/internal/types" ) // A batch recorded after the clock went back is still created after the // newest batch, so asking for the batches after that one finds it. func TestChangeBatchAfterClockWentBack(t *testing.T) { db := openTestDB(t) s := &Store{db: db} ctx := context.Background() _, err := s.SaveOpportunity( ctx, &types.Opportunity{ UUID: "ocds-1", LatestReleaseDate: time.Now(), }, ) if err != nil { t.Fatal(err) } future := time.Now().UTC().Add(time.Hour) db.MustExec(insertChangeBatch, "future", future) err = s.SetMarks(ctx, types.OpportunityMarks{ UUID: "ocds-1", Won: true, }) if err != nil { t.Fatal(err) } var latest changeBatch if err := db.Get(&latest, selectLatestChangeBatch); err != nil { t.Fatal(err) } if !latest.CreatedAt.After(future) { t.Errorf("batch created at %v, not after %v", latest.CreatedAt, future) } got, hash, err := s.ListChangedOpportunities(ctx, "future") if err != nil { t.Fatal(err) } if len(got) != 1 || got[0].UUID != "ocds-1" || hash != latest.Hash { t.Errorf("changed after future: %v, %q", got, hash) } }