package nextcloud

import "testing"

func TestFileMatchesQuery(t *testing.T) {
	f := FileInfo{Name: "Report Q4.pdf", Path: "/Docs/Report Q4.pdf"}
	if !fileMatchesQuery(f, "report") {
		t.Fatal("expected name match")
	}
	if fileMatchesQuery(f, "missing") {
		t.Fatal("expected no match")
	}
}

func TestSortSearchResults_prefersNamePrefix(t *testing.T) {
	files := []FileInfo{
		{Name: "archive-report.pdf", Path: "/a/archive-report.pdf", Type: "file"},
		{Name: "report.pdf", Path: "/b/report.pdf", Type: "file"},
	}
	sortSearchResults(files, "report")
	if files[0].Name != "report.pdf" {
		t.Fatalf("got %q, want report.pdf first", files[0].Name)
	}
}

func TestNormalizeSearchPath(t *testing.T) {
	if got := normalizeSearchPath("foo/bar/"); got != "/foo/bar" {
		t.Fatalf("got %q", got)
	}
}

func TestIsDirectoryEntry(t *testing.T) {
	if !isDirectoryEntry(FileInfo{Type: "directory"}) {
		t.Fatal("directory type")
	}
	if !isDirectoryEntry(FileInfo{MimeType: "httpd/unix-directory"}) {
		t.Fatal("directory mime")
	}
}
