feat(supervisor): support revoke binding and tighten access
This commit is contained in:
@@ -102,3 +102,51 @@ func TestSupervisorInviteBindAndOverview(t *testing.T) {
|
||||
t.Fatalf("status=%v, want one supervisor uid=%d", status.Items, supervisorUID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSupervisorRevokeBindingBySupervisor(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db := setupSupervisorTestDB(t)
|
||||
svc := NewService(db)
|
||||
ctx := context.Background()
|
||||
|
||||
ownerUID := 3101
|
||||
supervisorUID := 3102
|
||||
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)
|
||||
}
|
||||
if err := db.Create(&usermodel.User{ID: uint(supervisorUID), NickName: "supervisor"}).Error; err != nil {
|
||||
t.Fatalf("seed supervisor 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)
|
||||
}
|
||||
|
||||
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: %v", err)
|
||||
}
|
||||
|
||||
if err := svc.RevokeSupervisorBinding(ctx, supervisorUID, ownerUID, supervisorUID, now); err != nil {
|
||||
t.Fatalf("revoke by supervisor: %v", err)
|
||||
}
|
||||
|
||||
overview, err := svc.GetSupervisorOverview(ctx, supervisorUID, now)
|
||||
if err != nil {
|
||||
t.Fatalf("overview: %v", err)
|
||||
}
|
||||
if len(overview.Items) != 0 {
|
||||
t.Fatalf("overview items=%d, want=0 after revoke", len(overview.Items))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user