refactoring createdat to last update ... it will make sense
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
type Note struct {
|
||||
ID int `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Content string `json:"content"`
|
||||
ID int `json:"id"`
|
||||
LastUpdate time.Time `json:"last_update"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ func TestCreateNote(t *testing.T) {
|
||||
name: "Good note",
|
||||
content: "This is a good note with valid content.",
|
||||
expectedNote: models.Note{
|
||||
ID: 1,
|
||||
CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), //CreatedAt is set by synctest to this specific time
|
||||
Content: "This is a good note with valid content.",
|
||||
ID: 1,
|
||||
LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), //LastUpdate is set by synctest to this specific time
|
||||
Content: "This is a good note with valid content.",
|
||||
},
|
||||
expectedError: false,
|
||||
},
|
||||
@@ -38,9 +38,9 @@ func TestCreateNote(t *testing.T) {
|
||||
name: "Long content",
|
||||
content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
||||
expectedNote: models.Note{
|
||||
ID: 2,
|
||||
CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
Content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
||||
ID: 2,
|
||||
LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
Content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
||||
},
|
||||
expectedError: false,
|
||||
},
|
||||
@@ -65,8 +65,8 @@ func TestCreateNote(t *testing.T) {
|
||||
if note.ID != tc.expectedNote.ID {
|
||||
t.Errorf("expected ID %d but got %d", tc.expectedNote.ID, note.ID)
|
||||
}
|
||||
if !note.CreatedAt.Equal(tc.expectedNote.CreatedAt) {
|
||||
t.Errorf("expected CreatedAt %v but got %v", tc.expectedNote.CreatedAt, note.CreatedAt)
|
||||
if !note.LastUpdate.Equal(tc.expectedNote.LastUpdate) {
|
||||
t.Errorf("expected LastUpdate %v but got %v", tc.expectedNote.LastUpdate, note.LastUpdate)
|
||||
}
|
||||
fmt.Printf("Test case '%s' passed.\n", tc.name)
|
||||
})
|
||||
@@ -75,11 +75,11 @@ func TestCreateNote(t *testing.T) {
|
||||
|
||||
func TestGetNotes(t *testing.T) {
|
||||
notes := []models.Note{
|
||||
{ID: 1, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "First note"},
|
||||
{ID: 2, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Second note"},
|
||||
{ID: 3, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Third note"},
|
||||
{ID: 1, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "First note"},
|
||||
{ID: 2, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Second note"},
|
||||
{ID: 3, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Third note"},
|
||||
// 4th note was clearly deleted, :sadface:
|
||||
{ID: 5, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Lorem ipsum note dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."},
|
||||
{ID: 5, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Lorem ipsum note dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."},
|
||||
}
|
||||
store := &mockNoteStore{Notes: notes}
|
||||
repo := repository.NewNoteRepository(store)
|
||||
@@ -155,14 +155,14 @@ func TestListNotes(t *testing.T) {
|
||||
{
|
||||
name: "Multiple notes",
|
||||
notes: []models.Note{
|
||||
{ID: 1, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "First note"},
|
||||
{ID: 2, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Second note"},
|
||||
{ID: 3, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Third note"},
|
||||
{ID: 1, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "First note"},
|
||||
{ID: 2, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Second note"},
|
||||
{ID: 3, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Third note"},
|
||||
},
|
||||
expectedNotes: []models.Note{
|
||||
{ID: 1, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "First note"},
|
||||
{ID: 2, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Second note"},
|
||||
{ID: 3, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Third note"},
|
||||
{ID: 1, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "First note"},
|
||||
{ID: 2, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Second note"},
|
||||
{ID: 3, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Third note"},
|
||||
},
|
||||
expectedError: false,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user