同步小程序与管理端更新,完善抽烟记录和解绑冷静期
This commit is contained in:
@@ -4,9 +4,7 @@ const fs = require('node:fs');
|
||||
const vm = require('node:vm');
|
||||
const path = require('node:path');
|
||||
function load(file, wx) {
|
||||
const context = { module: { exports: {} }, wx, console, Promise, Date, require(name) { return require(path.join(__dirname, '../utils', name)); } };
|
||||
vm.runInNewContext(fs.readFileSync(path.join(__dirname, '..', file), 'utf8'), context);
|
||||
return context.module.exports;
|
||||
return require('./load-module.cjs')({wx, console, Promise, Date})(path.join(__dirname, '..', file));
|
||||
}
|
||||
test('GET business parameters and POST bodies use clean paths with auth', async () => {
|
||||
const calls=[];
|
||||
@@ -40,10 +38,24 @@ test('failed homepage load ends the recent-record spinner',async()=>{
|
||||
let definition;
|
||||
const api={coupleInfo:async()=>{throw { _statusCode:404 };}};
|
||||
vm.runInNewContext(fs.readFileSync(path.join(__dirname,'../pages/index/index.js'),'utf8'),{
|
||||
Page(p){definition=p;},require(name){return name.endsWith('/request')?{api,getImageUrl:v=>v}:name.endsWith('/layout')?{getLayout:()=>({})}:{saveScrollPosition(){},getScrollPosition(){return 0;}};},
|
||||
Page(p){definition=p;},require(name){return name.endsWith('/page-cache')?{withDataCache:p=>p}:name.endsWith('/request')?{api,getImageUrl:v=>v}:name.endsWith('/layout')?{getLayout:()=>({})}:{saveScrollPosition(){},getScrollPosition(){return 0;}};},
|
||||
wx:{getStorageSync:()=> 'test-token'}, console:{error(){}}, Date, setTimeout
|
||||
});
|
||||
const page={...definition,data:{...definition.data},setData(data){Object.assign(this.data,data);}};
|
||||
await page.loadData();
|
||||
assert.equal(page.data.homeError,true);assert.equal(page.data.statsLoading,false);assert.equal(page.data.statsError,true);assert.equal(page._loadingData,false);
|
||||
});
|
||||
|
||||
test('unbound newcomer loads homepage records without requesting couple-only pets',async()=>{
|
||||
let definition;let petCalls=0;
|
||||
const api={coupleInfo:async()=>({not_bound:true,partner1:{nickname:'新用户'}}),timelineList:async()=>[],albumList:async()=>[],diaryList:async()=>({items:[],total:0}),songsList:async()=>[],checkinList:async()=>({items:[]}),petInfo:async()=>{petCalls++;throw Error('请先绑定情侣');}};
|
||||
vm.runInNewContext(fs.readFileSync(path.join(__dirname,'../pages/index/index.js'),'utf8'),{
|
||||
Page(p){definition=p;},require(name){return name.endsWith('/page-cache')?{withDataCache:p=>p}:name.endsWith('/request')?{api,getImageUrl:v=>v}:name.endsWith('/layout')?{getLayout:()=>({})}:name.endsWith('/journal')?{diaryEntry:v=>v}:{};},
|
||||
wx:{getStorageSync:()=>1,removeStorageSync(){}},console,Date,setTimeout
|
||||
});
|
||||
const page={...definition,data:{...definition.data,coupleId:99},setData(data){Object.assign(this.data,data);}};
|
||||
await page.loadData();
|
||||
assert.equal(petCalls,0);assert.equal(page.data.coupleId,null);
|
||||
assert.equal(page.data.homeError,false);assert.equal(page.data.statsError,false);assert.equal(page.data.statsLoading,false);
|
||||
assert.equal(page.data.recentDiary.length,0);assert.equal(page.data.stats.pet,0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user