简化履约匹配并支持mock订单测试

This commit is contained in:
yml
2026-05-27 12:55:44 +08:00
parent e8010728a4
commit dd6776c4e4
21 changed files with 1892 additions and 683 deletions
@@ -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')
})