|
|
|
@ -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) {
|
|
|
|
|