package extractor import ( "testing" "time" "github.com/playwright-community/playwright-go" ) func TestPlaywrightCookieToCookie_AllFields(t *testing.T) { pwCookie := playwright.Cookie{ Name: "session", Value: "abc123", Domain: ".example.com", Path: "/app", Expires: 1700000000, Secure: true, HttpOnly: true, SameSite: playwright.SameSiteAttributeStrict, } c := playwrightCookieToCookie(pwCookie) if c.Name != "session" { t.Errorf("Name = %q, want %q", c.Name, "session") } if c.Value != "abc123" { t.Errorf("Value = %q, want %q", c.Value, "abc123") } if c.Host != ".example.com" { t.Errorf("Host = %q, want %q", c.Host, ".example.com") } if c.Path != "/app" { t.Errorf("Path = %q, want %q", c.Path, "/app") } if c.Expires != time.Unix(1700000000, 0) { t.Errorf("Expires = %v, want %v", c.Expires, time.Unix(1700000000, 0)) } if !c.Secure { t.Error("Secure = false, want true") } if !c.HttpOnly { t.Error("HttpOnly = false, want true") } if c.SameSite != SameSiteStrict { t.Errorf("SameSite = %q, want %q", c.SameSite, SameSiteStrict) } } func TestPlaywrightCookieToCookie_SecureFalse(t *testing.T) { pwCookie := playwright.Cookie{ Name: "tracking", Value: "xyz", Domain: "example.com", Path: "/", Secure: false, } c := playwrightCookieToCookie(pwCookie) if c.Secure { t.Error("Secure = true, want false") } } func TestCookieToPlaywrightOptionalCookie_AllFields(t *testing.T) { c := Cookie{ Name: "__Secure-ID", Value: "token123", Host: ".example.com", Path: "/secure", Expires: time.Unix(1700000000, 0), Secure: true, HttpOnly: true, SameSite: SameSiteLax, } oc := cookieToPlaywrightOptionalCookie(c) if oc.Name != "__Secure-ID" { t.Errorf("Name = %q, want %q", oc.Name, "__Secure-ID") } if oc.Value != "token123" { t.Errorf("Value = %q, want %q", oc.Value, "token123") } if oc.Domain == nil || *oc.Domain != ".example.com" { t.Errorf("Domain = %v, want %q", oc.Domain, ".example.com") } if oc.Path == nil || *oc.Path != "/secure" { t.Errorf("Path = %v, want %q", oc.Path, "/secure") } if oc.Expires == nil || *oc.Expires != 1700000000 { t.Errorf("Expires = %v, want %v", oc.Expires, 1700000000) } if oc.Secure == nil || !*oc.Secure { t.Error("Secure = nil or false, want *true") } if oc.HttpOnly == nil || !*oc.HttpOnly { t.Error("HttpOnly = nil or false, want *true") } if oc.SameSite == nil || *oc.SameSite != *playwright.SameSiteAttributeLax { t.Errorf("SameSite = %v, want Lax", oc.SameSite) } } func TestCookieToPlaywrightOptionalCookie_SecureFalse(t *testing.T) { c := Cookie{ Name: "tracker", Value: "v", Host: "example.com", Path: "/", Secure: false, } oc := cookieToPlaywrightOptionalCookie(c) if oc.Secure == nil { t.Fatal("Secure = nil, want *false") } if *oc.Secure { t.Error("Secure = *true, want *false") } } func TestCookieToPlaywrightOptionalCookie_NoSameSite(t *testing.T) { c := Cookie{ Name: "basic", Value: "val", Host: "example.com", Path: "/", } oc := cookieToPlaywrightOptionalCookie(c) if oc.SameSite != nil { t.Errorf("SameSite = %v, want nil", oc.SameSite) } }