package drive

import (
	"testing"

	"github.com/ultisuite/ulti-backend/internal/nextcloud"
)

func TestSidecarPathsForSourceMove(t *testing.T) {
	src, dest, ok := sidecarPathsForSourceMove("/docs/a.docx", "/archive/a.docx")
	if !ok {
		t.Fatal("expected sidecar sync for docx")
	}
	if src != "/docs/a.ultidoc.json" || dest != "/archive/a.ultidoc.json" {
		t.Fatalf("unexpected sidecar paths: %q -> %q", src, dest)
	}

	_, _, ok = sidecarPathsForSourceMove("/docs/a.ultidoc.json", "/archive/a.ultidoc.json")
	if ok {
		t.Fatal("ultidoc sidecar itself should not trigger companion sync")
	}
}

func TestShouldSyncUltidocSidecar(t *testing.T) {
	if !shouldSyncUltidocSidecar("/docs/report.docx") {
		t.Fatal("docx should sync sidecar")
	}
	if shouldSyncUltidocSidecar(nextcloud.SidecarPathForSource("/docs/report.docx")) {
		t.Fatal("sidecar path should not sync again")
	}
}
