test: add scheduling excludeUserID integration test
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -2882,3 +2882,48 @@ func TestScheduling_DST_AutumnBack_BookingAt0130GMT(t *testing.T) {
|
||||
t.Error("expected 01:30 GMT slot to be blocked (booking at 01:30 GMT = 01:30 UTC)")
|
||||
}
|
||||
}
|
||||
|
||||
// TestScheduling_GetAvailableHours_ExcludesOwnReservation verifies that an
|
||||
// authenticated user's own RESERVATION entry is excluded from time blockers
|
||||
// via the excludeUserID parameter in GetTimeBlockersInRange.
|
||||
func TestScheduling_GetAvailableHours_ExcludesOwnReservation(t *testing.T) {
|
||||
ctx, tx := resetTestData(t)
|
||||
|
||||
userID, err := fixtures.CreateTestUser(tx)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create user: %v", err)
|
||||
}
|
||||
|
||||
reservationTime := time.Date(2026, 3, 17, 10, 0, 0, 0, time.UTC)
|
||||
_, err = tx.Exec(ctx, `
|
||||
INSERT INTO time_blockers (start_time, duration_minutes, description, created_by)
|
||||
VALUES ($1, 60, 'RESERVATION:user:' || $2 || ':' || EXTRACT(epoch FROM NOW())::bigint::text, $2)
|
||||
`, reservationTime, userID)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create reservation: %v", err)
|
||||
}
|
||||
|
||||
// Request available hours as THIS user — their own reservation should be excluded
|
||||
handler := http.HandlerFunc(GetAvailableHours)
|
||||
req := httptest.NewRequest("GET", "/api/scheduling/available-hours?start=2026-03-17&end=2026-03-17", nil)
|
||||
reqCtx := context.WithValue(ctx, mw.UserIDKey, userID)
|
||||
reqCtx = context.WithValue(reqCtx, mw.UserRoleKey, "verified_email")
|
||||
req = req.WithContext(reqCtx)
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
|
||||
}
|
||||
var response []DayAvailableHours
|
||||
json.Unmarshal(w.Body.Bytes(), &response)
|
||||
targetDay := findDayByDate(response, "2026-03-17")
|
||||
if targetDay == nil {
|
||||
t.Fatal("expected 2026-03-17 in response")
|
||||
}
|
||||
|
||||
// The user's own reservation at 10:00 should NOT block the slot
|
||||
if !slotExists(targetDay.Slots, "10:00") {
|
||||
t.Error("expected 10:00 to be available (own reservation excluded)")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user