修复 affiliate-dash 绑定状态一致性

This commit is contained in:
yml2213
2026-08-07 11:40:28 +08:00
parent 17acd65f28
commit dc3fd63b04
2 changed files with 411 additions and 111 deletions
@@ -0,0 +1,138 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import {
canReuseAffiliateDashBindSnapshot,
isAffiliateDashBindSnapshotStale,
} from './kuaishou-cloud-claim-service.js'
test('isAffiliateDashBindSnapshotStale detects bind uuid that belongs to old uid', () => {
assert.equal(
isAffiliateDashBindSnapshotStale(
{
bindUuid: 'bind-old',
bindUrl: 'https://dash.example/bind-old',
expectedGameAccount: '111',
gameAccount: '111',
},
'222',
),
true,
)
})
test('isAffiliateDashBindSnapshotStale treats unknown bind uid as stale', () => {
assert.equal(
isAffiliateDashBindSnapshotStale(
{
bindUuid: 'bind-unknown',
bindUrl: 'https://dash.example/bind-unknown',
},
'222',
),
true,
)
})
test('isAffiliateDashBindSnapshotStale keeps current uid bind snapshot', () => {
assert.equal(
isAffiliateDashBindSnapshotStale(
{
bindUuid: 'bind-current',
bindUrl: 'https://dash.example/bind-current',
expectedGameAccount: '222',
gameAccount: '222',
},
'222',
),
false,
)
})
test('canReuseAffiliateDashBindSnapshot reuses pending current uid bind', () => {
assert.equal(
canReuseAffiliateDashBindSnapshot(
{
bindUuid: 'bind-current',
bindUrl: 'https://dash.example/bind-current',
expectedGameAccount: '222',
gameAccount: '222',
bound: false,
bindMismatch: false,
},
'222',
),
true,
)
})
test('canReuseAffiliateDashBindSnapshot refuses old uid bind', () => {
assert.equal(
canReuseAffiliateDashBindSnapshot(
{
bindUuid: 'bind-old',
bindUrl: 'https://dash.example/bind-old',
expectedGameAccount: '111',
gameAccount: '111',
bound: false,
bindMismatch: false,
},
'222',
),
false,
)
})
test('canReuseAffiliateDashBindSnapshot refuses bound snapshot without bound account', () => {
assert.equal(
canReuseAffiliateDashBindSnapshot(
{
bindUuid: 'bind-current',
bindUrl: 'https://dash.example/bind-current',
expectedGameAccount: '222',
gameAccount: '222',
bound: true,
boundAccount: '',
bindMismatch: false,
},
'222',
),
false,
)
})
test('canReuseAffiliateDashBindSnapshot reuses verified matching bound account', () => {
assert.equal(
canReuseAffiliateDashBindSnapshot(
{
bindUuid: 'bind-current',
bindUrl: 'https://dash.example/bind-current',
expectedGameAccount: '222',
gameAccount: '222',
bound: true,
boundAccount: '222',
bindMismatch: false,
},
'222',
),
true,
)
})
test('canReuseAffiliateDashBindSnapshot refuses mismatched bound account', () => {
assert.equal(
canReuseAffiliateDashBindSnapshot(
{
bindUuid: 'bind-current',
bindUrl: 'https://dash.example/bind-current',
expectedGameAccount: '222',
gameAccount: '222',
bound: true,
boundAccount: '333',
bindMismatch: false,
},
'222',
),
false,
)
})