test(07-07): cover already-activated activate and 22-ported corpus counts
Unit tests now expect Winter 500 HTML when the target user is already active, and the inventory assertions match 169/22/147. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"git.golem15.com/golem15/fonoteka/plugins/golem15/user/classes"
|
"git.golem15.com/golem15/fonoteka/plugins/golem15/user/classes"
|
||||||
"git.golem15.com/golem15/fonoteka/plugins/golem15/user/controllers"
|
"git.golem15.com/golem15/fonoteka/plugins/golem15/user/controllers"
|
||||||
|
"git.golem15.com/golem15/fonoteka/plugins/golem15/user/models"
|
||||||
"git.golem15.com/golem15/summercms/postcard"
|
"git.golem15.com/golem15/summercms/postcard"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -85,6 +86,13 @@ func TestActivate(t *testing.T) {
|
|||||||
if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), `"is_activated":false`) {
|
if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), `"is_activated":false`) {
|
||||||
t.Fatalf("activate %d %s", rec.Code, rec.Body.String())
|
t.Fatalf("activate %d %s", rec.Code, rec.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
already := loginToken(t, app, gdb, "activate-already@example.test")
|
||||||
|
if err := gdb.Model(&models.User{}).Where("email = ?", "activate-already@example.test").Update("is_activated", true).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
locked := bearerJSON(t, controllers.Activate(app), "/_user/api/v1/activate", already, `{"code":"wrong"}`)
|
||||||
|
assertWinterErrorPage(t, locked)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestActivateByCode(t *testing.T) {
|
func TestActivateByCode(t *testing.T) {
|
||||||
@@ -124,9 +132,20 @@ func TestActivateByCode(t *testing.T) {
|
|||||||
if _, ok := errorsBody["code"]; !ok {
|
if _, ok := errorsBody["code"]; !ok {
|
||||||
t.Fatalf("errors = %#v", verr)
|
t.Fatalf("errors = %#v", verr)
|
||||||
}
|
}
|
||||||
bad := postJSON(t, controllers.ActivateByCode(app), "/_user/api/v1/activate-by-code", `{"code":"1!nope"}`)
|
bad := postJSON(t, controllers.ActivateByCode(app), "/_user/api/v1/activate-by-code", `{"code":"`+strconv.FormatUint(uint64(user.ID), 10)+`!nope"}`)
|
||||||
if bad.Body.String() != `{"error":"This activation link is invalid or has expired"}` {
|
assertWinterErrorPage(t, bad)
|
||||||
t.Fatalf("bad %d %s", bad.Code, bad.Body.String())
|
}
|
||||||
|
|
||||||
|
func assertWinterErrorPage(t *testing.T, rec *httptest.ResponseRecorder) {
|
||||||
|
t.Helper()
|
||||||
|
if rec.Code != http.StatusInternalServerError {
|
||||||
|
t.Fatalf("status %d body %s", rec.Code, rec.Body.String())
|
||||||
|
}
|
||||||
|
if rec.Header().Get("Content-Type") != "text/html; charset=UTF-8" {
|
||||||
|
t.Fatalf("content-type %q", rec.Header().Get("Content-Type"))
|
||||||
|
}
|
||||||
|
if !strings.Contains(rec.Body.String(), "Błąd strony") {
|
||||||
|
t.Fatalf("missing winter error marker: %s", rec.Body.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,8 +92,20 @@ func TestCodes(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
before, err := IsAlreadyActivated(t.Context(), db, pending.ID)
|
||||||
|
if err != nil || before {
|
||||||
|
t.Fatalf("pending already-activated = %t err=%v", before, err)
|
||||||
|
}
|
||||||
activated, ok := VerifyActivationCode(t.Context(), db, pending.ID, activation)
|
activated, ok := VerifyActivationCode(t.Context(), db, pending.ID, activation)
|
||||||
if !ok || activated == nil || !activated.IsActivated {
|
if !ok || activated == nil || !activated.IsActivated {
|
||||||
t.Fatalf("activate = %v %#v", ok, activated)
|
t.Fatalf("activate = %v %#v", ok, activated)
|
||||||
}
|
}
|
||||||
|
after, err := IsAlreadyActivated(t.Context(), db, pending.ID)
|
||||||
|
if err != nil || !after {
|
||||||
|
t.Fatalf("activated already-activated = %t err=%v", after, err)
|
||||||
|
}
|
||||||
|
missing, err := IsAlreadyActivated(t.Context(), db, 999999)
|
||||||
|
if err != nil || missing {
|
||||||
|
t.Fatalf("missing already-activated = %t err=%v", missing, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user