49 lines
836 B
Go
49 lines
836 B
Go
package service
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"donniemarko/internal/note"
|
|
"donniemarko/internal/storage"
|
|
)
|
|
|
|
var service *NotesService
|
|
|
|
func TestMain(m *testing.M) {
|
|
storage := storage.NewNoteStorage()
|
|
|
|
notes := []*note.Note{
|
|
{ID: "test1", Title: "Golang Tutorial", Content: "Learn Go"},
|
|
{ID: "test2", Title: "Rust Guide", Content: "Learn Rust"},
|
|
}
|
|
for _, note := range notes {
|
|
storage.Create(note)
|
|
}
|
|
|
|
service = NewNoteService()
|
|
service.SetStorage(storage)
|
|
m.Run()
|
|
}
|
|
|
|
func TestQueryNotes_WithSearch(t *testing.T) {
|
|
|
|
opts := QueryOptions{
|
|
SearchTerm: "Go",
|
|
SortBy: "alpha",
|
|
}
|
|
|
|
results, err := service.QueryNotes(opts)
|
|
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if len(results) != 1 {
|
|
t.Errorf("expected 1 result, got %d", len(results))
|
|
}
|
|
|
|
if results[0].Title != "Golang Tutorial" {
|
|
t.Error("wrong note returned")
|
|
}
|
|
}
|