54 lines
2.3 KiB
TypeScript
54 lines
2.3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { buildSystemMessageActionPath } from './system-message-action'
|
|
|
|
describe('buildSystemMessageActionPath', () => {
|
|
it('keeps safe review action paths with order and review query parameters', () => {
|
|
expect(buildSystemMessageActionPath({
|
|
actionPath: '/orders?orderId=10&reviewId=99&orderItemId=1001',
|
|
businessType: 'ORDER_ARTIST_REVIEW',
|
|
businessId: 99
|
|
})).toBe('/orders?orderId=10&reviewId=99&orderItemId=1001')
|
|
})
|
|
|
|
it('uses reviewId fallback for review reminder messages when actionPath is absent', () => {
|
|
expect(buildSystemMessageActionPath({
|
|
businessType: 'ORDER_ARTIST_REVIEW',
|
|
businessId: 99
|
|
})).toBe('/orders?reviewId=99&source=message')
|
|
})
|
|
|
|
it('opens pending reviews when a review reminder has no business id', () => {
|
|
expect(buildSystemMessageActionPath({
|
|
businessType: 'ORDER_ARTIST_REVIEW'
|
|
})).toBe('/orders?review=pending&source=message')
|
|
})
|
|
|
|
it('uses orderId fallback for generic order messages', () => {
|
|
expect(buildSystemMessageActionPath({
|
|
businessType: 'ORDER',
|
|
businessId: 10
|
|
})).toBe('/orders/10')
|
|
})
|
|
|
|
it('uses after-sale fallback for after-sale messages', () => {
|
|
expect(buildSystemMessageActionPath({
|
|
businessType: 'AFTER_SALE',
|
|
businessId: 10
|
|
})).toBe('/after-sales?orderId=10&source=message')
|
|
})
|
|
|
|
it('keeps safe order detail and after-sale action paths', () => {
|
|
expect(buildSystemMessageActionPath({ actionPath: '/orders/10' })).toBe('/orders/10')
|
|
expect(buildSystemMessageActionPath({ actionPath: '/after-sales?orderId=10' })).toBe('/after-sales?orderId=10')
|
|
expect(buildSystemMessageActionPath({ actionPath: '/after-sale/apply?orderId=10&orderItemId=99' })).toBe('/after-sale/apply?orderId=10&orderItemId=99')
|
|
expect(buildSystemMessageActionPath({ actionPath: '/service-progress?orderId=10' })).toBe('/service-progress?orderId=10')
|
|
})
|
|
|
|
it('rejects unsafe or backend-only action paths', () => {
|
|
expect(buildSystemMessageActionPath({ actionPath: '//evil.example/orders' })).toBe('')
|
|
expect(buildSystemMessageActionPath({ actionPath: 'https://evil.example/orders' })).toBe('')
|
|
expect(buildSystemMessageActionPath({ actionPath: '/admin/users' })).toBe('')
|
|
expect(buildSystemMessageActionPath({ actionPath: '/orders-admin' })).toBe('')
|
|
})
|
|
})
|