Replace virtual payments with WeChat Pay API v3 and verify callbacks and order polling. Cache WeChat access tokens in Redis and write structured Zap logs. Support configurable capacity plans across the API, admin and mini program, with purchase snapshots and quota enforcement. Allow personal albums before binding and share them with the current partner. Update deployment configuration and domain routing.
28 lines
1.7 KiB
JavaScript
28 lines
1.7 KiB
JavaScript
const test=require('node:test');
|
|
const assert=require('node:assert/strict');
|
|
const path=require('node:path');
|
|
const loader=require('./load-module.cjs');
|
|
test('finite paid space uses its quota, zero is respected, unlimited is explicit',()=>{
|
|
const load=loader({wx:{},console},{'./request':{api:{}}});
|
|
const {quotaExceeded}=load(path.join(__dirname,'../utils/storage-guard.js'));
|
|
assert.equal(quotaExceeded({isVip:true,isUnlimited:false,quotaBytes:1024,usedBytes:1000},25),true);
|
|
assert.equal(quotaExceeded({is_vip:true,is_unlimited:false,quota_bytes:1024,used_bytes:1000},24),false);
|
|
assert.equal(quotaExceeded({isVip:true,isUnlimited:true,quotaBytes:0,usedBytes:9999},100),false);
|
|
assert.equal(quotaExceeded({quotaBytes:0,freeBytes:200,usedBytes:1},0),true);
|
|
});
|
|
test('storage page renders 1-cent plans and custom month/capacity values',async()=>{
|
|
let definition;
|
|
const info={freeBytes:200*1024*1024,quotaBytes:1024*1024*1024,usedBytes:512*1024*1024,isVip:true,isUnlimited:false,vipExpireAt:'2026-12-02',plans:[{key:'custom',name:'测试套餐',priceCents:1,quotaMb:1024,months:3}]};
|
|
const load=loader({Page(p){definition=p},wx:{},console},{'../../utils/request':{api:{storageInfo:async()=>info}}});
|
|
load(path.join(__dirname,'../pages/storage/storage.js'));
|
|
const page={...definition,data:{...definition.data},setData(d){Object.assign(this.data,d)}};
|
|
await page.loadInfo();
|
|
assert.equal(page.data.plans[0].priceText,'0.01');
|
|
assert.equal(page.data.plans[0].unit,'3个月');
|
|
assert.match(page.data.plans[0].description,/1.00 GB/);
|
|
assert.equal(page.data.percent,50);
|
|
assert.equal(page.data.isVip,true);
|
|
assert.equal(page.data.isUnlimited,false);
|
|
assert.equal(page.data.quotaText,'1.00 GB');
|
|
});
|