拆分腾讯会话纯函数与序列化逻辑
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import {
|
||||
normalizeLoginType,
|
||||
parseViewportSpec,
|
||||
} from './session-browser-config.js'
|
||||
import {
|
||||
buildArtifactsPayload,
|
||||
buildRedeemPayload,
|
||||
} from './session-payload.js'
|
||||
import {
|
||||
REDEEM_SUCCESS_AUTO_CLOSE_MS,
|
||||
resolveTencentSessionExpiresAt,
|
||||
@@ -23,3 +31,110 @@ test('resolveTencentSessionExpiresAt keeps redeemed auto-close deadline once arm
|
||||
autoCloseAt,
|
||||
)
|
||||
})
|
||||
|
||||
test('normalizeLoginType collapses aliases and falls back to qq', () => {
|
||||
assert.equal(normalizeLoginType(' qc '), 'qq')
|
||||
assert.equal(normalizeLoginType('wechat'), 'wx')
|
||||
assert.equal(normalizeLoginType('unknown'), 'qq')
|
||||
assert.equal(normalizeLoginType(''), 'qq')
|
||||
})
|
||||
|
||||
test('parseViewportSpec accepts valid viewport strings and rejects invalid values', () => {
|
||||
assert.deepEqual(parseViewportSpec('1920x1080'), { width: 1920, height: 1080 })
|
||||
assert.deepEqual(parseViewportSpec('1920x1080x24'), { width: 1920, height: 1080 })
|
||||
assert.equal(parseViewportSpec('799x600'), null)
|
||||
assert.equal(parseViewportSpec('broken'), null)
|
||||
})
|
||||
|
||||
test('buildRedeemPayload strips internal paths unless explicitly requested', () => {
|
||||
const redeem = {
|
||||
code: 'ABC123',
|
||||
area: '微信区',
|
||||
proofMode: 'basic',
|
||||
attempts: [
|
||||
{
|
||||
attempt: 1,
|
||||
redeem: { success: false, message: '验证码错误' },
|
||||
},
|
||||
],
|
||||
final: {
|
||||
attempt: 2,
|
||||
redeem: { success: true, message: '兑换成功' },
|
||||
},
|
||||
finishedAt: '2026-04-14T09:40:00.000Z',
|
||||
screenshotPath: '/tmp/redeem.png',
|
||||
htmlPath: '/tmp/redeem.html',
|
||||
resultPath: '/tmp/redeem.json',
|
||||
}
|
||||
|
||||
assert.deepEqual(buildRedeemPayload(redeem), {
|
||||
code: 'ABC123',
|
||||
area: '微信区',
|
||||
proofMode: 'basic',
|
||||
attempts: [
|
||||
{
|
||||
attempt: 1,
|
||||
redeem: { success: false, message: '验证码错误' },
|
||||
},
|
||||
],
|
||||
final: {
|
||||
attempt: 2,
|
||||
redeem: { success: true, message: '兑换成功' },
|
||||
},
|
||||
finishedAt: '2026-04-14T09:40:00.000Z',
|
||||
})
|
||||
|
||||
assert.deepEqual(buildRedeemPayload(redeem, { includeInternalPaths: true }), {
|
||||
code: 'ABC123',
|
||||
area: '微信区',
|
||||
proofMode: 'basic',
|
||||
attempts: [
|
||||
{
|
||||
attempt: 1,
|
||||
redeem: { success: false, message: '验证码错误' },
|
||||
},
|
||||
],
|
||||
final: {
|
||||
attempt: 2,
|
||||
redeem: { success: true, message: '兑换成功' },
|
||||
},
|
||||
finishedAt: '2026-04-14T09:40:00.000Z',
|
||||
screenshotPath: '/tmp/redeem.png',
|
||||
htmlPath: '/tmp/redeem.html',
|
||||
resultPath: '/tmp/redeem.json',
|
||||
})
|
||||
})
|
||||
|
||||
test('buildArtifactsPayload only exposes internal artifact paths in debug mode', () => {
|
||||
const session = {
|
||||
sessionDir: '/tmp/session',
|
||||
qrImagePath: '/tmp/session/qq-qr.png',
|
||||
qrImageBase64: 'base64data',
|
||||
lastReview: {
|
||||
screenshotPath: '/tmp/session/review.png',
|
||||
},
|
||||
lastRedeem: {
|
||||
screenshotPath: '/tmp/session/redeem.png',
|
||||
htmlPath: '/tmp/session/redeem.html',
|
||||
resultPath: '/tmp/session/redeem.json',
|
||||
},
|
||||
}
|
||||
|
||||
assert.deepEqual(buildArtifactsPayload(session), {
|
||||
hasQrImage: true,
|
||||
hasReviewScreenshot: true,
|
||||
hasScreenshot: true,
|
||||
})
|
||||
|
||||
assert.deepEqual(buildArtifactsPayload(session, { includeInternalPaths: true }), {
|
||||
hasQrImage: true,
|
||||
hasReviewScreenshot: true,
|
||||
hasScreenshot: true,
|
||||
sessionDir: '/tmp/session',
|
||||
qrImagePath: '/tmp/session/qq-qr.png',
|
||||
screenshotPath: '/tmp/session/redeem.png',
|
||||
htmlPath: '/tmp/session/redeem.html',
|
||||
resultPath: '/tmp/session/redeem.json',
|
||||
reviewScreenshotPath: '/tmp/session/review.png',
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user