feat(pages): admin publish and discard endpoints

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-03 11:29:32 +08:00
1 parent cd85faa60e
commit 8203839b09
5 files changed
+71 -1

No files matched your search

@@ -41,6 +41,8 @@ class AdminPageServiceTest {
private static final String SEARCH = "/counter/cmsPage/search";
private static final String DELETE = "/counter/cmsPage/delete";
private static final String UPLOAD = "/counter/pageImage/upload";
private static final String PUBLISH = "/counter/cmsPage/publish";
private static final String DISCARD = "/counter/cmsPage/discard";
private RestTemplateCustomUtil rest;
private AdminAuthenticationService auth;
@@ -173,4 +175,41 @@ class AdminPageServiceTest {
assertThatThrownBy(() -> service.create(request(null))).isInstanceOf(CodedResponseStatusException.class);
verify(rest, never()).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any());
}
@Test
void publishAndDiscardAreScopedAndSentForTheStoredPage() {
caller(2L, false);
when(rest.postForEntity(eq(PUBLISH), any(ParameterizedTypeReference.class), any())).thenReturn(ResponseEntity.ok(Map.of("id", 5)));
when(rest.postForEntity(eq(DISCARD), any(ParameterizedTypeReference.class), any())).thenReturn(ResponseEntity.ok(Map.of("id", 5)));
assertThat(service.publish(5L)).containsEntry("id", 5);
assertThat(service.discard(5L)).containsEntry("id", 5);
ArgumentCaptor<Object> body = ArgumentCaptor.forClass(Object.class);
verify(rest).postForEntity(eq(PUBLISH), any(ParameterizedTypeReference.class), body.capture());
assertThat((Map<String, Object>) body.getValue()).containsEntry("id", 5L).containsEntry("user", "boss");
verify(rest).postForEntity(eq(DISCARD), any(ParameterizedTypeReference.class), eq(5L));
}
@Test
void staffCannotPublishOrDiscardAnotherCompanysPage() {
caller(3L, false);
for (Runnable r : List.<Runnable>of(() -> service.publish(5L), () -> service.discard(5L))) {
assertThatThrownBy(r::run).isInstanceOfSatisfying(CodedResponseStatusException.class,
e -> assertThat(e.getCode()).isEqualTo("PAGE_NOT_FOUND"));
}
verify(rest, never()).postForEntity(eq(PUBLISH), any(ParameterizedTypeReference.class), any());
verify(rest, never()).postForEntity(eq(DISCARD), any(ParameterizedTypeReference.class), any());
}
@Test
void aPublishRefusalBecomesCodeAndField() {
caller(2L, false);
byte[] problem = "{\"status\":409,\"detail\":\"slug|PagesSlugTaken\"}".getBytes(StandardCharsets.UTF_8);
when(rest.postForEntity(eq(PUBLISH), any(ParameterizedTypeReference.class), any())).thenThrow(
HttpClientErrorException.create(HttpStatus.CONFLICT, "x", HttpHeaders.EMPTY, problem, StandardCharsets.UTF_8));
assertThatThrownBy(() -> service.publish(5L)).isInstanceOfSatisfying(CodedResponseStatusException.class, e -> {
assertThat(e.getStatusCode()).isEqualTo(HttpStatus.CONFLICT);
assertThat(e.getCode()).isEqualTo("PagesSlugTaken");
assertThat(e.getBody().getProperties()).containsEntry("details", Map.of("field", "slug"));
});
}
}