cookie ready
This commit is contained in:
@@ -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=") {
|
||||
|
||||
Reference in New Issue
Block a user