feat(supervisor): allow up to 3 supervisors per owner
This commit is contained in:
@@ -2,6 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -51,7 +52,6 @@ func TestSupervisorInviteBindAndOverview(t *testing.T) {
|
||||
supervisorUID := 3002
|
||||
now := time.Date(2026, 4, 16, 10, 0, 0, 0, time.Local)
|
||||
|
||||
// seed users
|
||||
if err := db.Create(&usermodel.User{ID: uint(ownerUID), NickName: "owner"}).Error; err != nil {
|
||||
t.Fatalf("seed owner user: %v", err)
|
||||
}
|
||||
@@ -150,3 +150,55 @@ func TestSupervisorRevokeBindingBySupervisor(t *testing.T) {
|
||||
t.Fatalf("overview items=%d, want=0 after revoke", len(overview.Items))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSupervisorBindRespectsMaxSupervisors(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db := setupSupervisorTestDB(t)
|
||||
svc := NewService(db)
|
||||
ctx := context.Background()
|
||||
|
||||
ownerUID := 3201
|
||||
now := time.Date(2026, 4, 16, 10, 0, 0, 0, time.Local)
|
||||
|
||||
if err := db.Create(&usermodel.User{ID: uint(ownerUID), NickName: "owner"}).Error; err != nil {
|
||||
t.Fatalf("seed owner user: %v", err)
|
||||
}
|
||||
|
||||
startDate := time.Date(2026, 4, 10, 0, 0, 0, 0, time.Local)
|
||||
if _, err := svc.UpsertProfile(ctx, ownerUID, UpsertProfileRequest{
|
||||
QuitStartDate: &startDate,
|
||||
PackPriceCent: intPtr(2500),
|
||||
BaselineCigsPerDay: intPtr(10),
|
||||
}, "owner", "", now); err != nil {
|
||||
t.Fatalf("upsert profile: %v", err)
|
||||
}
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
supervisorUID := 3300 + i
|
||||
if err := db.Create(&usermodel.User{ID: uint(supervisorUID), NickName: "s"}).Error; err != nil {
|
||||
t.Fatalf("seed supervisor user: %v", err)
|
||||
}
|
||||
invite, err := svc.CreateSupervisorInvite(ctx, ownerUID, now, 7)
|
||||
if err != nil {
|
||||
t.Fatalf("create invite: %v", err)
|
||||
}
|
||||
if err := svc.BindSupervisorInvite(ctx, supervisorUID, invite.Token, now); err != nil {
|
||||
t.Fatalf("bind #%d: %v", i+1, err)
|
||||
}
|
||||
}
|
||||
|
||||
supervisorUID := 3399
|
||||
if err := db.Create(&usermodel.User{ID: uint(supervisorUID), NickName: "s4"}).Error; err != nil {
|
||||
t.Fatalf("seed supervisor user: %v", err)
|
||||
}
|
||||
invite, err := svc.CreateSupervisorInvite(ctx, ownerUID, now, 7)
|
||||
if err != nil {
|
||||
t.Fatalf("create invite: %v", err)
|
||||
}
|
||||
if err := svc.BindSupervisorInvite(ctx, supervisorUID, invite.Token, now); err == nil {
|
||||
t.Fatalf("bind #4 should fail")
|
||||
} else if !errors.Is(err, ErrSupervisorLimitReached) {
|
||||
t.Fatalf("bind #4 err=%v, want ErrSupervisorLimitReached", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user