Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ void rejectsAnIntentUsedAsAWorkflowId() {
.isInstanceOf(AiRuntimeContractException.class);
}

@Test
void acceptsLegacyHwpGeneratedDocumentsForBackwardCompatibility() {
RenewalRunRequest request = request();

assertThatCode(() -> validator.validateResponse(
request,
generateResponse(
request,
Map.of("employee_name", "NGUYEN VAN AN"),
"hwp"
)
)).doesNotThrowAnyException();
}

@Test
void rejectsAResponseFromAnotherAttempt() {
RenewalRunRequest request = request();
Expand Down Expand Up @@ -376,6 +390,14 @@ workflowId, new BigDecimal("0.91"), "NEEDS_INFO", "NEEDS_INFO", "ask_hr",
private RenewalRunResponse generateResponse(
RenewalRunRequest request,
Map<String, Object> values
) {
return generateResponse(request, values, "hwpx");
}

private RenewalRunResponse generateResponse(
RenewalRunRequest request,
Map<String, Object> values,
String format
) {
return new RenewalRunResponse(
request.requestId(), request.attemptId(), request.taskId(), "EXPIRY_RENEWAL",
Expand All @@ -384,7 +406,7 @@ private RenewalRunResponse generateResponse(
"generate", "PHASE_4", "STEP_13", Map.of(), List.of(), List.of(),
null, null, false, null, null, null,
List.of(new RenewalGeneratedDocument(
"standard_labor_contract_v6", "표준근로계약서", "hwp", "stub", null, null,
"standard_labor_contract_v6", "표준근로계약서", format, "stub", null, null,
List.copyOf(values.keySet()), List.of(), values
)),
List.of(), null, List.of("GENERATE_DRAFTS", "READY_FOR_REVIEW"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -96,7 +97,7 @@ void resetAndSeed() {
reset(runtimeClient);
reset(documentGenerationClient, fileStorage);
when(documentGenerationClient.generate(any())).thenReturn(new GeneratedDocumentFile(
"표준근로계약서.hwp", "hwp", validHwpFile()
"표준근로계약서.hwpx", "hwpx", validHwpxFile()
));
capturedRequest.set(null);
jdbcTemplate.update("DELETE FROM document_request_draft");
Expand Down Expand Up @@ -468,16 +469,27 @@ void generatesAndLinksADraftWithoutPersistingTheRawValues() throws Exception {
.isEqualTo("standard_labor_contract_v6");
assertThat(JsonPath.<String>read(response.body(), "$.generated_documents[0].status"))
.isEqualTo("GENERATED");
assertThat(JsonPath.<String>read(response.body(), "$.generated_documents[0].format"))
.isEqualTo("hwpx");
assertThat(JsonPath.<String>read(response.body(), "$.generated_documents[0].stored_file_id"))
.isNotBlank();
assertThat(JsonPath.<String>read(response.body(), "$.generated_documents[0].worker_document_id"))
.isNotBlank();
assertThat(response.body()).doesNotContain("NGUYEN VAN AN", "passport_number");

assertThat(jdbcTemplate.queryForObject(
"SELECT COUNT(*) FROM stored_file WHERE task_id = ? AND worker_id = ?",
"""
SELECT COUNT(*) FROM stored_file
WHERE task_id = ? AND worker_id = ?
AND mime_type = 'application/vnd.hancom.hwpx'
AND LOWER(name) LIKE '%.hwpx'
""",
Integer.class, TASK_A, WORKER_A
)).isEqualTo(1);
verify(documentGenerationClient).generate(argThat(request ->
"hwpx".equals(request.format())
&& "standard_labor_contract_v6".equals(request.templateId())
));
assertThat(jdbcTemplate.queryForObject(
"""
SELECT COUNT(*) FROM worker_document
Expand Down Expand Up @@ -641,7 +653,7 @@ private RenewalGeneratedDocument generatedDocument(String templateId) {
return new RenewalGeneratedDocument(
templateId,
"Renewal test document",
"hwp",
"hwpx",
"stub",
null,
null,
Expand Down Expand Up @@ -705,15 +717,15 @@ private RenewalRunResponse workerGuideReviewResponse(RenewalRunRequest request)
);
}

private byte[] validHwpFile() {
try (org.apache.poi.poifs.filesystem.POIFSFileSystem fileSystem =
new org.apache.poi.poifs.filesystem.POIFSFileSystem()) {
byte[] header = new byte[256];
byte[] signature = "HWP Document File".getBytes(StandardCharsets.US_ASCII);
System.arraycopy(signature, 0, header, 0, signature.length);
fileSystem.createDocument(new java.io.ByteArrayInputStream(header), "FileHeader");
java.io.ByteArrayOutputStream output = new java.io.ByteArrayOutputStream();
fileSystem.writeFilesystem(output);
private byte[] validHwpxFile() {
java.io.ByteArrayOutputStream output = new java.io.ByteArrayOutputStream();
try (java.util.zip.ZipOutputStream zip = new java.util.zip.ZipOutputStream(output)) {
zip.putNextEntry(new java.util.zip.ZipEntry("mimetype"));
zip.write("application/hwp+zip".getBytes(StandardCharsets.UTF_8));
zip.closeEntry();
zip.putNextEntry(new java.util.zip.ZipEntry("Contents/section0.xml"));
zip.write("<xml>Renewal draft</xml>".getBytes(StandardCharsets.UTF_8));
zip.closeEntry();
return output.toByteArray();
} catch (java.io.IOException exception) {
throw new IllegalStateException(exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void setUp() {
var request = invocation.<com.fowoco.server.aiintegration.application.document.DocumentGenerationRequest>
getArgument(0);
return new GeneratedDocumentFile(
request.templateId() + ".hwp",
request.templateId() + "." + request.format(),
request.format(),
request.templateId().getBytes(StandardCharsets.UTF_8)
);
Expand Down Expand Up @@ -83,7 +83,7 @@ void rejectsADraftWithMissingRequiredMappedValuesBeforeGeneration() {
RenewalGeneratedDocument incomplete = new RenewalGeneratedDocument(
"standard_labor_contract_v6",
"standard_labor_contract_v6",
"hwp",
"hwpx",
"READY",
null,
null,
Expand All @@ -100,6 +100,30 @@ void rejectsADraftWithMissingRequiredMappedValuesBeforeGeneration() {
verify(generationClient, times(0)).generate(any());
}

@Test
void preservesLegacyHwpFormatForBackwardCompatibility() {
RenewalGeneratedDocument legacyHwp = new RenewalGeneratedDocument(
"standard_labor_contract_v6",
"standard_labor_contract_v6",
"hwp",
"READY",
null,
null,
List.of(),
List.of(),
values("standard_labor_contract_v6")
);

PreparedRenewalDocument prepared = service.prepare(
"RECONTRACT",
List.of(legacyHwp)
).get(0);

assertThat(prepared.descriptor().format()).isEqualTo("hwp");
assertThat(prepared.file().format()).isEqualTo("hwp");
assertThat(prepared.file().fileName()).endsWith(".hwp");
}

@Test
void mapsGeneratedTemplatesToTheirActualDocumentTypes() {
assertThat(service.documentType("standard_labor_contract_v6"))
Expand All @@ -123,7 +147,7 @@ private List<RenewalGeneratedDocument> caseWideDocuments() {

private RenewalGeneratedDocument document(String templateId) {
return new RenewalGeneratedDocument(
templateId, templateId, "hwp", "READY",
templateId, templateId, "hwpx", "READY",
null, null, List.of(), List.of(), values(templateId)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void setUp() {
null, null, taskSnapshot()
);
RenewalGeneratedDocument document = new RenewalGeneratedDocument(
"standard_labor_contract_v6", "표준근로계약서", "hwp", "READY",
"standard_labor_contract_v6", "표준근로계약서", "hwpx", "READY",
null, null, List.of(), List.of(), Map.of("worker_name", "응웬반안")
);
response = new RenewalRunResponse(
Expand Down