ultisuite-backend/internal/nextcloud/dav_path_test.go
R3D347HR4Y 556d5f416d Enhance API and configuration for contact discovery and public sharing
- 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.
2026-06-06 20:27:02 +02:00

98 lines
2.9 KiB
Go

package nextcloud
import "testing"
func TestDecodeDAVPath(t *testing.T) {
got := decodeDAVPath("/Documents/My%20File.docx")
want := "/Documents/My File.docx"
if got != want {
t.Fatalf("decodeDAVPath() = %q, want %q", got, want)
}
}
func TestClientPathFromDAVHref(t *testing.T) {
href := "/remote.php/dav/files/user%40example.com/Documents/Hello%20World/"
got := clientPathFromDAVHref(href)
want := "/Documents/Hello World"
if got != want {
t.Fatalf("clientPathFromDAVHref() = %q, want %q", got, want)
}
}
func TestFileNameFromDAVPropPrefersDisplayName(t *testing.T) {
got := fileNameFromDAVProp("My File", "/remote.php/dav/files/u/x%20y")
if got != "My File" {
t.Fatalf("got %q", got)
}
}
func TestFileNameFromDAVPropDecodesHref(t *testing.T) {
got := fileNameFromDAVProp("", "/remote.php/dav/files/u/Report%20Q1.pdf")
if got != "Report Q1.pdf" {
t.Fatalf("got %q", got)
}
}
func TestSameServerDestinationHeader(t *testing.T) {
got := SameServerDestinationHeader("/remote.php/dav/files/user/doc.pdf")
want := "/remote.php/dav/files/user/doc.pdf"
if got != want {
t.Fatalf("SameServerDestinationHeader() = %q, want %q", got, want)
}
got = SameServerDestinationHeader("remote.php/dav/files/user/doc.pdf")
if got != want {
t.Fatalf("SameServerDestinationHeader(relative) = %q, want %q", got, want)
}
}
func TestWebDAVDestinationUsesPublicURL(t *testing.T) {
c := (&Client{}).WithPublicURL("http://localhost/cloud")
got := c.webDAVDestination("/remote.php/dav/files/user/doc.pdf")
want := "http://localhost/cloud/remote.php/dav/files/user/doc.pdf"
if got != want {
t.Fatalf("webDAVDestination() = %q, want %q", got, want)
}
}
func TestWebDAVDestinationFallbackRelative(t *testing.T) {
c := &Client{}
got := c.webDAVDestination("/remote.php/dav/files/user/doc.pdf")
want := "/remote.php/dav/files/user/doc.pdf"
if got != want {
t.Fatalf("webDAVDestination() = %q, want %q", got, want)
}
}
func TestWebDAVPathEncodesSpaces(t *testing.T) {
c := &Client{}
got := c.WebDAVPath("user@example.com", "/Documents/My File")
want := "/remote.php/dav/files/user@example.com/Documents/My%20File"
if got != want {
t.Fatalf("WebDAVPath() = %q, want %q", got, want)
}
}
func TestResolvePropfindClientPathRelativeHref(t *testing.T) {
got := ResolvePropfindClientPath("/Documents", "photo.jpg", "photo.jpg")
want := "/Documents/photo.jpg"
if got != want {
t.Fatalf("ResolvePropfindClientPath() = %q, want %q", got, want)
}
}
func TestNormalizeClientFilePathStripsOCSPrefix(t *testing.T) {
got := NormalizeClientFilePath("alice", "/alice/files/Photos/vacation.jpg")
want := "/Photos/vacation.jpg"
if got != want {
t.Fatalf("NormalizeClientFilePath() = %q, want %q", got, want)
}
}
func TestEnsureClientFilePathJoinsName(t *testing.T) {
got := EnsureClientFilePath("/Documents", "report.pdf")
want := "/Documents/report.pdf"
if got != want {
t.Fatalf("EnsureClientFilePath() = %q, want %q", got, want)
}
}