@@ -3,6 +3,7 @@ package main
33import (
44 "strings"
55 "testing"
6+ "time"
67)
78
89func TestStoreAddIssue (t * testing.T ) {
@@ -198,3 +199,58 @@ func TestStoreResolveIssueID_EmptyPrefix(t *testing.T) {
198199 t .Errorf ("expected 'abc123', got '%s'" , id )
199200 }
200201}
202+
203+ func TestStoreAddIssue_Timestamps (t * testing.T ) {
204+ store := NewStore ()
205+
206+ before := time .Now ()
207+ issue , err := store .AddIssue ("Test issue" )
208+ after := time .Now ()
209+
210+ if err != nil {
211+ t .Fatalf ("AddIssue() failed: %v" , err )
212+ }
213+
214+ // CreatedAt should be set
215+ if issue .CreatedAt .IsZero () {
216+ t .Error ("CreatedAt should not be zero" )
217+ }
218+
219+ // UpdatedAt should be set
220+ if issue .UpdatedAt .IsZero () {
221+ t .Error ("UpdatedAt should not be zero" )
222+ }
223+
224+ // Both should equal on creation
225+ if ! issue .CreatedAt .Equal (issue .UpdatedAt ) {
226+ t .Errorf ("CreatedAt and UpdatedAt should be equal on creation, got CreatedAt=%v, UpdatedAt=%v" ,
227+ issue .CreatedAt , issue .UpdatedAt )
228+ }
229+
230+ // Timestamps should be within test execution window
231+ if issue .CreatedAt .Before (before ) || issue .CreatedAt .After (after ) {
232+ t .Errorf ("CreatedAt should be between %v and %v, got %v" , before , after , issue .CreatedAt )
233+ }
234+ }
235+
236+ func TestStoreUpdateIssueTitle_UpdatesTimestamp (t * testing.T ) {
237+ store := NewStore ()
238+ issue , _ := store .AddIssue ("Original" )
239+
240+ originalCreated := issue .CreatedAt
241+ originalUpdated := issue .UpdatedAt
242+ time .Sleep (10 * time .Millisecond ) // Ensure timestamp differs
243+
244+ err := store .UpdateIssueTitle (issue .ID , "New title" )
245+ if err != nil {
246+ t .Fatalf ("UpdateIssueTitle() failed: %v" , err )
247+ }
248+
249+ if ! issue .UpdatedAt .After (originalUpdated ) {
250+ t .Errorf ("UpdatedAt should be after original, got original=%v, new=%v" , originalUpdated , issue .UpdatedAt )
251+ }
252+
253+ if ! issue .CreatedAt .Equal (originalCreated ) {
254+ t .Error ("CreatedAt should not change on update" )
255+ }
256+ }
0 commit comments