53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestListInboxNodesReturnsOnlyUnassignedRoots(t *testing.T) {
|
|
app, _ := setupTestApp(t)
|
|
|
|
unassigned, err := app.CreateNodeFromTemplate("", "Unassigned Root", "folder.default")
|
|
if err != nil {
|
|
t.Fatalf("create unassigned root: %v", err)
|
|
}
|
|
inbox, err := app.CreateNodeFromTemplate("", "Inbox Root", "folder.default")
|
|
if err != nil {
|
|
t.Fatalf("create inbox root: %v", err)
|
|
}
|
|
assigned, err := app.CreateNodeFromTemplate("", "Assigned Root", "folder.default")
|
|
if err != nil {
|
|
t.Fatalf("create assigned root: %v", err)
|
|
}
|
|
child, err := app.CreateNodeFromTemplate(unassigned.ID, "Nested Child", "folder.default")
|
|
if err != nil {
|
|
t.Fatalf("create child: %v", err)
|
|
}
|
|
if _, err := app.db.Exec(`UPDATE nodes SET section = 'inbox' WHERE id = ?`, inbox.ID); err != nil {
|
|
t.Fatalf("mark inbox: %v", err)
|
|
}
|
|
if _, err := app.db.Exec(`UPDATE nodes SET section = 'projects' WHERE id = ?`, assigned.ID); err != nil {
|
|
t.Fatalf("mark assigned: %v", err)
|
|
}
|
|
|
|
list, err := app.ListInboxNodes()
|
|
if err != nil {
|
|
t.Fatalf("ListInboxNodes: %v", err)
|
|
}
|
|
|
|
got := map[string]bool{}
|
|
for _, item := range list {
|
|
got[item.ID] = true
|
|
}
|
|
if !got[unassigned.ID] {
|
|
t.Fatal("unassigned root missing from inbox")
|
|
}
|
|
if !got[inbox.ID] {
|
|
t.Fatal("section=inbox root missing from inbox")
|
|
}
|
|
if got[assigned.ID] {
|
|
t.Fatal("assigned root should not be in inbox")
|
|
}
|
|
if got[child.ID] {
|
|
t.Fatal("nested child should not be in inbox")
|
|
}
|
|
}
|