feat(semi-auto): 客户链接按平台严格绑定,注入后统一由前端打开指定页
This commit is contained in:
@@ -1,17 +1,93 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import test from 'node:test'
|
||||
|
||||
import { isCustomerFulfillmentPath } from '../src/utils/customer-fulfillment-link.ts'
|
||||
import {
|
||||
buildCustomerFulfillmentPath,
|
||||
isCustomerFulfillmentPath,
|
||||
resolveCustomerPlatformRedirect,
|
||||
} from '../src/utils/customer-fulfillment-link.ts'
|
||||
|
||||
test('客户半自动履约入口:/c 命名空间整段命中', () => {
|
||||
test('客户半自动履约入口:/c 与 /d 命名空间整段命中', () => {
|
||||
assert.equal(isCustomerFulfillmentPath('/c/263123'), true)
|
||||
assert.equal(isCustomerFulfillmentPath('/c'), true)
|
||||
assert.equal(isCustomerFulfillmentPath('/c/a/b'), true)
|
||||
assert.equal(isCustomerFulfillmentPath('/d/263123'), true)
|
||||
assert.equal(isCustomerFulfillmentPath('/d'), true)
|
||||
assert.equal(isCustomerFulfillmentPath('/d/a/b'), true)
|
||||
assert.equal(isCustomerFulfillmentPath('/d/263123?from=chat'), true)
|
||||
assert.equal(isCustomerFulfillmentPath('/d/263123#section'), true)
|
||||
})
|
||||
|
||||
test('客户半自动履约入口不误伤相似前缀和其他路径', () => {
|
||||
assert.equal(isCustomerFulfillmentPath('/claim/x'), false)
|
||||
assert.equal(isCustomerFulfillmentPath('/customer/x'), false)
|
||||
assert.equal(isCustomerFulfillmentPath('/admin/c/1'), false)
|
||||
assert.equal(isCustomerFulfillmentPath('/admin/d/1'), false)
|
||||
assert.equal(isCustomerFulfillmentPath('/dd/1'), false)
|
||||
assert.equal(isCustomerFulfillmentPath('c/1'), false)
|
||||
assert.equal(isCustomerFulfillmentPath('d/1'), false)
|
||||
})
|
||||
|
||||
test('按平台生成客户链接:虎牙 /c、微博 /d', () => {
|
||||
assert.equal(
|
||||
buildCustomerFulfillmentPath('INTSA1794902905684_360848', 'huya'),
|
||||
'/c/INTSA1794902905684_360848',
|
||||
)
|
||||
assert.equal(
|
||||
buildCustomerFulfillmentPath('INTSA1794902905684_360848', 'weibo'),
|
||||
'/d/INTSA1794902905684_360848',
|
||||
)
|
||||
assert.equal(buildCustomerFulfillmentPath(' INTWB1 ', 'WEIBO'), '/d/INTWB1')
|
||||
assert.equal(buildCustomerFulfillmentPath('a/b', 'weibo'), '/d/a%2Fb')
|
||||
assert.equal(buildCustomerFulfillmentPath('', 'weibo'), '')
|
||||
assert.equal(buildCustomerFulfillmentPath('x', 'unknown'), '/c/x')
|
||||
})
|
||||
|
||||
test('严格绑定:路径平台不匹配时返回应跳转的平台', () => {
|
||||
assert.equal(resolveCustomerPlatformRedirect('huya', [{ platform: 'weibo' }]), 'weibo')
|
||||
assert.equal(resolveCustomerPlatformRedirect('weibo', [{ platform: 'huya' }]), 'huya')
|
||||
assert.equal(resolveCustomerPlatformRedirect('huya', [{ platform: 'huya' }]), null)
|
||||
assert.equal(resolveCustomerPlatformRedirect('weibo', [{ platform: 'weibo' }]), null)
|
||||
assert.equal(
|
||||
resolveCustomerPlatformRedirect('huya', [{ platform: 'huya' }, { platform: 'weibo' }]),
|
||||
null,
|
||||
)
|
||||
assert.equal(
|
||||
resolveCustomerPlatformRedirect('weibo', [{ platform: 'huya' }, { platform: 'weibo' }]),
|
||||
null,
|
||||
)
|
||||
assert.equal(resolveCustomerPlatformRedirect('huya', []), null)
|
||||
assert.equal(resolveCustomerPlatformRedirect(undefined, [{ platform: 'weibo' }]), null)
|
||||
assert.equal(resolveCustomerPlatformRedirect('huya', [{ platform: 'unknown' }]), null)
|
||||
assert.equal(
|
||||
resolveCustomerPlatformRedirect('huya', [{ platform: 'weibo' }, { platform: 'unknown' }]),
|
||||
'weibo',
|
||||
)
|
||||
})
|
||||
|
||||
test('客户页路由与严格绑定接线', async () => {
|
||||
const app = await readFile(new URL('../src/App.tsx', import.meta.url), 'utf8')
|
||||
const page = await readFile(
|
||||
new URL('../src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx', import.meta.url),
|
||||
'utf8',
|
||||
)
|
||||
|
||||
assert.match(app, /path="\/c\/:orderNo"/)
|
||||
assert.match(app, /expectedPlatform="huya"/)
|
||||
assert.match(app, /path="\/d\/:orderNo"/)
|
||||
assert.match(app, /expectedPlatform="weibo"/)
|
||||
assert.match(page, /resolveCustomerPlatformRedirect/)
|
||||
assert.match(page, /buildCustomerFulfillmentPath/)
|
||||
assert.match(page, /task\.platform === expectedPlatform/)
|
||||
})
|
||||
|
||||
test('开发 Mock 页按平台重新生成客户路径', async () => {
|
||||
const page = await readFile(
|
||||
new URL('../src/pages/admin/AdminDevMockPage.tsx', import.meta.url),
|
||||
'utf8',
|
||||
)
|
||||
assert.match(page, /buildCustomerFulfillmentPath/)
|
||||
assert.match(page, /semiAutoCustomerPath/)
|
||||
assert.match(page, /semiAutoCustomerUrl/)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user