- Introduced new endpoints for contact discovery, including scanning, listing, and managing discovered contacts. - Implemented retry logic for handling missing DAV credentials during contact operations. - Added public share functionality for drive API, allowing users to manage public shares, including upload, delete, and rename operations. - Updated Nextcloud configuration to support public share links and improved error handling for public share permissions. - Enhanced logging and validation across contact and drive APIs for better error tracking and user feedback. - Added tests for new contact matching and ranking functionalities to ensure accuracy and reliability.
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package nextcloud
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestDecodeOCSShareRecordsArray(t *testing.T) {
|
|
raw := `[{"id":"6","share_type":3,"permissions":17,"path":"/docs","share_with":null,"stime":1780572446}]`
|
|
items, err := decodeOCSShareRecords([]byte(raw))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(items) != 1 {
|
|
t.Fatalf("len = %d, want 1", len(items))
|
|
}
|
|
if items[0].ID.String() != "6" {
|
|
t.Fatalf("id = %q", items[0].ID)
|
|
}
|
|
}
|
|
|
|
func TestDecodeOCSShareRecordsSingleObject(t *testing.T) {
|
|
raw := `{"id":12,"share_type":0,"permissions":1,"path":"/file.txt","share_with":"admin"}`
|
|
items, err := decodeOCSShareRecords([]byte(raw))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(items) != 1 || items[0].ID.String() != "12" {
|
|
t.Fatalf("unexpected items: %+v", items)
|
|
}
|
|
if items[0].ShareWith == nil || *items[0].ShareWith != "admin" {
|
|
t.Fatalf("share_with = %v", items[0].ShareWith)
|
|
}
|
|
}
|
|
|
|
func TestMapOCSShareRecordOwnerAndCreatedAt(t *testing.T) {
|
|
with := "user@example.com"
|
|
item := ocsShareRecord{
|
|
ID: "3",
|
|
ShareType: 3,
|
|
Permissions: 1,
|
|
URL: "http://localhost/s/abc",
|
|
ShareWith: &with,
|
|
DisplayNameOwner: "Alice",
|
|
DisplayNameFileOwner: "Alice",
|
|
Stime: 1780572446,
|
|
Label: "internal",
|
|
ItemType: "file",
|
|
}
|
|
info := mapOCSShareRecord(item, "/file.txt")
|
|
if info.AccessMode != "internal" {
|
|
t.Fatalf("access_mode = %q", info.AccessMode)
|
|
}
|
|
if info.OwnerDisplayName != "Alice" {
|
|
t.Fatalf("owner = %q", info.OwnerDisplayName)
|
|
}
|
|
if !strings.Contains(info.CreatedAt, "2026") {
|
|
t.Fatalf("created_at = %q", info.CreatedAt)
|
|
}
|
|
}
|