feat(workspace): per-user note pinning, real-time unlock synchronization, and icon-only share button
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 56s
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 56s
This commit is contained in:
1 parent
ec79a2493e
commit
af7a9eb200
5 files changed
+183
-47
No files matched your search
@@ -164,6 +164,82 @@ func TestStoreLifecycle(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPerUserDocPinning(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
dbPath := filepath.Join(tmpDir, "pin_test.db")
|
||||
|
||||
store, err := NewStore(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("NewStore failed: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
|
||||
user1, _ := store.CreateUser("user1@example.com", "hash", "User 1", "admin")
|
||||
user2, _ := store.CreateUser("user2@example.com", "hash", "User 2", "member")
|
||||
|
||||
// user1 creates document and pins it
|
||||
doc, err := store.CreateDocument(user1.ID, "", "Doc 1", "📝", "", []domain.DocumentBlock{
|
||||
{ID: "b1", Type: "text", Content: "Hello"},
|
||||
}, []string{"test"}, true)
|
||||
if err != nil {
|
||||
t.Fatalf("CreateDocument failed: %v", err)
|
||||
}
|
||||
if !doc.IsPinned {
|
||||
t.Fatalf("expected doc to be pinned for user1")
|
||||
}
|
||||
|
||||
// Share with user2 as read-only
|
||||
_, err = store.CreateDocShare(user1.ID, doc.ID, user2.ID, "read")
|
||||
if err != nil {
|
||||
t.Fatalf("CreateDocShare failed: %v", err)
|
||||
}
|
||||
|
||||
// user2 reads document: should NOT be pinned for user2
|
||||
docForUser2, err := store.GetDocumentByID(user2.ID, doc.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("GetDocumentByID user2 failed: %v", err)
|
||||
}
|
||||
if docForUser2.IsPinned {
|
||||
t.Fatalf("expected doc to NOT be pinned for user2 initially")
|
||||
}
|
||||
|
||||
// user2 pins the shared document (even with read-only access)
|
||||
pinTrue := true
|
||||
updatedDoc2, err := store.UpdateDocument(user2.ID, doc.ID, nil, nil, nil, nil, nil, &pinTrue)
|
||||
if err != nil {
|
||||
t.Fatalf("user2 pinning read-only doc failed: %v", err)
|
||||
}
|
||||
if !updatedDoc2.IsPinned {
|
||||
t.Fatalf("expected doc to be pinned for user2")
|
||||
}
|
||||
|
||||
// Verify user1's doc is still pinned
|
||||
docForUser1, err := store.GetDocumentByID(user1.ID, doc.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("GetDocumentByID user1 failed: %v", err)
|
||||
}
|
||||
if !docForUser1.IsPinned {
|
||||
t.Fatalf("expected doc to still be pinned for user1")
|
||||
}
|
||||
|
||||
// user1 unpins the doc
|
||||
pinFalse := false
|
||||
_, err = store.UpdateDocument(user1.ID, doc.ID, nil, nil, nil, nil, nil, &pinFalse)
|
||||
if err != nil {
|
||||
t.Fatalf("user1 unpinning doc failed: %v", err)
|
||||
}
|
||||
|
||||
// user1 doc is now unpinned, but user2 doc must STILL be pinned!
|
||||
docForUser1, _ = store.GetDocumentByID(user1.ID, doc.ID)
|
||||
if docForUser1.IsPinned {
|
||||
t.Fatalf("expected doc to be unpinned for user1")
|
||||
}
|
||||
docForUser2, _ = store.GetDocumentByID(user2.ID, doc.ID)
|
||||
if !docForUser2.IsPinned {
|
||||
t.Fatalf("expected doc to remain pinned for user2")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnsureDemoAccountsAndLoginLookup(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
dbPath := filepath.Join(tmpDir, "demo_test.db")
|
||||
|
||||
Reference in new issue
Block a user