Diffdown is a real-time collaborative Markdown editor/previewer built on the AT Protocol diffdown.com

Add DB test for AddCollaboration and GetCollaborations

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

+47
+47
internal/db/db_test.go
··· 1 + package db 2 + 3 + import ( 4 + "path/filepath" 5 + "testing" 6 + ) 7 + 8 + func openTestDB(t *testing.T) *DB { 9 + t.Helper() 10 + dir := t.TempDir() 11 + SetMigrationsDir("../../migrations") 12 + d, err := Open(filepath.Join(dir, "test.db")) 13 + if err != nil { 14 + t.Fatal(err) 15 + } 16 + if err := d.Migrate(); err != nil { 17 + t.Fatal(err) 18 + } 19 + t.Cleanup(func() { d.Close() }) 20 + return d 21 + } 22 + 23 + func TestCollaborations(t *testing.T) { 24 + d := openTestDB(t) 25 + const collabDID = "did:plc:collab" 26 + const ownerDID = "did:plc:owner" 27 + const rkey = "abc123" 28 + 29 + if err := d.AddCollaboration(collabDID, ownerDID, rkey); err != nil { 30 + t.Fatalf("AddCollaboration: %v", err) 31 + } 32 + // idempotent 33 + if err := d.AddCollaboration(collabDID, ownerDID, rkey); err != nil { 34 + t.Fatalf("AddCollaboration (dup): %v", err) 35 + } 36 + 37 + rows, err := d.GetCollaborations(collabDID) 38 + if err != nil { 39 + t.Fatalf("GetCollaborations: %v", err) 40 + } 41 + if len(rows) != 1 { 42 + t.Fatalf("want 1 row, got %d", len(rows)) 43 + } 44 + if rows[0].OwnerDID != ownerDID || rows[0].DocumentRKey != rkey { 45 + t.Errorf("unexpected row: %+v", rows[0]) 46 + } 47 + }