test(document): address @saraholt — lock JSON wire contract for thumbnailUrl
Prior coverage only exercised getThumbnailUrl() as a Java method call. The new case serialises via ObjectMapper and asserts the resulting JSON contains "thumbnailUrl":"..." so we catch silent breakages in the wire contract (getter rename, @JsonIgnore, visibility drop) — not just regressions in the method's return value (#309). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package org.raddatz.familienarchiv.model;
|
package org.raddatz.familienarchiv.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -58,4 +60,26 @@ class DocumentTest {
|
|||||||
String expected = "/api/documents/" + id + "/thumbnail?v=2026-04-23T14%3A30%3A45";
|
String expected = "/api/documents/" + id + "/thumbnail?v=2026-04-23T14%3A30%3A45";
|
||||||
assertThat(doc.getThumbnailUrl()).isEqualTo(expected);
|
assertThat(doc.getThumbnailUrl()).isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void thumbnailUrl_isSerialisedToJson_soFrontendReceivesIt() throws Exception {
|
||||||
|
UUID id = UUID.fromString("99999999-aaaa-bbbb-cccc-111122223333");
|
||||||
|
Document doc = Document.builder()
|
||||||
|
.id(id)
|
||||||
|
.title("Brief")
|
||||||
|
.originalFilename("brief.pdf")
|
||||||
|
.status(DocumentStatus.UPLOADED)
|
||||||
|
.thumbnailKey("thumbnails/" + id + ".jpg")
|
||||||
|
.thumbnailGeneratedAt(LocalDateTime.of(2026, 4, 23, 9, 0, 0))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule());
|
||||||
|
String json = mapper.writeValueAsString(doc);
|
||||||
|
|
||||||
|
// Locks the wire contract, not just the Java API: every Document JSON must carry
|
||||||
|
// `thumbnailUrl`. Protects against silent breakage if the getter gets renamed,
|
||||||
|
// hidden behind @JsonIgnore, or visibility-reduced — any of which would leave the
|
||||||
|
// frontend rendering the fallback icon on every surface.
|
||||||
|
assertThat(json).contains("\"thumbnailUrl\":\"" + doc.getThumbnailUrl() + "\"");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user