package users

import "testing"

func TestNormalizeAvatarURL(t *testing.T) {
	tinyPNG := "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="

	got, err := normalizeAvatarURL(tinyPNG)
	if err != nil {
		t.Fatalf("normalizeAvatarURL() error = %v", err)
	}
	if got != tinyPNG {
		t.Fatalf("normalizeAvatarURL() = %q, want %q", got, tinyPNG)
	}

	if _, err := normalizeAvatarURL("not-a-data-uri"); err == nil {
		t.Fatal("expected error for invalid avatar")
	}

	if _, err := normalizeAvatarURL("data:text/plain;base64,YQ=="); err == nil {
		t.Fatal("expected error for non-image mime")
	}
}
