ai slop ah
This commit is contained in:
@@ -2,11 +2,13 @@ package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
appdb "github.com/example/sndit/backend/internal/db"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func TestRegisterLoginAndSession(t *testing.T) {
|
||||
@@ -33,7 +35,7 @@ func TestRegisterLoginAndSession(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("create auth service: %v", err)
|
||||
}
|
||||
user, err := service.Register(ctx, "Photographer@Example.com", "DemoPassword123!", "Northline Studio")
|
||||
user, err := service.Register(ctx, "Photographer@Example.com", "DemoPassword123!", "Noah Bianchi")
|
||||
if err != nil {
|
||||
t.Fatalf("register user: %v", err)
|
||||
}
|
||||
@@ -44,9 +46,24 @@ func TestRegisterLoginAndSession(t *testing.T) {
|
||||
if err != nil || loggedIn.ID != user.ID {
|
||||
t.Fatalf("login failed: user=%+v err=%v", loggedIn, err)
|
||||
}
|
||||
updated, err := service.UpdateProfile(ctx, user.ID, "updated@example.com", "Updated Studio")
|
||||
if err != nil || updated.Email != "updated@example.com" || updated.Name != "Updated Studio" {
|
||||
t.Fatalf("profile update failed: user=%+v err=%v", updated, err)
|
||||
}
|
||||
if err := service.ChangePassword(ctx, user.ID, "DemoPassword123!", "NewPassword123!"); err != nil {
|
||||
t.Fatalf("password update failed: %v", err)
|
||||
}
|
||||
if _, err := service.Login(ctx, "updated@example.com", "DemoPassword123!"); !errors.Is(err, ErrInvalidCredentials) {
|
||||
t.Fatalf("old password should be invalid, got %v", err)
|
||||
}
|
||||
if _, err := service.Login(ctx, "updated@example.com", "NewPassword123!"); err != nil {
|
||||
t.Fatalf("new password should work: %v", err)
|
||||
}
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
service.SetSession(recorder, user)
|
||||
ginContext, _ := gin.CreateTestContext(recorder)
|
||||
ginContext.Request = httptest.NewRequest(http.MethodGet, "/api/auth/me", nil)
|
||||
service.SetSession(ginContext, user)
|
||||
request := httptest.NewRequest(http.MethodGet, "/api/auth/me", nil)
|
||||
request.AddCookie(recorder.Result().Cookies()[0])
|
||||
fromSession, err := service.UserFromRequest(ctx, request)
|
||||
|
||||
Reference in New Issue
Block a user