diff --git a/internal/board/board.go b/internal/board/board.go index bdc5345..686447c 100644 --- a/internal/board/board.go +++ b/internal/board/board.go @@ -5,6 +5,7 @@ import ( "encoding/gob" "fmt" "sort" + "time" "codeflow.dananglin.me.uk/apollo/pelican/internal/db" bolt "go.etcd.io/bbolt" @@ -205,6 +206,8 @@ type CardArgs struct { // CreateCard creates a card in the database. func (b *Board) CreateCard(args CardArgs) (int, error) { + timestamp := time.Now().Format(time.DateOnly) + statusList, err := b.StatusList() if err != nil { return 0, fmt.Errorf("unable to read the status list, %w", err) @@ -218,6 +221,7 @@ func (b *Board) CreateCard(args CardArgs) (int, error) { ID: -1, Title: args.NewTitle, Content: args.NewContent, + Created: timestamp, } cardID, err := db.Write(b.db, db.CardBucket, &card) diff --git a/internal/board/card.go b/internal/board/card.go index 153941d..9ea2c50 100644 --- a/internal/board/card.go +++ b/internal/board/card.go @@ -15,6 +15,7 @@ type Card struct { ID int Title string Content string + Created string } // UpdateId updates the ID of the Card value. diff --git a/internal/board/card_lifecycle_test.go b/internal/board/card_lifecycle_test.go index 978b6b4..8641916 100644 --- a/internal/board/card_lifecycle_test.go +++ b/internal/board/card_lifecycle_test.go @@ -6,6 +6,7 @@ import ( "path/filepath" "reflect" "testing" + "time" "codeflow.dananglin.me.uk/apollo/pelican/internal/board" ) @@ -34,19 +35,20 @@ func TestCardLifecycle(t *testing.T) { initialCardContent := "Ensure that this card is safely stored in the database." expectedCardID := 1 expectedStatusID := 1 + timestamp := time.Now().Format(time.DateOnly) t.Run("Test Create Card", testCreateCard(kanban, initialCardTitle, initialCardContent, expectedCardID, expectedStatusID)) - t.Run("Test Read Card", testReadCard(kanban, expectedCardID, initialCardTitle, initialCardContent)) + t.Run("Test Read Card", testReadCard(kanban, expectedCardID, initialCardTitle, initialCardContent, timestamp)) modifiedCardTitle := "Test card updated." modifiedCardContent1 := "Ensure that this card is safely updated in the database." - t.Run("Test Update Card", testUpdateCard(kanban, expectedCardID, modifiedCardTitle, modifiedCardContent1)) + t.Run("Test Update Card", testUpdateCard(kanban, expectedCardID, modifiedCardTitle, modifiedCardContent1, timestamp)) modifiedCardContent2 := "Updated card content only." - t.Run("Test Update Card Content", testUpdateCardContent(kanban, expectedCardID, modifiedCardTitle, modifiedCardContent2)) + t.Run("Test Update Card Content", testUpdateCardContent(kanban, expectedCardID, modifiedCardTitle, modifiedCardContent2, timestamp)) t.Run("Test Card Delete", testDeleteCard(kanban, expectedCardID, expectedStatusID)) } @@ -85,7 +87,7 @@ func testCreateCard(kanban board.Board, title, content string, expectedCardID, e } } -func testReadCard(kanban board.Board, cardID int, wantTitle, wantContent string) func(t *testing.T) { +func testReadCard(kanban board.Board, cardID int, wantTitle, wantContent, wantTimestamp string) func(t *testing.T) { return func(t *testing.T) { t.Log("When a card is read from the database.") @@ -105,10 +107,16 @@ func testReadCard(kanban board.Board, cardID int, wantTitle, wantContent string) } else { t.Logf("%s\tExpected card content received, got: %s.", success, card.Content) } + + if card.Created != wantTimestamp { + t.Errorf("%s\tUnexpected timestamp received for the created card, want: %s, got %s.", failure, wantTimestamp, card.Created) + } else { + t.Logf("%s\tExpected timestamp received for the created card, got: %s.", success, card.Created) + } } } -func testUpdateCard(kanban board.Board, cardID int, newTitle, newContent string) func(t *testing.T) { +func testUpdateCard(kanban board.Board, cardID int, newTitle, newContent, timestamp string) func(t *testing.T) { return func(t *testing.T) { t.Log("When a card is updated in the database.") @@ -133,6 +141,7 @@ func testUpdateCard(kanban board.Board, cardID int, newTitle, newContent string) ID: cardID, Title: newTitle, Content: newContent, + Created: timestamp, } if !reflect.DeepEqual(got, want) { @@ -143,7 +152,7 @@ func testUpdateCard(kanban board.Board, cardID int, newTitle, newContent string) } } -func testUpdateCardContent(kanban board.Board, cardID int, expectedTitle, newContent string) func(t *testing.T) { +func testUpdateCardContent(kanban board.Board, cardID int, expectedTitle, newContent, timestamp string) func(t *testing.T) { return func(t *testing.T) { t.Log("When (and only when) a card's content is updated in the database.") @@ -168,6 +177,7 @@ func testUpdateCardContent(kanban board.Board, cardID int, expectedTitle, newCon ID: cardID, Title: expectedTitle, Content: newContent, + Created: timestamp, } if !reflect.DeepEqual(got, want) {