1
This commit is contained in:
+37
-3
@@ -2,6 +2,7 @@ package com.baiyue.iam.notification;
|
||||
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.iam.entity.IamMembership;
|
||||
import com.baiyue.iam.entity.IamMembershipRole;
|
||||
import com.baiyue.iam.entity.IamRole;
|
||||
import com.baiyue.iam.entity.IamUser;
|
||||
import com.baiyue.iam.mapper.IamMembershipMapper;
|
||||
@@ -22,7 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class NotificationRecipientResolverTest {
|
||||
private final IamMembershipMapper memberships = mock(IamMembershipMapper.class);
|
||||
@@ -70,7 +71,7 @@ class NotificationRecipientResolverTest {
|
||||
|
||||
@Test
|
||||
void explainsWhenRoleCodeDoesNotExist() {
|
||||
when(roles.selectOne(any())).thenReturn(null);
|
||||
when(roles.selectList(any())).thenReturn(List.of());
|
||||
|
||||
assertThatThrownBy(() -> resolver.resolve(roleRequest(RecipientType.PLATFORM_ROLE, "MISSING_ROLE")))
|
||||
.isInstanceOf(BizException.class)
|
||||
@@ -81,7 +82,7 @@ class NotificationRecipientResolverTest {
|
||||
void explainsWhenRoleHasNoActiveMembers() {
|
||||
IamRole role = new IamRole();
|
||||
role.setId(501L);
|
||||
when(roles.selectOne(any())).thenReturn(role);
|
||||
when(roles.selectList(any())).thenReturn(List.of(role));
|
||||
when(membershipRoles.selectList(any())).thenReturn(List.of());
|
||||
|
||||
assertThatThrownBy(() -> resolver.resolve(roleRequest(RecipientType.PLATFORM_ROLE, "CUSTOMER_REVIEWER")))
|
||||
@@ -89,6 +90,39 @@ class NotificationRecipientResolverTest {
|
||||
.hasMessage("该角色下暂无可接收消息的有效用户,请先为角色分配启用中的成员");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolvesEnterpriseMemberAssignedToPlatformProvidedMerchantRole() {
|
||||
IamRole role = new IamRole();
|
||||
role.setId(501L);
|
||||
role.setTenantId(0L);
|
||||
role.setAppCode("MERCHANT");
|
||||
role.setRoleCode("MERCHANT_OWNER");
|
||||
IamMembershipRole assignment = new IamMembershipRole();
|
||||
assignment.setTenantId(9L);
|
||||
assignment.setRoleId(role.getId());
|
||||
assignment.setMembershipId(301L);
|
||||
IamMembership membership = new IamMembership();
|
||||
membership.setId(301L);
|
||||
membership.setTenantId(9L);
|
||||
membership.setUserId(401L);
|
||||
membership.setStatus("ACTIVE");
|
||||
IamUser user = new IamUser();
|
||||
user.setId(401L);
|
||||
user.setDisplayName("企业管理员");
|
||||
user.setStatus("ACTIVE");
|
||||
when(roles.selectList(any())).thenReturn(List.of(role));
|
||||
when(membershipRoles.selectList(any())).thenReturn(List.of(assignment));
|
||||
when(memberships.selectBatchIds(List.of(301L))).thenReturn(List.of(membership));
|
||||
when(users.selectById(401L)).thenReturn(user);
|
||||
|
||||
var recipients = resolver.resolve(new CreateNotificationRequest(9L, "ORDER_STATUS_CHANGED",
|
||||
RecipientType.TENANT_ROLE, null, "MERCHANT_OWNER", Map.of(), null,
|
||||
"notification-tenant-role-key", null, null));
|
||||
|
||||
assertThat(recipients).containsExactly(new NotificationRecipientResolver.ResolvedRecipient(
|
||||
9L, 301L, 401L, "企业管理员", "MERCHANT"));
|
||||
}
|
||||
|
||||
private CreateNotificationRequest request(RecipientType recipientType, List<Long> recipientIds) {
|
||||
return new CreateNotificationRequest(9L, "ORDER_STATUS_CHANGED", recipientType, recipientIds,
|
||||
null, Map.of(), null, "notification-test-key", null, null);
|
||||
|
||||
Reference in New Issue
Block a user