package authentik

import "testing"

func TestOAuthPresetForGoogle(t *testing.T) {
	preset := OAuthPresetFor("google")
	if preset.ProviderType != "google" {
		t.Fatalf("provider type = %q", preset.ProviderType)
	}
	if preset.AuthorizationURL == "" || preset.AccessTokenURL == "" {
		t.Fatal("expected google oauth endpoints")
	}
}

func TestOAuthRedirectURI(t *testing.T) {
	got := OAuthRedirectURI("http://localhost/auth", "google-workspace")
	want := "http://localhost/auth/source/oauth/callback/google-workspace/"
	if got != want {
		t.Fatalf("redirect uri = %q, want %q", got, want)
	}
}

func TestRemovedIdentityProviders(t *testing.T) {
	before := map[string]any{
		"identity_providers": map[string]any{
			"providers": []any{
				map[string]any{"id": "a", "authentik_pk": 1, "type": "oauth"},
				map[string]any{"id": "b", "authentik_pk": 2, "type": "saml"},
			},
		},
	}
	after := map[string]any{
		"identity_providers": map[string]any{
			"providers": []any{
				map[string]any{"id": "a", "authentik_pk": 1, "type": "oauth"},
			},
		},
	}
	removed := RemovedIdentityProviders(before, after)
	if len(removed) != 1 {
		t.Fatalf("removed count = %d, want 1", len(removed))
	}
	if id, _ := removed[0]["id"].(string); id != "b" {
		t.Fatalf("removed id = %q", id)
	}
}
