简化履约匹配并支持mock订单测试
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import {
|
||||
normalizeCloudtentaclesMatchName,
|
||||
resolveCloudtentaclesSkuByProductName,
|
||||
} from './cloudtentacles-name-match-service.js'
|
||||
|
||||
test('normalizeCloudtentaclesMatchName normalizes punctuation and spaces', () => {
|
||||
assert.equal(
|
||||
normalizeCloudtentaclesMatchName(' 荣耀勋章礼包(30个) '),
|
||||
normalizeCloudtentaclesMatchName('荣耀勋章礼包(30个)'),
|
||||
)
|
||||
})
|
||||
|
||||
test('resolveCloudtentaclesSkuByProductName matches SKU name with logged-in sources', async () => {
|
||||
const result = await resolveCloudtentaclesSkuByProductName('荣耀勋章礼包(30个)', {
|
||||
listCloudtentaclesSources: () => ({
|
||||
enabled: true,
|
||||
sources: [
|
||||
{
|
||||
key: 'account-a',
|
||||
label: '账号 A',
|
||||
enabled: true,
|
||||
baseUrl: 'https://cloud.example.com',
|
||||
deviceId: '-',
|
||||
deviceType: 0,
|
||||
},
|
||||
],
|
||||
}),
|
||||
getCloudtentaclesSessionStateByKey: () => ({
|
||||
token: 'token-a',
|
||||
baseUrl: 'https://cloud.example.com',
|
||||
username: 'user-a',
|
||||
phone: '',
|
||||
loggedInAt: '2026-05-27T12:00:00.000Z',
|
||||
deviceId: '-',
|
||||
deviceType: 0,
|
||||
}),
|
||||
listCloudtentaclesSku: async () => ({
|
||||
baseUrl: 'https://cloud.example.com',
|
||||
itemCount: 1,
|
||||
rawItems: [],
|
||||
items: [
|
||||
{
|
||||
id: 74,
|
||||
name: '荣耀勋章礼包(30个)',
|
||||
inventory: 13837,
|
||||
price: 300,
|
||||
},
|
||||
],
|
||||
}),
|
||||
})
|
||||
|
||||
assert.equal(result?.cloudSkuId, 74)
|
||||
assert.equal(result?.cloudSkuName, '荣耀勋章礼包(30个)')
|
||||
assert.deepEqual(result?.cloudSourceKeys, ['account-a'])
|
||||
assert.equal(result?.matchMode, 'cloudtentacles_name')
|
||||
})
|
||||
Reference in New Issue
Block a user