Files
past-go/weapp/tests/storage-tiers.test.cjs
T
Blizzard 8be6d9b1ab feat: add account deletion, announcements and subscription renewal
Support personal records and persistent smoking visibility. Add upload quota preflight, file cleanup, privacy entry, image caching and revision-based page refresh across the backend, admin and mini program.
2026-11-03 22:06:47 +08:00

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:{getStorageSync:()=> 'user'},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');
});