package main import "testing" func TestBuildMountTreeGroupsByFolderAndDate(t *testing.T) { items := []SearchItem{{ ID: "item-1", Name: "Invoice/July", Date: 1720396800000, Folder: &DocspellEntity{ Name: "Bills/Private", }, Attachments: []ItemAttachment{{ID: "att-1", Name: "invoice.pdf", Size: 123}}, }} root := buildMountTree(&DocspellClient{}, items) folder, ok := root.children["Bills_Private"].(*dirNode) if !ok { t.Fatalf("expected sanitized folder directory, got %#v", root.children) } year, ok := folder.children["2024"].(*dirNode) if !ok { t.Fatalf("expected year directory, got %#v", folder.children) } month, ok := year.children["07"].(*dirNode) if !ok { t.Fatalf("expected month directory, got %#v", year.children) } if _, ok := month.children["invoice.pdf"].(*fileNode); !ok { t.Fatalf("expected attachment file, got %#v", month.children) } } func TestBuildMountTreeDeduplicatesAttachmentNames(t *testing.T) { items := []SearchItem{{ ID: "item-1", Name: "Invoice", Attachments: []ItemAttachment{ {ID: "att-1", Name: "same.pdf"}, {ID: "att-2", Name: "same.pdf"}, }, }} root := buildMountTree(&DocspellClient{}, items) folder := root.children["No Folder"].(*dirNode) date := folder.children["No Date"].(*dirNode) if _, ok := date.children["Invoice - 01 - same.pdf"]; !ok { t.Fatalf("expected first unique name, got %#v", date.children) } if _, ok := date.children["Invoice - 02 - same.pdf"]; !ok { t.Fatalf("expected second unique name, got %#v", date.children) } }