feat(finance): add customer wallet recharge flow
This commit is contained in:
@@ -42,6 +42,11 @@ class IamOpenApiContractTest {
|
||||
.contains("merchant:warehouse:inbound:list")
|
||||
.contains("lastleg:pda:operate")
|
||||
.contains("OVERSEAS_WAREHOUSE_PDA_OPERATOR")
|
||||
.contains("merchant:finance:account:view")
|
||||
.contains("merchant:finance:recharge:create")
|
||||
.contains("platform:finance:recharge:review")
|
||||
.contains("platform:finance:customer-account:adjust")
|
||||
.contains("两者独立授权")
|
||||
.contains("列表权限包含详情只读")
|
||||
.contains("PermissionCodesApiResponse:")
|
||||
.contains("TenantPageApiResponse:")
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.baiyue.iam.repository;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class WalletPermissionSqlContractTest {
|
||||
@Test
|
||||
void declaresReadAndWritePermissionsAsSeparateResources() throws Exception {
|
||||
String sql = sql();
|
||||
|
||||
assertThat(sql).contains(
|
||||
"(5105056,0,'PLATFORM','BUTTON',5105040,'platform:finance:recharge:review'",
|
||||
"(5105057,0,'PLATFORM','BUTTON',5105040,'platform:finance:customer-account:adjust'",
|
||||
"(5305020,0,'MERCHANT','MENU',5300000,'merchant:finance:account:view'",
|
||||
"(5305021,0,'MERCHANT','BUTTON',5305020,'merchant:finance:recharge:create'",
|
||||
"'资金账户','/finance/account','GET'",
|
||||
"'提交充值申请',NULL,'POST'",
|
||||
"'审核客户充值',NULL,'POST'",
|
||||
"'调整客户资金账户',NULL,'POST'");
|
||||
}
|
||||
|
||||
@Test
|
||||
void failsClosedOnPermissionIdentityOrTypeConflicts() throws Exception {
|
||||
String sql = sql();
|
||||
|
||||
assertThat(sql).contains(
|
||||
"migrate_wallet_permissions",
|
||||
"permission_type <> 'MENU'",
|
||||
"permission_type <> 'BUTTON'",
|
||||
"permission_code = 'merchant:finance:account:view'",
|
||||
"permission_code = 'platform:finance:customer-account:adjust'",
|
||||
"资金账户权限初始化失败:权限ID、编码或类型冲突");
|
||||
}
|
||||
|
||||
@Test
|
||||
void grantsMerchantPermissionsOnlyToTheEnterpriseOwner() throws Exception {
|
||||
String sql = sql();
|
||||
int permissionIndex = sql.indexOf("'merchant:finance:account:view'", sql.indexOf("INSERT IGNORE INTO"));
|
||||
int grantStart = sql.lastIndexOf("INSERT IGNORE INTO", permissionIndex);
|
||||
int grantEnd = sql.indexOf(';', permissionIndex);
|
||||
String grant = sql.substring(grantStart, grantEnd);
|
||||
|
||||
assertThat(grant).contains(
|
||||
"role.app_code='MERCHANT'",
|
||||
"role.role_code='MERCHANT_OWNER'",
|
||||
"'merchant:finance:account:view'",
|
||||
"'merchant:finance:recharge:create'");
|
||||
assertThat(grant).doesNotContain("PLATFORM_ADMIN", "PLATFORM_CUSTOM_ADMIN");
|
||||
}
|
||||
|
||||
@Test
|
||||
void grantsPlatformWritesOnlyToTheSuperAdministratorByDefault() throws Exception {
|
||||
String sql = sql();
|
||||
int permissionIndex = sql.indexOf("'platform:finance:recharge:review'", sql.indexOf("INSERT IGNORE INTO"));
|
||||
int grantStart = sql.lastIndexOf("INSERT IGNORE INTO", permissionIndex);
|
||||
int grantEnd = sql.indexOf(';', permissionIndex);
|
||||
String grant = sql.substring(grantStart, grantEnd);
|
||||
|
||||
assertThat(grant).contains(
|
||||
"role.app_code='PLATFORM'",
|
||||
"role.role_code='PLATFORM_ADMIN'",
|
||||
"'platform:finance:recharge:review'",
|
||||
"'platform:finance:customer-account:adjust'");
|
||||
assertThat(grant).doesNotContain(
|
||||
"PLATFORM_CUSTOM_ADMIN",
|
||||
"CUSTOMER_REVIEWER",
|
||||
"ORDER_OPERATOR");
|
||||
}
|
||||
|
||||
@Test
|
||||
void assertsCatalogAndDefaultRoleGrants() throws Exception {
|
||||
assertThat(sql()).contains(
|
||||
"资金账户权限初始化失败:平台写权限资源不完整",
|
||||
"资金账户权限初始化失败:客户权限资源不完整",
|
||||
"资金账户权限初始化失败:平台超级管理员授权不完整",
|
||||
"资金账户权限初始化失败:企业负责人授权不完整",
|
||||
")) <> 2 THEN");
|
||||
}
|
||||
|
||||
private static String sql() throws Exception {
|
||||
return new ClassPathResource("db/wallet-permissions.sql")
|
||||
.getContentAsString(StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
@@ -110,6 +110,35 @@ class AuthorizationSnapshotServiceTest {
|
||||
"merchant:warehouse:inbound:list");
|
||||
}
|
||||
|
||||
@Test
|
||||
void exposesWalletPermissionsFromCurrentRoleAssignments() {
|
||||
when(mapper.countActiveIdentity(42L, 7L, 9L)).thenReturn(1);
|
||||
when(mapper.findRoles(42L, 7L, 9L, "MERCHANT")).thenReturn(List.of("MERCHANT_OWNER"));
|
||||
when(mapper.findPermissions(42L, 7L, 9L, "MERCHANT")).thenReturn(List.of(
|
||||
"merchant:finance:account:view",
|
||||
"merchant:finance:recharge:create"));
|
||||
|
||||
var merchantPermissions = service.currentPermissions(new AuthenticatedUser(42L, 7L, 7L, 9L,
|
||||
"owner", "MERCHANT", "MERCHANT", java.util.Set.of()), "MERCHANT");
|
||||
|
||||
assertThat(merchantPermissions).containsExactlyInAnyOrder(
|
||||
"merchant:finance:account:view",
|
||||
"merchant:finance:recharge:create");
|
||||
|
||||
when(mapper.countActiveIdentity(51L, 0L, 19L)).thenReturn(1);
|
||||
when(mapper.findRoles(51L, 0L, 19L, "PLATFORM")).thenReturn(List.of("PLATFORM_ADMIN"));
|
||||
when(mapper.findPermissions(51L, 0L, 19L, "PLATFORM")).thenReturn(List.of(
|
||||
"platform:finance:recharge:review",
|
||||
"platform:finance:customer-account:adjust"));
|
||||
|
||||
var platformPermissions = service.currentPermissions(new AuthenticatedUser(51L, 0L, 0L, 19L,
|
||||
"platform-admin", "PLATFORM", "PLATFORM", java.util.Set.of()), "PLATFORM");
|
||||
|
||||
assertThat(platformPermissions).containsExactlyInAnyOrder(
|
||||
"platform:finance:recharge:review",
|
||||
"platform:finance:customer-account:adjust");
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsIncompleteCurrentIdentityAsBusinessError() {
|
||||
assertThatThrownBy(() -> service
|
||||
|
||||
Reference in New Issue
Block a user