Files
client-web/src/modules/overseas-warehouse/permissions.test.mjs
T

89 lines
5.4 KiB
JavaScript
Raw Normal View History

2026-09-17 18:32:43 +08:00
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
const routes = readFileSync(new URL('./routes.ts', import.meta.url), 'utf8')
const services = readFileSync(new URL('./views/WarehouseServiceView.vue', import.meta.url), 'utf8')
const returns = readFileSync(new URL('./views/ReturnOrdersView.vue', import.meta.url), 'utf8')
const contracts = readFileSync(new URL('../tenant-management/contracts.ts', import.meta.url), 'utf8')
test('protects every overseas warehouse page with its independent list permission', () => {
for (const permission of [
'merchant:overseas-warehouse:relabel:list',
'merchant:overseas-warehouse:transfer:list',
'merchant:overseas-warehouse:discard:list',
'merchant:overseas-warehouse:return-order:list',
'merchant:overseas-warehouse:return-inventory:list',
]) assert.match(routes, new RegExp(`permission: '${permission}'`))
assert.doesNotMatch(routes, /permission: 'dashboard:view'/)
})
2026-09-18 16:48:35 +08:00
test('opens labeling and return relabeling on dedicated protected create pages', () => {
assert.match(routes, /path: 'overseas-warehouse\/labeling\/create'[\s\S]*?props: \{ service: 'labeling', createPage: true \}[\s\S]*?permission: 'merchant:overseas-warehouse:relabel:create'/)
2026-09-21 11:17:13 +08:00
assert.match(routes, /path: 'overseas-warehouse\/return-relabel\/create'[\s\S]*?ReturnOrdersView\.vue'[\s\S]*?props: \{ createPage: true \}[\s\S]*?title: '新建退货预报'[\s\S]*?permission: 'merchant:overseas-warehouse:return-order:create'/)
2026-09-18 16:48:35 +08:00
assert.match(services, /props\.createPage \? 'create' : 'list'/)
assert.match(services, /function returnToList\(\)/)
2026-09-21 11:17:13 +08:00
assert.match(returns, /props\.createPage/)
assert.match(returns, /class="return-create-surface"/)
2026-09-18 16:48:35 +08:00
})
test('opens warehouse service and return receipt details as dedicated protected workspace pages', () => {
assert.match(routes, /path: 'overseas-warehouse\/labeling\/:detailNo\/detail'[\s\S]*?name: 'overseas-labeling-detail'[\s\S]*?props: \{ service: 'labeling', detailPage: true \}[\s\S]*?permission: 'merchant:overseas-warehouse:relabel:list'/)
assert.match(routes, /path: 'overseas-warehouse\/return-relabel\/:returnNo\/detail'[\s\S]*?name: 'overseas-return-relabel-detail'[\s\S]*?props: \{ detailPage: true \}[\s\S]*?permission: 'merchant:overseas-warehouse:return-order:list'/)
assert.match(routes, /path: 'overseas-warehouse\/storage-transfer\/:detailNo\/detail'[\s\S]*?name: 'overseas-storage-transfer-detail'[\s\S]*?props: \{ service: 'transfer', detailPage: true \}/)
assert.match(routes, /path: 'overseas-warehouse\/cargo-disposal\/:detailNo\/detail'[\s\S]*?name: 'overseas-cargo-disposal-detail'[\s\S]*?props: \{ service: 'disposal', detailPage: true \}/)
assert.match(services, /name: 'overseas-labeling-detail'/)
assert.match(services, /transfer: 'overseas-storage-transfer-detail'/)
assert.match(services, /disposal: 'overseas-cargo-disposal-detail'/)
assert.match(services, /class="warehouse-detail-error"/)
assert.match(returns, /name: 'overseas-return-relabel-detail'/)
assert.doesNotMatch(returns, /title="退货签收详情"/)
})
2026-09-17 18:32:43 +08:00
test('keeps overseas warehouse writes behind operation-specific button permissions', () => {
for (const permission of [
'merchant:overseas-warehouse:relabel:create',
'merchant:overseas-warehouse:relabel:files',
'merchant:overseas-warehouse:relabel:confirm',
'merchant:overseas-warehouse:transfer:create',
'merchant:overseas-warehouse:transfer:confirm',
'merchant:overseas-warehouse:discard:create',
'merchant:overseas-warehouse:discard:cancel',
]) assert.match(services, new RegExp(permission))
assert.match(services, /v-if="canCreate" type="primary" @click="openCreate"/)
assert.match(services, /canManageRelabelFiles && props\.service === 'labeling'/)
assert.match(services, /canConfirmTransfer && props\.service === 'transfer'/)
assert.match(services, /canCancelDiscard && props\.service === 'disposal'/)
assert.match(returns, /merchant:overseas-warehouse:return-order:create/)
assert.match(returns, /v-if="canCreate" type="primary" @click="openCreate"/)
})
2026-09-19 17:02:11 +08:00
test('keeps all four overseas warehouse create buttons in the shared left-aligned table toolbar', () => {
for (const service of ['labeling', 'transfer', 'disposal']) {
assert.match(routes, new RegExp(`props: \\{ service: '${service}' \\}`))
}
assert.match(services, /<DataTable[\s\S]*?<template #toolbar-actions><el-button v-if="canCreate"/)
assert.match(returns, /<DataTable[\s\S]*?<template #toolbar-actions><el-button v-if="canCreate"/)
})
2026-09-17 18:32:43 +08:00
test('publishes all overseas operation permissions in the enterprise role editor', () => {
for (const permission of [
'merchant:overseas-warehouse:last-mile-order:list',
'merchant:overseas-warehouse:relabel:list',
'merchant:overseas-warehouse:relabel:create',
'merchant:overseas-warehouse:relabel:files',
'merchant:overseas-warehouse:relabel:confirm',
'merchant:overseas-warehouse:transfer:list',
'merchant:overseas-warehouse:transfer:create',
'merchant:overseas-warehouse:transfer:confirm',
'merchant:overseas-warehouse:discard:list',
'merchant:overseas-warehouse:discard:create',
'merchant:overseas-warehouse:discard:cancel',
'merchant:overseas-warehouse:return-order:list',
'merchant:overseas-warehouse:return-order:create',
'merchant:overseas-warehouse:return-order:relabel',
'merchant:overseas-warehouse:return-inventory:list',
]) assert.match(contracts, new RegExp(`code: '${permission}'`))
})