package migration

import "testing"

func TestNormalizeAuthMode(t *testing.T) {
	if got := NormalizeAuthMode("google", "google_dwd"); got != AuthModeGoogleDWD {
		t.Fatalf("got %q", got)
	}
	if got := NormalizeAuthMode("microsoft", "google_dwd"); got != AuthModeOAuth {
		t.Fatalf("microsoft ignores dwd: got %q", got)
	}
	if got := NormalizeAuthMode("microsoft", "microsoft_app"); got != AuthModeMicrosoftApp {
		t.Fatalf("microsoft app: got %q", got)
	}
	if got := NormalizeAuthMode("google", ""); got != AuthModeOAuth {
		t.Fatalf("default oauth: got %q", got)
	}
}

func TestValidateServiceAccountJSON(t *testing.T) {
	if err := validateServiceAccountJSON(""); err != nil {
		t.Fatalf("empty ok: %v", err)
	}
	if err := validateServiceAccountJSON(`{"client_email":"a@b.iam.gserviceaccount.com","private_key":"-----BEGIN PRIVATE KEY-----\nabc\n-----END PRIVATE KEY-----\n"}`); err != nil {
		t.Fatalf("valid json: %v", err)
	}
	if err := validateServiceAccountJSON(`{`); err == nil {
		t.Fatal("expected invalid json error")
	}
}

func TestNewGoogleDWDEmpty(t *testing.T) {
	dwd, err := NewGoogleDWD("")
	if err != nil || dwd != nil {
		t.Fatalf("empty config: dwd=%v err=%v", dwd, err)
	}
}
