Implement permission-driven home tab aligned with Android.
Load role-permission on first visit to drive menus, role-based layout, store card, and location reporting with account-scoped persistence and unit tests. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
52
suixinkanTests/RolePermissionMatcherTests.swift
Normal file
52
suixinkanTests/RolePermissionMatcherTests.swift
Normal file
@ -0,0 +1,52 @@
|
||||
//
|
||||
// RolePermissionMatcherTests.swift
|
||||
// suixinkanTests
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import suixinkan
|
||||
|
||||
/// 角色权限匹配测试。
|
||||
final class RolePermissionMatcherTests: XCTestCase {
|
||||
|
||||
private func makeItem(code: String, id: Int, name: String) -> RolePermissionResponse {
|
||||
RolePermissionResponse(
|
||||
role: RoleInfo(id: id, name: name, roleCode: code, notes: nil, permission: []),
|
||||
scenic: []
|
||||
)
|
||||
}
|
||||
|
||||
func testMatchByRoleCodeHasHighestPriority() {
|
||||
let list = [
|
||||
makeItem(code: "photographer", id: 41, name: "摄影师"),
|
||||
makeItem(code: "store_admin", id: 46, name: "店铺管理员"),
|
||||
]
|
||||
let matched = RolePermissionMatcher.match(
|
||||
in: list,
|
||||
roleCode: AppRoleCode.storeAdmin.rawValue,
|
||||
roleName: "摄影师"
|
||||
)
|
||||
XCTAssertEqual(matched?.role.roleCode, AppRoleCode.storeAdmin.rawValue)
|
||||
}
|
||||
|
||||
func testMatchByLegacyRoleIdWhenCodeMissing() {
|
||||
let list = [makeItem(code: "", id: 53, name: "景区管理员")]
|
||||
let matched = RolePermissionMatcher.match(
|
||||
in: list,
|
||||
roleCode: "",
|
||||
roleName: "",
|
||||
legacyRoleId: 53
|
||||
)
|
||||
XCTAssertEqual(matched?.role.id, 53)
|
||||
}
|
||||
|
||||
func testMatchByRoleNameWhenCodeAndLegacyMissing() {
|
||||
let list = [makeItem(code: "", id: 99, name: "剪辑师")]
|
||||
let matched = RolePermissionMatcher.match(
|
||||
in: list,
|
||||
roleCode: "",
|
||||
roleName: "剪辑师"
|
||||
)
|
||||
XCTAssertEqual(matched?.role.name, "剪辑师")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user