Gate record features and storage entry points with invitation guidance; enforce record access in the backend. Add homepage greetings, right-swipe profile dismissal, and move the smoking switch to settings. Simplify API base configuration and remove the unused legacy tab bar component.
61 lines
3.5 KiB
JavaScript
61 lines
3.5 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const path = require('node:path');
|
|
const createLoader = require('./load-module.cjs');
|
|
const {uploadReference} = require('../utils/file-media');
|
|
const id = '6083e119-6b26-441b-8b70-44d224366238';
|
|
const id2 = '7083e119-6b26-441b-8b70-44d224366238';
|
|
function client(extra = {}) {
|
|
const calls = [];
|
|
const load = createLoader({console, Promise, Date, wx: {
|
|
getStorageSync: () => 'token', hideLoading() {},
|
|
getFileInfo(o){o.success({size:100,digest:'a'.repeat(32)});},
|
|
request(o) { calls.push(o); o.success({statusCode:200, data:{success:true}}); }, ...extra
|
|
}});
|
|
return {...load(path.join(__dirname, '../utils/request.js')), calls};
|
|
}
|
|
test('business requests persist IDs, preserve order and distinguish clear from omitted fields', async () => {
|
|
const c = client();
|
|
await c.api.diaryUpdate({id:'diary',images:['https://we.sundynix.cn/api/files/'+id, id2]});
|
|
await c.api.albumUpdate({id:'album',cover:''});
|
|
await c.api.updateProfile({nickname:'test'});
|
|
await c.api.photoAdd({album_id:'album',path:'/api/files/'+id});
|
|
await c.api.checkinDo({id:'checkin',photo:id});
|
|
assert.deepEqual(JSON.parse(JSON.stringify(c.calls[0].data)), {id:'diary',imageFileIds:[id,id2]});
|
|
assert.equal(c.calls[1].data.coverFileId,'');
|
|
assert.equal('avatarFileId' in c.calls[2].data,false);
|
|
assert.equal(c.calls[3].data.fileId,id);
|
|
assert.equal(c.calls[4].data.photoFileId,id);
|
|
});
|
|
test('duplicate and ID-only uploads keep stable display URLs and file metadata', async () => {
|
|
const c = client({compressImage(o){o.fail();},uploadFile(o){o.success({statusCode:200,data:JSON.stringify({success:true,duplicate:true,file:{id,url:'https://minio/raw-object'}})});}});
|
|
const result = await c.uploadFileCompat({url:c.API_BASE+'/upload',filePath:'http://tmp/new.jpg'});
|
|
assert.equal(uploadReference(result),id);
|
|
assert.equal(result.duplicate,true);
|
|
assert.equal(result.file.url,'https://minio/raw-object');
|
|
assert.equal(c.getImageUrl(result.path),c.API_BASE+'/files/'+id);
|
|
assert.throws(()=>uploadReference({success:true,path:'http://tmp/new.jpg'}),/文件 ID/);
|
|
});
|
|
test('diary edit uploads HTTP temporary images, retains existing IDs and stops on upload failure', async () => {
|
|
let definition, saved, uploads=[];
|
|
const c = client();
|
|
const load = createLoader({console, Date, Promise, setTimeout(){}, Page(p){definition=p;}, wx:{showLoading(){},hideLoading(){},showToast(){}}}, {
|
|
'../../utils/request':{getImageUrl:c.getImageUrl,api:{async diaryUpdate(data){saved=data;}}}
|
|
});
|
|
load(path.join(__dirname,'../pages/diary_edit/diary_edit.js'));
|
|
const p = {...definition, data:{loading:false,form:{content:'text'},existingImages:[id],tempImages:[c.getImageUrl(id),'http://tmp/new.jpg']},setData(v){Object.assign(this.data,v);},async _uploadImage(v){uploads.push(v);return id2;}};
|
|
await p.submit();
|
|
assert.deepEqual(uploads,['http://tmp/new.jpg']);
|
|
assert.deepEqual(Array.from(saved.images),[id,id2]);
|
|
saved=null;p._uploadImage=async()=>{throw Error('network');};
|
|
await p.submit();assert.equal(saved,null);
|
|
});
|
|
|
|
test('media display keeps local assets and temporary paths without a backend directory prefix', () => {
|
|
const c = client();
|
|
assert.equal(c.getImageUrl('/images/default-avatar.png'), '/images/default-avatar.png');
|
|
assert.equal(c.getImageUrl('wxfile://tmp/photo.jpg'), 'wxfile://tmp/photo.jpg');
|
|
assert.equal(c.getImageUrl('http://tmp/photo.jpg'), 'http://tmp/photo.jpg');
|
|
assert.equal(c.getImageUrl(id), c.API_BASE+'/files/' + id);
|
|
});
|