Test docstrings
This commit is contained in:
@@ -207,7 +207,9 @@ func parseResponseBody(w *httptest.ResponseRecorder, dest interface{}) error {
|
||||
// Create Booking Tests
|
||||
// =============================================================================
|
||||
|
||||
func TestBookings_Create(t *testing.T) {
|
||||
// TestBookings_Create tests that a user can successfully create a new booking
|
||||
// with a valid future time and at least one service. The test verifies the
|
||||
// booking is created in the database and associated with the correct user.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -269,7 +271,8 @@ func TestBookings_Create(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBookings_Create_InvalidInput(t *testing.T) {
|
||||
// TestBookings_Create_InvalidInput verifies that booking creation fails
|
||||
// with HTTP 400 when required fields are missing: start time or service IDs.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -330,7 +333,9 @@ func TestBookings_Create_InvalidInput(t *testing.T) {
|
||||
// List Bookings Tests
|
||||
// =============================================================================
|
||||
|
||||
func TestBookings_List(t *testing.T) {
|
||||
// TestBookings_List tests that a user can retrieve their list of bookings.
|
||||
// The test verifies the response includes the correct total count and that
|
||||
// bookings are properly returned.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -383,7 +388,9 @@ func TestBookings_List(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBookings_List_FilterByStatus(t *testing.T) {
|
||||
// TestBookings_List_FilterByStatus tests that booking list can be filtered
|
||||
// by status (e.g., pending, completed). It verifies that non-matching statuses
|
||||
// return empty results.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -452,7 +459,8 @@ func TestBookings_List_FilterByStatus(t *testing.T) {
|
||||
// Get Single Booking Tests
|
||||
// =============================================================================
|
||||
|
||||
func TestBookings_Get(t *testing.T) {
|
||||
// TestBookings_Get tests that a user can retrieve a single booking by its ID.
|
||||
// The test verifies the booking details including services are returned.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -505,7 +513,8 @@ func TestBookings_Get(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBookings_Get_NotFound(t *testing.T) {
|
||||
// TestBookings_Get_NotFound verifies that requesting a non-existent booking
|
||||
// returns HTTP 404 Not Found.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -532,7 +541,9 @@ func TestBookings_Get_NotFound(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBookings_Get_AccessDenied(t *testing.T) {
|
||||
// TestBookings_Get_AccessDenied tests that a user cannot access another user's
|
||||
// booking. The test creates two users, one creates a booking, and the other
|
||||
// attempts to access it - expecting HTTP 404 (not found/access denied).
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -578,7 +589,9 @@ func TestBookings_Get_AccessDenied(t *testing.T) {
|
||||
// Get Calendar Tests
|
||||
// =============================================================================
|
||||
|
||||
func TestBookings_GetCalendar(t *testing.T) {
|
||||
// TestBookings_GetCalendar tests that a user can export their booking
|
||||
// as an ICS calendar file. It verifies the response has the correct
|
||||
// text/calendar Content-Type and contains ICS-formatted data.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -638,7 +651,8 @@ func TestBookings_GetCalendar(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBookings_GetCalendar_NotFound(t *testing.T) {
|
||||
// TestBookings_GetCalendar_NotFound verifies that attempting to export
|
||||
// a non-existent booking to calendar returns HTTP 404.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -669,7 +683,8 @@ func TestBookings_GetCalendar_NotFound(t *testing.T) {
|
||||
// Edit Booking Tests
|
||||
// =============================================================================
|
||||
|
||||
func TestBookings_Edit(t *testing.T) {
|
||||
// TestBookings_Edit tests that a user can modify the start time of
|
||||
// their existing booking. The test verifies the time is updated in the DB.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -733,7 +748,8 @@ func TestBookings_Edit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBookings_Edit_InvalidInput(t *testing.T) {
|
||||
// TestBookings_Edit_InvalidInput verifies that editing fails with HTTP 400
|
||||
// when the start time is missing or is in the past.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -793,7 +809,8 @@ func TestBookings_Edit_InvalidInput(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBookings_Edit_NotFound(t *testing.T) {
|
||||
// TestBookings_Edit_NotFound verifies that editing a non-existent
|
||||
// booking returns HTTP 404.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -828,7 +845,9 @@ func TestBookings_Edit_NotFound(t *testing.T) {
|
||||
// Delete Booking Tests
|
||||
// =============================================================================
|
||||
|
||||
func TestBookings_Delete(t *testing.T) {
|
||||
// TestBookings_Delete tests that a user can delete (cancel) their booking.
|
||||
// For bookings without payments, it performs a hard delete. The test verifies
|
||||
// the booking is removed from the database.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -879,7 +898,10 @@ func TestBookings_Delete(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBookings_Delete_WithReason(t *testing.T) {
|
||||
// TestBookings_Delete_WithReason verifies that cancelling a booking with
|
||||
// an associated payment requires a reason (client_cancelled). Without a reason,
|
||||
// the request fails with HTTP 400. With a reason, the booking is soft-deleted
|
||||
// (status changed to client_cancelled).
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -947,7 +969,8 @@ func TestBookings_Delete_WithReason(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBookings_Delete_NotFound(t *testing.T) {
|
||||
// TestBookings_Delete_NotFound verifies that deleting a non-existent
|
||||
// booking returns HTTP 404.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -978,7 +1001,9 @@ func TestBookings_Delete_NotFound(t *testing.T) {
|
||||
// Unauthorized Tests
|
||||
// =============================================================================
|
||||
|
||||
func TestBookings_Unauthorized(t *testing.T) {
|
||||
// TestBookings_Unauthorized tests that all booking endpoints require
|
||||
// authentication. It verifies that requests without a token are rejected with
|
||||
// HTTP 401 for protected endpoints.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -1093,7 +1118,8 @@ func TestBookings_Unauthorized(t *testing.T) {
|
||||
// Additional Edge Case Tests
|
||||
// =============================================================================
|
||||
|
||||
func TestBookings_List_Empty(t *testing.T) {
|
||||
// TestBookings_List_Empty tests that listing bookings for a user with no
|
||||
// bookings returns an empty list with total 0.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -1133,7 +1159,8 @@ func TestBookings_List_Empty(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBookings_Get_InvalidBookingID(t *testing.T) {
|
||||
// TestBookings_Get_InvalidBookingID verifies that using an invalid
|
||||
// booking ID format returns HTTP 404 or 400.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -1161,7 +1188,8 @@ func TestBookings_Get_InvalidBookingID(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBookings_Create_PastDate(t *testing.T) {
|
||||
// TestBookings_Create_PastDate verifies that creating a booking with a
|
||||
// past start time fails with HTTP 400 Bad Request.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -1199,7 +1227,9 @@ func TestBookings_Create_PastDate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBookings_Create_Within48HourDepositRequired(t *testing.T) {
|
||||
// TestBookings_Create_Within48HourDepositRequired tests that when a booking
|
||||
// is made within 48 hours and the user has deposits_required > 0, the booking
|
||||
// should have deposit_required=true. With deposits_required=0, no deposit needed.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -1246,7 +1276,9 @@ func TestBookings_Create_Within48HourDepositRequired(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBookings_Create_MultipleServices(t *testing.T) {
|
||||
// TestBookings_Create_MultipleServices verifies that a booking can include
|
||||
// multiple services at once, and all services are properly associated with
|
||||
// the booking in the database.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -1309,7 +1341,8 @@ var _ = mw.UserIDKey
|
||||
// Auth and Security Tests
|
||||
// =============================================================================
|
||||
|
||||
func TestBookings_Get_NoAuthHeader(t *testing.T) {
|
||||
// TestBookings_Get_NoAuthHeader confirms that accessing a booking without
|
||||
// an Authorization header returns HTTP 401 Unauthorized.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -1350,7 +1383,9 @@ func TestBookings_Get_NoAuthHeader(t *testing.T) {
|
||||
// Calendar Export Tests - ICS Format Validation
|
||||
// =============================================================================
|
||||
|
||||
func TestBookings_GetCalendar_ValidICS(t *testing.T) {
|
||||
// TestBookings_GetCalendar_ValidICS validates that the ICS calendar export
|
||||
// contains all required fields: BEGIN:VCALENDAR, END:VCALENDAR, BEGIN:VEVENT,
|
||||
// END:VEVENT, DTSTART, DTEND, and SUMMARY.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -1421,7 +1456,9 @@ func TestBookings_GetCalendar_ValidICS(t *testing.T) {
|
||||
// Cancellation and Notification Tests
|
||||
// =============================================================================
|
||||
|
||||
func TestUserCancelBooking_ConfirmedCreatesNotification(t *testing.T) {
|
||||
// TestUserCancelBooking_ConfirmedCreatesNotification verifies that when a
|
||||
// user cancels a confirmed booking (one with payments), an admin notification
|
||||
// is created to alert staff of the cancellation.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -1490,7 +1527,9 @@ func TestUserCancelBooking_ConfirmedCreatesNotification(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserCancelBooking_PendingNoNotification(t *testing.T) {
|
||||
// TestUserCancelBooking_PendingNoNotification verifies that cancelling a
|
||||
// pending booking (one without payments) does NOT create an admin notification,
|
||||
// as pending cancellations don't require staff attention.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -1556,7 +1595,9 @@ func TestUserCancelBooking_PendingNoNotification(t *testing.T) {
|
||||
|
||||
// TestUserCancelBooking_TransactionIntegrity verifies that if any part of the
|
||||
// cancellation transaction fails, the booking status is NOT changed (rollback behavior)
|
||||
func TestUserCancelBooking_TransactionIntegrity(t *testing.T) {
|
||||
// TestUserCancelBooking_TransactionIntegrity tests that the cancellation
|
||||
// transaction properly commits - verifying the booking status actually changes
|
||||
// after a successful cancellation request.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -1630,7 +1671,9 @@ func TestUserCancelBooking_TransactionIntegrity(t *testing.T) {
|
||||
|
||||
|
||||
// TestCreateEditRequest tests that creating an edit request creates an admin notification
|
||||
func TestCreateEditRequest(t *testing.T) {
|
||||
// TestCreateEditRequest verifies that a user can request an edit to their
|
||||
// confirmed booking (e.g., change time). This creates a booking_edit_request record
|
||||
// and generates an admin notification for staff review.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -1704,7 +1747,8 @@ func TestCreateEditRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestDeleteEditRequest tests that user deleting their edit request deletes the admin notification
|
||||
func TestDeleteEditRequest(t *testing.T) {
|
||||
// TestDeleteEditRequest tests that an admin can delete/remove a pending
|
||||
// edit request from a booking without affecting the original booking data.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -1795,7 +1839,9 @@ func TestDeleteEditRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestAdminApproveEditRequest tests that admin approving acknowledges the notification (not deletes)
|
||||
func TestAdminApproveEditRequest(t *testing.T) {
|
||||
// TestAdminApproveEditRequest verifies that an admin can approve a user's
|
||||
// edit request. This updates the booking's start time to the requested time and
|
||||
// marks the edit request as handled.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -1912,7 +1958,8 @@ func TestAdminApproveEditRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestAdminRejectEditRequest tests that admin rejecting acknowledges the notification (not deletes)
|
||||
func TestAdminRejectEditRequest(t *testing.T) {
|
||||
// TestAdminRejectEditRequest tests that an admin can reject an edit request.
|
||||
// The original booking remains unchanged and the edit request is deleted.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -2026,7 +2073,8 @@ func TestAdminRejectEditRequest(t *testing.T) {
|
||||
|
||||
|
||||
// TestBookings_RequestEdit_BookingNotFound tests that requesting an edit for a non-existent booking returns 404
|
||||
func TestBookings_RequestEdit_BookingNotFound(t *testing.T) {
|
||||
// TestBookings_RequestEdit_BookingNotFound verifies that requesting an edit
|
||||
// for a non-existent booking returns HTTP 404 Not Found.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -2057,7 +2105,8 @@ func TestBookings_RequestEdit_BookingNotFound(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestBookings_RequestEdit_AlreadyHasPending tests that a user cannot create a second edit request while one already exists
|
||||
func TestBookings_RequestEdit_AlreadyHasPending(t *testing.T) {
|
||||
// TestBookings_RequestEdit_AlreadyHasPending tests that a user cannot create
|
||||
// a new edit request if one is already pending for the same booking.
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user