0529
This commit is contained in:
+85
@@ -0,0 +1,85 @@
|
||||
package com.writeoff.module.audit.service;
|
||||
|
||||
import com.writeoff.module.audit.dto.AuditActionRequest;
|
||||
import com.writeoff.module.audit.model.AuditNode;
|
||||
import com.writeoff.module.audit.model.AuditTask;
|
||||
import com.writeoff.module.audit.model.AuditTaskStatus;
|
||||
import com.writeoff.module.audit.repository.InMemoryAuditTaskRepository;
|
||||
import com.writeoff.module.meeting.service.MeetingService;
|
||||
import com.writeoff.module.scheduler.repository.InMemoryAsyncJobRepository;
|
||||
import com.writeoff.module.scheduler.service.AsyncJobService;
|
||||
import com.writeoff.security.AuthContext;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class AuditServiceNotificationTest {
|
||||
|
||||
@AfterEach
|
||||
void clearAuthContext() {
|
||||
AuthContext.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
void approveShouldTriggerAssignedNotificationForNextNode() {
|
||||
AuthContext.set(2001L, 1L);
|
||||
|
||||
InMemoryAuditTaskRepository repository = new InMemoryAuditTaskRepository();
|
||||
AsyncJobService asyncJobService = new AsyncJobService(new InMemoryAsyncJobRepository());
|
||||
MeetingService meetingService = mock(MeetingService.class);
|
||||
AuditFlowConfigService auditFlowConfigService = mock(AuditFlowConfigService.class);
|
||||
|
||||
AuditTask pendingTask = repository.save(new AuditTask(
|
||||
null,
|
||||
9001L,
|
||||
AuditNode.INIT_REVIEW,
|
||||
2001L,
|
||||
AuditTaskStatus.PENDING,
|
||||
""
|
||||
));
|
||||
|
||||
when(auditFlowConfigService.nextNode(1L, AuditNode.INIT_REVIEW)).thenReturn(AuditNode.RE_REVIEW);
|
||||
when(auditFlowConfigService.resolveAssigneeUserId(1L, AuditNode.RE_REVIEW)).thenReturn(3001L);
|
||||
|
||||
AuditService auditService = new AuditService(
|
||||
repository,
|
||||
meetingService,
|
||||
null,
|
||||
asyncJobService,
|
||||
auditFlowConfigService,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
AuditActionRequest request = new AuditActionRequest();
|
||||
request.setIdempotencyKey("approve-next-node-notify");
|
||||
request.setOpinion("初审通过");
|
||||
|
||||
auditService.approve(pendingTask.getId(), request);
|
||||
|
||||
ArgumentCaptor<AuditTask> taskCaptor = ArgumentCaptor.forClass(AuditTask.class);
|
||||
verify(meetingService, times(1)).updateCurrentAuditNode(9001L, AuditNode.RE_REVIEW.name(), 3001L);
|
||||
verify(meetingService, times(1)).triggerAuditTaskAssignedNotification(taskCaptor.capture());
|
||||
|
||||
AuditTask nextTask = taskCaptor.getValue();
|
||||
assertNotNull(nextTask);
|
||||
assertEquals(9001L, nextTask.getMeetingId());
|
||||
assertEquals(AuditNode.RE_REVIEW, nextTask.getNode());
|
||||
assertEquals(Long.valueOf(3001L), nextTask.getAssigneeUserId());
|
||||
assertEquals(AuditTaskStatus.PENDING, nextTask.getStatus());
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -7,6 +7,7 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
@@ -25,11 +26,14 @@ class SystemUserServicePasswordTest {
|
||||
void shouldAcceptLegacyPlaintextOldPasswordAndUpgradeToHashWhenChangingPassword() {
|
||||
JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
|
||||
PasswordCodecService passwordCodecService = new PasswordCodecService();
|
||||
PlatformTransactionManager transactionManager = mock(PlatformTransactionManager.class);
|
||||
SystemUserService systemUserService = new SystemUserService(
|
||||
jdbcTemplate,
|
||||
null,
|
||||
null,
|
||||
new PasswordPolicyService(),
|
||||
passwordCodecService
|
||||
passwordCodecService,
|
||||
transactionManager
|
||||
);
|
||||
AuthContext.set(1001L, 2001L);
|
||||
when(jdbcTemplate.queryForObject(
|
||||
|
||||
Reference in New Issue
Block a user