cookie ready

This commit is contained in:
2026-05-13 22:34:11 +02:00
parent 8c4e664ca8
commit 1b53c1c199
16 changed files with 798 additions and 146 deletions
+49 -1
View File
@@ -12,6 +12,54 @@ import (
pscookie "git.ma-al.com/goc_marek/ps_shop/internal/prestashop/cookie"
)
func TestShouldBootstrapAnonymousSession(t *testing.T) {
tests := []struct {
name string
rawCookie string
session *pscookie.SessionContext
want bool
}{
{
name: "missing cookie bootstraps",
rawCookie: "",
session: &pscookie.SessionContext{},
want: true,
},
{
name: "nil session bootstraps",
rawCookie: "cookie",
session: nil,
want: true,
},
{
name: "incomplete anonymous cookie does not bootstrap",
rawCookie: "cookie",
session: &pscookie.SessionContext{
Values: map[string]string{
"id_lang": "5",
},
},
want: false,
},
{
name: "logged in cookie does not bootstrap",
rawCookie: "cookie",
session: &pscookie.SessionContext{
IsLoggedIn: true,
},
want: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if got := shouldBootstrapAnonymousSession(tc.rawCookie, tc.session); got != tc.want {
t.Fatalf("shouldBootstrapAnonymousSession() = %v, want %v", got, tc.want)
}
})
}
}
func TestSetPrestaShopCookiePersistsExpiry(t *testing.T) {
e := echo.New()
req := httptest.NewRequest(http.MethodGet, "https://shop.example.com/product/test", nil)
@@ -21,7 +69,7 @@ func TestSetPrestaShopCookiePersistsExpiry(t *testing.T) {
setPrestaShopCookie(req, res, &pscookie.SessionContext{
ExpiresAt: &expiresAt,
}, "PrestaShop-test", "value")
}, "PrestaShop-test", "value", "/")
setCookie := rec.Header().Get("Set-Cookie")
if !strings.Contains(setCookie, "max-age=") {