修复(半自动履约): 登录取得CK后允许注入浏览器
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import test from 'node:test'
|
||||
|
||||
import {
|
||||
canCompleteSemiAutoTask,
|
||||
canInjectSemiAutoBrowser,
|
||||
} from '../src/utils/semi-auto-task-readiness.ts'
|
||||
|
||||
const root = dirname(fileURLToPath(import.meta.url))
|
||||
const adminPage = readFileSync(join(root, '../src/pages/admin/AdminSemiAutoTasksPage.tsx'), 'utf8')
|
||||
|
||||
const baseTask = {
|
||||
platform: 'huya' as const,
|
||||
loginStatus: 'authenticated',
|
||||
bindingPolicy: {
|
||||
bindingRequired: true,
|
||||
},
|
||||
bindingStatus: 'role_ready',
|
||||
credentialReady: true,
|
||||
credentialStatus: 'valid' as const,
|
||||
}
|
||||
|
||||
test('虎牙和微博登录并取得 CK 后即可注入浏览器', () => {
|
||||
for (const platform of ['huya', 'weibo'] as const) {
|
||||
assert.equal(canInjectSemiAutoBrowser({ ...baseTask, platform }), true)
|
||||
}
|
||||
assert.equal(canInjectSemiAutoBrowser({ ...baseTask, bindingStatus: 'not_started' }), true)
|
||||
})
|
||||
|
||||
test('没有可用 CK 时不能注入浏览器', () => {
|
||||
assert.equal(canInjectSemiAutoBrowser({ ...baseTask, credentialReady: false }), false)
|
||||
assert.equal(canInjectSemiAutoBrowser({ ...baseTask, loginStatus: 'waiting_login' }), false)
|
||||
assert.equal(canInjectSemiAutoBrowser({ ...baseTask, credentialStatus: 'invalid' }), false)
|
||||
assert.equal(canInjectSemiAutoBrowser({ ...baseTask, credentialStatus: 'error' }), false)
|
||||
})
|
||||
|
||||
test('完成履约仍要求必要的角色绑定已确认', () => {
|
||||
assert.equal(canCompleteSemiAutoTask(baseTask), false)
|
||||
assert.equal(canCompleteSemiAutoTask({ ...baseTask, bindingStatus: 'confirmed' }), true)
|
||||
assert.equal(
|
||||
canCompleteSemiAutoTask({
|
||||
...baseTask,
|
||||
bindingPolicy: { bindingRequired: false },
|
||||
bindingStatus: 'not_started',
|
||||
}),
|
||||
true,
|
||||
)
|
||||
})
|
||||
|
||||
test('注入按钮和完成按钮使用各自的门槛', () => {
|
||||
assert.equal(adminPage.match(/disabled=\{!canInjectSemiAutoBrowser\(/g)?.length, 2)
|
||||
assert.equal(adminPage.match(/disabled=\{!canCompleteSemiAutoTask\(/g)?.length, 1)
|
||||
assert.ok(!adminPage.includes('function taskCanUseCredential('))
|
||||
})
|
||||
Reference in New Issue
Block a user