39 lines
1.5 KiB
TypeScript
39 lines
1.5 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?orderId=10&source=message')
|
||
|
|
})
|
||
|
|
|
||
|
|
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('')
|
||
|
|
})
|
||
|
|
})
|