package middleware import ( "net/http" "net/http/httptest" "strings" "testing" "time" "github.com/labstack/echo/v4" pscookie "git.ma-al.com/goc_marek/ps_shop/internal/prestashop/cookie" ) func TestSetPrestaShopCookiePersistsExpiry(t *testing.T) { e := echo.New() req := httptest.NewRequest(http.MethodGet, "https://shop.example.com/product/test", nil) rec := httptest.NewRecorder() res := e.NewContext(req, rec).Response() expiresAt := time.Now().UTC().Add(4 * time.Hour).Truncate(time.Second) setPrestaShopCookie(req, res, &pscookie.SessionContext{ ExpiresAt: &expiresAt, }, "PrestaShop-test", "value") setCookie := rec.Header().Get("Set-Cookie") if !strings.Contains(setCookie, "max-age=") { t.Fatalf("Set-Cookie missing max-age: %q", setCookie) } if strings.Contains(setCookie, "Expires=") { t.Fatalf("Set-Cookie should not include Expires: %q", setCookie) } if !strings.Contains(setCookie, "path=/") { t.Fatalf("Set-Cookie missing path=/: %q", setCookie) } }