抽离后台平台配置共享映射逻辑
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import {
|
||||
mapAdminCloudtentaclesSession,
|
||||
mapAdminKhhaoSourceConfig,
|
||||
mapAdminKhhaoSyncState,
|
||||
mapAdminKuaishouCloudFulfillmentSource,
|
||||
mapAdminKuaishouEticketSourceConfig,
|
||||
maskPhone,
|
||||
maskSecret,
|
||||
} from './admin-platform-config-mappers.js'
|
||||
|
||||
test('maskSecret preserves edges while hiding middle characters', () => {
|
||||
assert.equal(maskSecret('abcdef1234567890'), 'abcdef****567890')
|
||||
assert.equal(maskSecret('12345678'), '12****78')
|
||||
assert.equal(maskSecret(''), '')
|
||||
})
|
||||
|
||||
test('maskPhone hides middle digits for mobile numbers', () => {
|
||||
assert.equal(maskPhone('13812345678'), '138****5678')
|
||||
assert.equal(maskPhone('123456'), '123456')
|
||||
assert.equal(maskPhone(''), '')
|
||||
})
|
||||
|
||||
test('mapAdminKhhaoSourceConfig normalizes defaults and nested auto sync values', () => {
|
||||
assert.deepEqual(
|
||||
mapAdminKhhaoSourceConfig({
|
||||
enabled: true,
|
||||
baseUrl: ' https://admin.khhao.com ',
|
||||
username: ' user ',
|
||||
password: ' pass ',
|
||||
maxCaptchaAttempts: '0',
|
||||
autoSync: {
|
||||
enabled: true,
|
||||
intervalMinutes: '',
|
||||
pages: '0',
|
||||
pageSize: '50',
|
||||
},
|
||||
}),
|
||||
{
|
||||
enabled: true,
|
||||
baseUrl: 'https://admin.khhao.com',
|
||||
username: 'user',
|
||||
password: 'pass',
|
||||
maxCaptchaAttempts: 3,
|
||||
autoSync: {
|
||||
enabled: true,
|
||||
intervalMinutes: 3,
|
||||
pages: 2,
|
||||
pageSize: 50,
|
||||
},
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
test('mapAdminKhhaoSyncState normalizes watch orders and fallback values', () => {
|
||||
assert.deepEqual(
|
||||
mapAdminKhhaoSyncState({
|
||||
watchMode: '',
|
||||
fetchedCount: '8',
|
||||
watchOrders: [
|
||||
{
|
||||
platformOrderId: ' A1 ',
|
||||
shopId: ' S1 ',
|
||||
shopName: ' 店铺 ',
|
||||
itemTitle: ' 商品 ',
|
||||
payStatus: ' unpaid ',
|
||||
detectedAt: ' t1 ',
|
||||
lastSeenAt: ' t2 ',
|
||||
},
|
||||
],
|
||||
}),
|
||||
{
|
||||
syncFromCreatedAt: '',
|
||||
lastRunStartedAt: '',
|
||||
lastRunFinishedAt: '',
|
||||
lastRunStatus: '',
|
||||
lastErrorMessage: '',
|
||||
fetchedCount: 8,
|
||||
syncedCount: 0,
|
||||
ignoredCount: 0,
|
||||
watchMode: 'normal',
|
||||
watchOrders: [
|
||||
{
|
||||
platformOrderId: 'A1',
|
||||
shopId: 'S1',
|
||||
shopName: '店铺',
|
||||
itemTitle: '商品',
|
||||
payStatus: 'unpaid',
|
||||
detectedAt: 't1',
|
||||
lastSeenAt: 't2',
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
test('mapAdminKuaishouEticketSourceConfig maps shops and masks cookies', () => {
|
||||
assert.deepEqual(
|
||||
mapAdminKuaishouEticketSourceConfig(
|
||||
{ enabled: true, baseUrl: ' https://s.kwaixiaodian.com ' },
|
||||
[{ shopId: ' 1 ', kshopName: ' A店 ', cookie: 'cookie-abcdef123456', enabled: true }],
|
||||
),
|
||||
{
|
||||
enabled: true,
|
||||
baseUrl: 'https://s.kwaixiaodian.com',
|
||||
shops: [
|
||||
{
|
||||
shopId: '1',
|
||||
kshopName: 'A店',
|
||||
cookie: 'cookie-abcdef123456',
|
||||
cookieMasked: 'cookie****123456',
|
||||
hasCookie: true,
|
||||
userAvatar: '',
|
||||
enabled: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
test('mapAdminCloudtentaclesSession derives masked fields and token presence', () => {
|
||||
assert.deepEqual(
|
||||
mapAdminCloudtentaclesSession({
|
||||
token: 'abcdef1234567890',
|
||||
baseUrl: ' https://123.207.217.176 ',
|
||||
username: ' admin ',
|
||||
phone: '13812345678',
|
||||
loggedInAt: ' 2026-05-04T10:00:00.000Z ',
|
||||
deviceId: ' dev-1 ',
|
||||
deviceType: '2',
|
||||
}),
|
||||
{
|
||||
token: 'abcdef1234567890',
|
||||
tokenMasked: 'abcdef****567890',
|
||||
baseUrl: 'https://123.207.217.176',
|
||||
username: 'admin',
|
||||
phoneMasked: '138****5678',
|
||||
loggedInAt: '2026-05-04T10:00:00.000Z',
|
||||
deviceId: 'dev-1',
|
||||
deviceType: 2,
|
||||
hasToken: true,
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
test('mapAdminKuaishouCloudFulfillmentSource normalizes items and defaults', () => {
|
||||
assert.deepEqual(
|
||||
mapAdminKuaishouCloudFulfillmentSource({
|
||||
enabled: true,
|
||||
items: [
|
||||
{
|
||||
id: ' item-1 ',
|
||||
provider: '',
|
||||
platform: '',
|
||||
cloudSourceKey: '',
|
||||
cloudSkuId: '0',
|
||||
autoConsumeAfterDispatch: true,
|
||||
kuaishouConsumeShopId: ' ks1 ',
|
||||
notes: ' note ',
|
||||
},
|
||||
],
|
||||
}),
|
||||
{
|
||||
enabled: true,
|
||||
items: [
|
||||
{
|
||||
id: 'item-1',
|
||||
enabled: true,
|
||||
priority: 100,
|
||||
provider: 'khhao',
|
||||
platform: 'kuaishou',
|
||||
shopId: '',
|
||||
internalSkuCode: '',
|
||||
internalSkuName: '',
|
||||
externalSkuCode: '',
|
||||
externalItemId: '',
|
||||
externalSkuName: '',
|
||||
resolvedSkuName: '',
|
||||
cloudSourceKey: 'default',
|
||||
cloudSkuId: 0,
|
||||
cloudSkuName: '',
|
||||
vnKey: '',
|
||||
autoBuyEnabled: true,
|
||||
minAssetReserve: 0,
|
||||
autoReturnNumberAfterDispatch: false,
|
||||
autoConsumeAfterDispatch: true,
|
||||
kuaishouConsumeShopId: 'ks1',
|
||||
kuaishouConsumeShopName: '',
|
||||
notes: 'note',
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user