23 lines
2.3 KiB
JavaScript
23 lines
2.3 KiB
JavaScript
const fs=require('node:fs'),vm=require('node:vm'),assert=require('node:assert/strict');
|
|||
|
|
const ts=require('D:/Develop/HBuilderX/plugins/uniapp-uts-v1/node_modules/@dcloudio/uni-uts-v1/lib/typescript/lib/typescript.js');
|
||
|
|
class Json {constructor(values={}){Object.assign(this,values)} getString(k){return this[k]??null} getNumber(k){return this[k]??null} getBoolean(k){return this[k]??null} getJSON(k){return this[k]??null} getArray(k){return this[k]??null}}
|
||
|
|
let sent, reply;
|
||
|
|
function load(file){const out={};const source=fs.readFileSync(__dirname+'/../'+file,'utf8');vm.runInNewContext(ts.transpileModule(source,{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2020}}).outputText,{exports:out,UTSJSONObject:Json,require:p=>{
|
||
|
|
if(p.endsWith('api.uts'))return {getSession:()=>({token:'synthetic'}),requestJson:async(path,method,body)=>{sent=body;return reply ?? new Json({assessmentId:'1',revisionId:'2',submissionStatus:'accepted'})}};
|
||
|
|
if(p.endsWith('/assessment.uts'))return {assessmentApiPayload:p=>p,draftText:(p,k)=>typeof p[k]==='string'?p[k]:''};
|
||
|
|
if(p.endsWith('assessment-flow.uts'))return {assessmentRequestKey:()=> 'synthetic-key'};
|
||
|
|
if(p.endsWith('cities.uts'))return load('services/cities.uts');
|
||
|
|
if(p.endsWith('contribution.uts'))return {contributionLabel:v=>v};
|
||
|
|
return {};
|
||
|
|
}});return out;}
|
||
|
|
(async()=>{const service=load('packages/finance/services/records.uts');let checks=0;
|
||
|
|
for(const [city,provinceCode,cityCode]of[['广东省','440000',null],['北京市','110000',null],['台湾省','710000',null],['深圳市',undefined,'440300'],['南京市',undefined,null],['旧手填地区',undefined,null]]){
|
||
|
|
await service.createAssessment(new Json({type:'personal',city,documents:[],authorizations:[]}));
|
||
|
|
assert.equal(sent.form.city,city);assert.equal(sent.form.cityCode,cityCode);assert.equal(sent.form.provinceCode,provinceCode);checks+=3;
|
||
|
|
}
|
||
|
|
for(const [city,provinceCode,label]of[['广东省','440000','所在省份'],['深圳市',undefined,'城市']]){
|
||
|
|
reply=new Json({assessmentId:'1',revisionId:'2',revisionNo:1,type:'personal',status:'succeeded',form:new Json({city,provinceCode})});
|
||
|
|
const detail=await service.fetchAssessmentDetail('1','2');assert.equal(detail.fields[2].label,label);assert.equal(detail.fields[2].value,city);checks+=2;
|
||
|
|
}
|
||
|
|
console.log(`PASS: ${checks} region submit/detail checks`);})().catch(e=>{console.error(e);process.exitCode=1});
|