feat: company on emails and audit search
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
a6996841ac
commit
118c57c0ea
6 files changed
+147
-4
No files matched your search
+52
@@ -0,0 +1,52 @@
|
||||
package com.solvway.services.log.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.solvway.services.log.model.AuditEventLog;
|
||||
import com.solvway.services.log.repo.AuditEventLogRepository;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class AuditEventControllerCompanyTest {
|
||||
|
||||
private final AuditEventLogRepository repository = mock(AuditEventLogRepository.class);
|
||||
private final AuditEventController controller = new AuditEventController(repository);
|
||||
|
||||
@Test
|
||||
void companyIdGivenSearchesOnlyThatCompany() {
|
||||
when(repository.searchInCompany(eq(2L), any(), any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(new PageImpl<>(List.of(new AuditEventLog())));
|
||||
controller.search(new AuditEventController.SearchRequest(
|
||||
null, null, null, null, null, null, null, null, 2L));
|
||||
verify(repository).searchInCompany(eq(2L), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), any());
|
||||
verify(repository, never()).search(any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void companyIdAbsentSearchesAllRows() {
|
||||
when(repository.search(any(), any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(new PageImpl<>(List.of(new AuditEventLog())));
|
||||
controller.search(new AuditEventController.SearchRequest(
|
||||
null, null, null, null, null, null, null, null, null));
|
||||
verify(repository).search(any(), any(), any(), any(), any(), any(), any());
|
||||
verify(repository, never()).searchInCompany(any(), any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void companyIdIsReadFromJsonBodyAndOldBodiesStillWork() throws Exception {
|
||||
var m = new ObjectMapper();
|
||||
assertThat(m.readValue("{\"companyId\":3,\"actor\":\"a\"}", AuditEventController.SearchRequest.class)
|
||||
.companyId()).isEqualTo(3L);
|
||||
assertThat(m.readValue("{\"actor\":\"a\"}", AuditEventController.SearchRequest.class).companyId()).isNull();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user