You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diary/model/note_test.go

70 lines
1.6 KiB

package model
import (
"testing"
)
func TestNewEntryNote(t *testing.T) {
var app = setup()
var entry = app.NewDiaryEntry("Met with Nagee @ 1PM")
var note = app.NewDiaryEntryNote(entry.Id, "A note")
assert_string(t, "A note", note.Body)
assert_exists(t, note.Id)
assert_exists(t, note.CreatedAt)
assert_exists(t, note.Version)
teardown(app)
}
func TestGetDiaryEntryNotes(t *testing.T) {
var app = setup()
var entry = app.NewDiaryEntry("Met with Nagee @ 1PM")
var note_1 = app.NewDiaryEntryNote(entry.Id, "A note")
var note_2 = app.NewDiaryEntryNote(entry.Id, "Another note")
// The first note should be the latest one created
var notes = app.GetDiaryEntryNotes(entry.Id)
assert_string(t, notes[0].Body, note_2.Body)
assert_int(t, notes[0].Id, note_2.Id)
assert_int(t, notes[0].CreatedAt, note_2.CreatedAt)
assert_int(t, notes[0].Version, note_2.Version)
assert_string(t, notes[1].Body, note_1.Body)
assert_int(t, notes[1].Id, note_1.Id)
assert_int(t, notes[1].CreatedAt, note_1.CreatedAt)
assert_int(t, notes[1].Version, note_1.Version)
teardown(app)
}
func DeleteDiaryEntryNote(t *testing.T) {
var app = setup()
var entry = app.NewDiaryEntry("Met with Nagee @ 1PM")
var note = app.NewDiaryEntryNote(entry.Id, "A note")
is_deleted, _ := app.DeleteDiaryEntry(note.Id)
assert_bool(t, true, is_deleted)
teardown(app)
}
func DeleteDiaryEntryNoteNotFound(t *testing.T) {
var app = setup()
_, err := app.DeleteDiaryEntryNote(-1)
switch err_type := err.(type) {
case *NotFoundError:
// Do nothing
break
default:
t.Fatalf("Expected NotFoundError, got %s", err_type)
}
teardown(app)
}