完成Salon SIT整改并清理旧接口
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { BUY_NOW_MODE, getBuyNowProductIdFromQuery, isBuyNowCartItem } from './buy-now'
|
||||
|
||||
describe('buy-now checkout mode', () => {
|
||||
it('reads the target product id only when cart query is in buyNow mode', () => {
|
||||
expect(getBuyNowProductIdFromQuery({ mode: BUY_NOW_MODE, productId: '1001' })).toBe('1001')
|
||||
expect(getBuyNowProductIdFromQuery({ mode: 'cart', productId: '1001' })).toBe('')
|
||||
})
|
||||
|
||||
it('uses the first query value when vue-router provides array values', () => {
|
||||
expect(getBuyNowProductIdFromQuery({ mode: [BUY_NOW_MODE], productId: ['2002', '3003'] })).toBe('2002')
|
||||
})
|
||||
|
||||
it('matches numeric and string product ids for cart selection', () => {
|
||||
expect(isBuyNowCartItem(1001, '1001')).toBe(true)
|
||||
expect(isBuyNowCartItem('1002', '1001')).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -1,15 +0,0 @@
|
||||
export const BUY_NOW_MODE = 'buyNow'
|
||||
|
||||
type QueryValue = string | string[] | null | undefined
|
||||
|
||||
const firstQueryValue = (value: QueryValue) => Array.isArray(value) ? value[0] : value
|
||||
|
||||
export const getBuyNowProductIdFromQuery = (query: Record<string, unknown>) => {
|
||||
const mode = firstQueryValue(query.mode as QueryValue)
|
||||
const productId = firstQueryValue(query.productId as QueryValue)
|
||||
return mode === BUY_NOW_MODE && productId ? String(productId) : ''
|
||||
}
|
||||
|
||||
export const isBuyNowCartItem = (itemProductId: unknown, buyNowProductId: string) => {
|
||||
return Boolean(buyNowProductId) && String(itemProductId || '') === String(buyNowProductId)
|
||||
}
|
||||
@@ -21,7 +21,7 @@ describe('request signature', () => {
|
||||
const config = {
|
||||
method: 'post',
|
||||
baseURL: '/api',
|
||||
url: '/order/checkout-preview',
|
||||
url: '/order/42/quote/reply',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -36,7 +36,7 @@ describe('request signature', () => {
|
||||
const payloadHash = createHash('sha256').update(JSON.stringify({ items: [] })).digest('hex')
|
||||
const canonical = [
|
||||
'POST',
|
||||
'/order/checkout-preview',
|
||||
'/order/42/quote/reply',
|
||||
'1700000000000',
|
||||
'1700000000000-fallback-id',
|
||||
payloadHash
|
||||
|
||||
Reference in New Issue
Block a user