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