feat: admin events with salesperson teams (add-admin-events) #5
No files matched your search
+4
-4
@@ -135,7 +135,7 @@ public class AdminEventService {
|
||||
List<String> missing = in.entrySet().stream().filter(e -> !StringUtils.hasText(e.getValue())).map(Map.Entry::getKey).toList();
|
||||
if (!missing.isEmpty()) {
|
||||
CodedResponseStatusException e = error(HttpStatus.BAD_REQUEST, "Required: " + String.join(", ", missing), "REQUIRED_FIELD", missing.get(0));
|
||||
e.getBody().setProperty("fields", missing);
|
||||
e.getBody().setProperty("errors", missing);
|
||||
throw e;
|
||||
}
|
||||
String name = r.name().trim();
|
||||
@@ -200,7 +200,7 @@ public class AdminEventService {
|
||||
} catch (RuntimeException ex) {
|
||||
CodedResponseStatusException e = error(HttpStatus.BAD_GATEWAY,
|
||||
"Event " + eventUuid + " was saved but its team was not; save the team again", "TEAM_NOT_SAVED", null);
|
||||
e.getBody().setProperty("eventUuid", String.valueOf(eventUuid));
|
||||
e.getBody().setProperty("details", Map.of("eventUuid", String.valueOf(eventUuid)));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -248,10 +248,10 @@ public class AdminEventService {
|
||||
return error(HttpStatus.NOT_FOUND, "Event not found", "EVENT_NOT_FOUND", null);
|
||||
}
|
||||
|
||||
/** field, when given, rides on the ProblemDetail body next to code, so the portal can mark the failing input. */
|
||||
/** field, when given, rides in the ProblemDetail's details (the portal forwards code, errors and flat details only). */
|
||||
private static CodedResponseStatusException error(HttpStatus status, String reason, String code, String field) {
|
||||
CodedResponseStatusException e = new CodedResponseStatusException(status, reason, code);
|
||||
if (field != null) e.getBody().setProperty("field", field);
|
||||
if (field != null) e.getBody().setProperty("details", Map.of("field", field));
|
||||
return e;
|
||||
}
|
||||
}
|
||||
+13
-2
@@ -107,10 +107,21 @@ class AdminEventServiceTest {
|
||||
assertThatThrownBy(r::run).isInstanceOfSatisfying(CodedResponseStatusException.class, e -> {
|
||||
assertThat(e.getStatusCode()).isEqualTo(status);
|
||||
assertThat(e.getCode()).isEqualTo(code);
|
||||
if (field != null) assertThat(e.getBody().getProperties()).containsEntry("field", field);
|
||||
// the portal forwards only code, errors (string list) and details (flat object) from a ProblemDetail
|
||||
if (field != null) assertThat((Map<String, Object>) e.getBody().getProperties().get("details")).containsEntry("field", field);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_allMissingFieldsAreListedInErrors() {
|
||||
assertThatThrownBy(() -> service.create(req("N", " ", null, "", null)))
|
||||
.isInstanceOfSatisfying(CodedResponseStatusException.class, e -> {
|
||||
assertThat(e.getCode()).isEqualTo("REQUIRED_FIELD");
|
||||
assertThat(e.getBody().getProperties().get("errors")).isEqualTo(List.of("location", "startDate", "endDate"));
|
||||
assertThat((Map<String, Object>) e.getBody().getProperties().get("details")).containsEntry("field", "location");
|
||||
});
|
||||
}
|
||||
|
||||
private void assertRefusedWithoutSave(AdminEventRequest r, String code, String field) {
|
||||
assertCoded(() -> service.create(r), HttpStatus.BAD_REQUEST, code, field);
|
||||
verify(rest, never()).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any());
|
||||
@@ -309,7 +320,7 @@ class AdminEventServiceTest {
|
||||
.isInstanceOfSatisfying(CodedResponseStatusException.class, e -> {
|
||||
assertThat(e.getStatusCode()).isEqualTo(HttpStatus.BAD_GATEWAY);
|
||||
assertThat(e.getCode()).isEqualTo("TEAM_NOT_SAVED");
|
||||
Object uuid = e.getBody().getProperties().get("eventUuid");
|
||||
Object uuid = ((Map<String, Object>) e.getBody().getProperties().get("details")).get("eventUuid");
|
||||
assertThat(uuid).isInstanceOf(String.class);
|
||||
assertThat(e.getReason()).contains((String) uuid);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user