Files
suixinkan_uikit/suixinkanTests/RolePermissionMatcherTests.swift
汉秋 3b17b7f7f0 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>
2026-07-06 17:27:54 +08:00

53 lines
1.6 KiB
Swift

//
// 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, "剪辑师")
}
}