| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestNamedEmptyTopicArchiveIsRecoverable(t *testing.T) { |
| 10 | isolateDesktopUserDirs(t) |
| 11 | a := NewApp() |
| 12 | a.ctx = t.Context() |
| 13 | installNoopRuntimeEvents(a) |
| 14 | t.Cleanup(a.closeSessionServices) |
| 15 | topic, err := a.CreateTopic("global", "", "Named empty conversation") |
| 16 | if err != nil { |
| 17 | t.Fatal(err) |
| 18 | } |
| 19 | if err := a.TrashTopic(topic.ID); err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | page, err := a.ListTrashEntries("", "", 50) |
| 23 | if err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | for _, item := range page.Items { |
| 27 | if item.Title == topic.Title && item.CanRestore { |
| 28 | return |
| 29 | } |
| 30 | } |
| 31 | t.Fatalf("successful move to trash has no restorable entry: items=%+v, title=%q", page.Items, loadTopicTitle("", topic.ID)) |
| 32 | } |
| 33 | |
| 34 | func TestEmptyTopicArchiveDoesNotReportSuccessWhileStillVisible(t *testing.T) { |
| 35 | isolateDesktopUserDirs(t) |
| 36 | a := NewApp() |
| 37 | a.ctx = t.Context() |
| 38 | installNoopRuntimeEvents(a) |
| 39 | t.Cleanup(a.closeSessionServices) |
| 40 | topic, err := a.CreateTopic("global", "", "Cannot remove metadata") |
| 41 | if err != nil { |
| 42 | t.Fatal(err) |
| 43 | } |
| 44 | path := filepath.Join(desktopConfigDir(), desktopProjectsFile) |
| 45 | if err := os.Rename(path, path+".saved"); err != nil { |
| 46 | t.Fatal(err) |
| 47 | } |
| 48 | if err := os.Mkdir(path, 0700); err != nil { |
| 49 | t.Fatal(err) |
| 50 | } |
| 51 | err = a.TrashTopic(topic.ID) |
| 52 | if err != nil { |
| 53 | return |
| 54 | } |
| 55 | page, err := a.ListProjectTopics(ProjectTopicPageRequest{Scope: "global", Limit: 50}) |
| 56 | if err != nil { |
| 57 | t.Fatal(err) |
| 58 | } |
| 59 | for _, row := range page.Items { |
| 60 | if row.TopicID == topic.ID { |
| 61 | t.Fatalf("archive returned success but topic remains visible: %+v", row) |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 |