61 lines
2.2 KiB
JavaScript
61 lines
2.2 KiB
JavaScript
import assert from 'node:assert/strict'
|
|||
|
|
import { readFileSync } from 'node:fs'
|
||
|
|
import vm from 'node:vm'
|
||
|
|
import ts from '../miniapp/node_modules/typescript/lib/typescript.js'
|
||
|
|
|
||
|
|
function loadPage(relativePath, api) {
|
||
|
|
let page
|
||
|
|
const source = readFileSync(new URL(`../${relativePath}`, import.meta.url), 'utf8')
|
||
|
|
const executableSource = relativePath.endsWith('.ts')
|
||
|
|
? ts.transpileModule(source, {
|
||
|
|
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
||
|
|
}).outputText
|
||
|
|
: source
|
||
|
|
vm.runInNewContext(executableSource, {
|
||
|
|
exports: {},
|
||
|
|
module: { exports: {} },
|
||
|
|
require(request) {
|
||
|
|
if (request === '../../utils/api') return { default: api }
|
||
|
|
throw new Error(`未预期依赖:${request}`)
|
||
|
|
},
|
||
|
|
Page(config) { page = config },
|
||
|
|
wx: {},
|
||
|
|
console,
|
||
|
|
}, { filename: relativePath })
|
||
|
|
return page
|
||
|
|
}
|
||
|
|
|
||
|
|
const statusCalls = []
|
||
|
|
const declarationPage = loadPage('miniapp/pages/local-eligibility/local-eligibility.ts', {
|
||
|
|
get: async (url) => {
|
||
|
|
statusCalls.push(url)
|
||
|
|
return { verificationStatus: 'needs_evidence', eligibilityType: 'employment' }
|
||
|
|
},
|
||
|
|
})
|
||
|
|
assert.equal(typeof declarationPage.checkStatus, 'function', 'U62 必须实现资格状态查询')
|
||
|
|
await declarationPage.checkStatus.call({
|
||
|
|
setData(data) { this.data = { ...(this.data || {}), ...data } },
|
||
|
|
data: {},
|
||
|
|
})
|
||
|
|
assert.deepEqual(statusCalls, ['/local-eligibility'], 'U62 必须从当前用户资格接口读取状态')
|
||
|
|
|
||
|
|
const submitCalls = []
|
||
|
|
const supplementPage = loadPage('miniapp/pages/local-eligibility-supplement/local-eligibility-supplement.ts', {
|
||
|
|
post: async (url, data) => {
|
||
|
|
submitCalls.push([url, data])
|
||
|
|
return { verificationStatus: 'pending_review' }
|
||
|
|
},
|
||
|
|
})
|
||
|
|
assert.equal(typeof supplementPage.submitEligibility, 'function', 'U63 必须实现声明与提交审核链路')
|
||
|
|
await supplementPage.submitEligibility.call({
|
||
|
|
data: { eligibilityType: 'employment', selectedType: '', uploadedFileIds: [] },
|
||
|
|
setData() {},
|
||
|
|
})
|
||
|
|
assert.deepEqual(
|
||
|
|
submitCalls.map(([url]) => url),
|
||
|
|
['/local-eligibility/declaration', '/local-eligibility/submit'],
|
||
|
|
'无需补证时必须先声明,再提交审核',
|
||
|
|
)
|
||
|
|
|
||
|
|
console.log('Phase 04 local eligibility contracts passed')
|