-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add details for document edition logs
- Loading branch information
1 parent
b478b19
commit b3b7638
Showing
9 changed files
with
159 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...acile-common-library/src/main/java/fr/dossierfacile/common/model/EditedDocumentModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package fr.dossierfacile.common.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import fr.dossierfacile.common.entity.Document; | ||
import fr.dossierfacile.common.entity.Guarantor; | ||
import fr.dossierfacile.common.entity.Tenant; | ||
import fr.dossierfacile.common.enums.DocumentCategory; | ||
import fr.dossierfacile.common.enums.DocumentSubCategory; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Optional; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class EditedDocumentModel { | ||
|
||
private DocumentCategory documentCategory; | ||
private DocumentSubCategory documentSubCategory; | ||
private Boolean noDocument; | ||
private Long tenantId; | ||
private Long guarantorId; | ||
|
||
public static EditedDocumentModel from(Document document) { | ||
return EditedDocumentModel.builder() | ||
.documentCategory(document.getDocumentCategory()) | ||
.documentSubCategory(document.getDocumentSubCategory()) | ||
.noDocument(document.getNoDocument()) | ||
.tenantId(Optional.ofNullable(document.getTenant()) | ||
.map(Tenant::getId).orElse(null)) | ||
.guarantorId(Optional.ofNullable(document.getGuarantor()) | ||
.map(Guarantor::getId).orElse(null)) | ||
.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...e-common-library/src/main/resources/db/migration/202312010000-update-tenant-log-table.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<databaseChangeLog | ||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.10.xsd"> | ||
<changeSet id="202312010000-01" author="juliette"> | ||
<addColumn tableName="tenant_log"> | ||
<column name="log_details" type="jsonb"/> | ||
</addColumn> | ||
</changeSet> | ||
</databaseChangeLog> |
71 changes: 71 additions & 0 deletions
71
...cile-common-library/src/test/java/fr/dossierfacile/common/service/LogServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package fr.dossierfacile.common.service; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import fr.dossierfacile.common.entity.Document; | ||
import fr.dossierfacile.common.entity.Guarantor; | ||
import fr.dossierfacile.common.entity.Log; | ||
import fr.dossierfacile.common.entity.Tenant; | ||
import fr.dossierfacile.common.enums.DocumentCategory; | ||
import fr.dossierfacile.common.enums.DocumentSubCategory; | ||
import fr.dossierfacile.common.enums.LogType; | ||
import fr.dossierfacile.common.repository.LogRepository; | ||
import fr.dossierfacile.common.service.interfaces.LogService; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
class LogServiceImplTest { | ||
|
||
private final LogRepository logRepository = mock(LogRepository.class); | ||
private final LogService logService = new LogServiceImpl(logRepository, null, new ObjectMapper()); | ||
|
||
@Test | ||
void should_save_edition_log_for_tenant_document() { | ||
Document document = Document.builder() | ||
.documentCategory(DocumentCategory.IDENTIFICATION) | ||
.documentSubCategory(DocumentSubCategory.FRENCH_IDENTITY_CARD) | ||
.tenant(tenantWithId(2L)) | ||
.build(); | ||
|
||
logService.saveDocumentEditedLog(document, tenantWithId(1L)); | ||
|
||
Log savedLog = getSavedLog(); | ||
assertThat(savedLog.getLogType()).isEqualTo(LogType.ACCOUNT_EDITED); | ||
assertThat(savedLog.getTenantId()).isEqualTo(1L); | ||
assertThat(savedLog.getLogDetails()).isEqualTo(""" | ||
{"documentCategory":"IDENTIFICATION","documentSubCategory":"FRENCH_IDENTITY_CARD","tenantId":2}"""); | ||
} | ||
|
||
@Test | ||
void should_save_edition_log_for_guarantor_document() { | ||
Document document = Document.builder() | ||
.documentCategory(DocumentCategory.FINANCIAL) | ||
.documentSubCategory(DocumentSubCategory.SALARY) | ||
.noDocument(true) | ||
.guarantor(Guarantor.builder().id(3L).build()) | ||
.build(); | ||
|
||
logService.saveDocumentEditedLog(document, tenantWithId(2L)); | ||
|
||
Log savedLog = getSavedLog(); | ||
assertThat(savedLog.getLogType()).isEqualTo(LogType.ACCOUNT_EDITED); | ||
assertThat(savedLog.getTenantId()).isEqualTo(2L); | ||
assertThat(savedLog.getLogDetails()).isEqualTo(""" | ||
{"documentCategory":"FINANCIAL","documentSubCategory":"SALARY","noDocument":true,"guarantorId":3}"""); | ||
} | ||
|
||
private static Tenant tenantWithId(long id) { | ||
return Tenant.builder().id(id).build(); | ||
} | ||
|
||
private Log getSavedLog() { | ||
ArgumentCaptor<Log> logCaptor = ArgumentCaptor.forClass(Log.class); | ||
verify(logRepository, times(1)).save(logCaptor.capture()); | ||
return logCaptor.getAllValues().get(0); | ||
} | ||
|
||
} |