92 lines
5.6 KiB
JavaScript
92 lines
5.6 KiB
JavaScript
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'/)
|
|
})
|
|
|
|
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'/)
|
|
assert.match(routes, /path: 'overseas-warehouse\/return-relabel\/create'[\s\S]*?props: \{ service: 'relabel', createPage: true \}[\s\S]*?permission: 'merchant:overseas-warehouse:return-order:create'/)
|
|
assert.match(services, /props\.createPage \? 'create' : 'list'/)
|
|
assert.match(services, /function returnToList\(\)/)
|
|
})
|
|
|
|
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, /labeling: '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="退货签收详情"/)
|
|
})
|
|
|
|
test('returns to the labeling list after a labeling application is submitted', () => {
|
|
assert.match(services, /ElMessage\.success\(`\$\{config\.value\.title\}提交成功`\)[\s\S]*?router\.push\(\{ name: 'overseas-labeling' \}\)/)
|
|
assert.match(services, /uploadReturnRelabelFile\([\s\S]*?router\.push\(\{ name: 'overseas-labeling' \}\)/)
|
|
})
|
|
|
|
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"/)
|
|
})
|
|
|
|
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"/)
|
|
})
|
|
|
|
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}'`))
|
|
})
|