Validate expiryDate is strictly after eventDate and harden rejection tests
All checks were successful
CI / backend-test (push) Successful in 59s
CI / frontend-test (push) Successful in 22s
CI / frontend-e2e (push) Successful in 56s
CI / build-and-publish (push) Has been skipped

Adds ExpiryDateBeforeEventException (400) when expiryDate <= eventDate,
asserts DB row count unchanged after every rejection in integration tests,
and replaces all hardcoded dates in EventServiceTest with TODAY-relative
expressions derived from the fixed Clock.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-08 13:22:10 +01:00
parent 4d6df8d16b
commit 90bfd12bf3
5 changed files with 171 additions and 23 deletions

View File

@@ -2,6 +2,7 @@ package de.fete.adapter.in.web;
import de.fete.application.service.EventExpiredException;
import de.fete.application.service.EventNotFoundException;
import de.fete.application.service.ExpiryDateBeforeEventException;
import de.fete.application.service.ExpiryDateInPastException;
import de.fete.application.service.InvalidTimezoneException;
import java.net.URI;
@@ -47,6 +48,19 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
return handleExceptionInternal(ex, problemDetail, headers, status, request);
}
/** Handles expiry date before event date. */
@ExceptionHandler(ExpiryDateBeforeEventException.class)
public ResponseEntity<ProblemDetail> handleExpiryDateBeforeEvent(
ExpiryDateBeforeEventException ex) {
ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(
HttpStatus.BAD_REQUEST, ex.getMessage());
problemDetail.setTitle("Invalid Expiry Date");
problemDetail.setType(URI.create("urn:problem-type:expiry-date-before-event"));
return ResponseEntity.badRequest()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.body(problemDetail);
}
/** Handles expiry date validation failures. */
@ExceptionHandler(ExpiryDateInPastException.class)
public ResponseEntity<ProblemDetail> handleExpiryDateInPast(

View File

@@ -32,6 +32,10 @@ public class EventService implements CreateEventUseCase, GetEventUseCase {
throw new ExpiryDateInPastException(command.expiryDate());
}
if (!command.expiryDate().isAfter(command.dateTime().toLocalDate())) {
throw new ExpiryDateBeforeEventException(command.expiryDate(), command.dateTime());
}
var event = new Event();
event.setEventToken(EventToken.generate());
event.setOrganizerToken(OrganizerToken.generate());

View File

@@ -0,0 +1,13 @@
package de.fete.application.service;
import java.time.LocalDate;
import java.time.OffsetDateTime;
/** Thrown when an event's expiry date is not after the event date. */
public class ExpiryDateBeforeEventException extends RuntimeException {
/** Creates a new exception for the given dates. */
public ExpiryDateBeforeEventException(LocalDate expiryDate, OffsetDateTime dateTime) {
super("Expiry date " + expiryDate + " must be after event date " + dateTime.toLocalDate());
}
}