- Updated environment configuration to unify frontend for mail and drive under a single service. - Revised README to reflect changes in frontend setup and routing for the unified application. - Introduced new API documentation endpoints for better accessibility of API specifications. - Enhanced drive and mail services with improved handling of file uploads and metadata enrichment. - Implemented new API token management features, including creation, listing, and revocation of tokens. - Added tests for new functionalities in drive and mail services to ensure reliability and correctness.
106 lines
3.1 KiB
Go
106 lines
3.1 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 TestSyncFileDisplayNamePrefersPathBasename(t *testing.T) {
|
|
got := SyncFileDisplayName("/Documents/actual.jpg", "Display Name.jpg")
|
|
want := "actual.jpg"
|
|
if got != want {
|
|
t.Fatalf("SyncFileDisplayName() = %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)
|
|
}
|
|
}
|