ultisuite-backend/internal/driveroot/cloud_native_test.go
R3D347HR4Y 857b9afc43
Some checks are pending
CI / Go tests (push) Waiting to run
CI / Integration tests (push) Waiting to run
CI / DB migrations (push) Waiting to run
feat(drive): implement external URL resolution for mounted cloud files
- Added new functionality to resolve external URLs for files on Google Drive and Microsoft OneDrive mounts.
- Introduced `mount_cloud_service.go` to handle OAuth token extraction and URL resolution.
- Enhanced `mounts_service.go` to update mount configurations with OAuth tokens.
- Updated API routes to include a new endpoint for fetching external URLs.
- Implemented enrichment functions in `cloud_native.go` to mark files that should open in the provider's web editor.
- Added tests for cloud-native file enrichment in `cloud_native_test.go` to ensure correct behavior.
2026-06-13 13:44:43 +02:00

62 lines
1.8 KiB
Go

package driveroot_test
import (
"testing"
"github.com/ultisuite/ulti-backend/internal/driveroot"
"github.com/ultisuite/ulti-backend/internal/nextcloud"
)
func TestGoogleWorkspaceWebURL(t *testing.T) {
url := driveroot.GoogleWorkspaceWebURL("application/vnd.google-apps.document", "abc123")
if url != "https://docs.google.com/document/d/abc123/edit" {
t.Fatalf("unexpected url: %s", url)
}
}
func TestEnrichMountCloudNativeGoogle(t *testing.T) {
file := nextcloud.FileInfo{
Type: "file",
Name: "Budget",
MimeType: "application/vnd.google-apps.spreadsheet",
ETag: "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
}
driveroot.EnrichMountCloudNative(&file, "googledrive")
if !file.OpenExternally {
t.Fatal("expected open_externally")
}
if file.ExternalURL == "" {
t.Fatal("expected external_url")
}
if file.MountBackend != "google" {
t.Fatalf("mount_backend=%s", file.MountBackend)
}
}
func TestEnrichMountCloudNativePersonalIgnored(t *testing.T) {
file := nextcloud.FileInfo{
Type: "file",
Name: "Report.docx",
MimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
}
driveroot.EnrichMountCloudNative(&file, "googledrive")
if file.OpenExternally {
t.Fatal("personal ultidrive doc should not open externally from mount enrich without mount context")
}
}
func TestEnrichMountCloudNativeMicrosoftOffice(t *testing.T) {
file := nextcloud.FileInfo{
Type: "file",
Name: "Plan.xlsx",
MimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
}
driveroot.EnrichMountCloudNative(&file, "onedrive")
if !file.OpenExternally {
t.Fatal("expected open_externally for office on onedrive mount")
}
if file.MountBackend != "microsoft" {
t.Fatalf("mount_backend=%s", file.MountBackend)
}
}