优化采购实时编辑与权限,支持先到货后补报价、按批次补录照片和批量附件上传。更新验收报告模板及明细选择,增加验收发票独立管理和付款前置校验。完善 BOM 数据权限及 App 更新兼容性。
22 lines
2.7 KiB
JavaScript
22 lines
2.7 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {createHash} from 'node:crypto';
|
|
import {downloadLegacyPackage} from '../src/core/legacy-package-download.ts';
|
|
import {productionAppSigner,getOfficialPackage,officialAppInternalOrigin} from '../src/core/official-app-update.ts';
|
|
const bytes=Buffer.alloc(600000,7),hash=createHash('sha256').update(bytes).digest('hex');
|
|
const release={environment:'prod',packageName:'cn.cmvr.wms',versionCode:15,versionName:'1.0.3',sha256:hash,size:bytes.length,signerSha256:productionAppSigner,downloadPath:`/static/mobile/cmvr-wms-prod-v15-${hash}.apk`,notes:[]};
|
|
function files(initial){let content=initial;const calls=[];return {calls,cacheDirectory:'file:///cache/',async getInfoAsync(){return {exists:!!content,size:content?.length};},async deleteAsync(){content=undefined;},async readAsStringAsync(uri,options){return content.subarray(options.position,options.position+options.length).toString('base64');},createDownloadResumable(url,uri,options,progress){calls.push(url);return {async downloadAsync(){content=bytes;progress({totalBytesWritten:bytes.length});return {status:200,uri};},async pauseAsync(){}};}};}
|
|
test('legacy updates download inside the app using the selected company network and verify all bytes',async()=>{
|
|
const fs=files(),events=[],uri=await downloadLegacyPackage(release,officialAppInternalOrigin,fs,new AbortController().signal,(...event)=>events.push(event));
|
|
assert.equal(fs.calls[0],officialAppInternalOrigin+release.downloadPath);assert.match(uri,/^file:\/\/\/cache\/.*\.apk$/);assert.deepEqual(events.at(-1),['verifying',100]);
|
|
await downloadLegacyPackage(release,officialAppInternalOrigin,fs,new AbortController().signal,()=>{});assert.equal(fs.calls.length,1);
|
|
});
|
|
test('corrupt or cancelled compatibility downloads never return an installable file',async()=>{
|
|
await assert.rejects(downloadLegacyPackage(release,officialAppInternalOrigin,files(Buffer.alloc(bytes.length,8)),new AbortController().signal,()=>{}),/校验失败/);
|
|
const controller=new AbortController();controller.abort();const fs=files();await assert.rejects(downloadLegacyPackage(release,officialAppInternalOrigin,fs,controller.signal,()=>{}),/取消/);assert.equal(fs.calls.length,0);
|
|
await assert.rejects(downloadLegacyPackage(release,'https://other.example',files(),new AbortController().signal,()=>{}),/地址无效/);
|
|
});
|
|
test('official manifest requests can use the same internal connection without external Internet access',async()=>{
|
|
let requested;await getOfficialPackage(new AbortController().signal,undefined,async url=>{requested=url;return new Response(JSON.stringify(release));},officialAppInternalOrigin);assert.ok(requested.startsWith(officialAppInternalOrigin+'/static/mobile/'));
|
|
});
|