Files
mgm-daylight-mcrm-mobile-ios/tests/bookingSharerMigration.test.mjs
2026-09-16 10:43:59 +08:00

36 lines
2.0 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {readFile} from 'node:fs/promises';
const source=await readFile(new URL('../booking/newBooking/newBooking.vue',import.meta.url),'utf8');
const script=source.match(/<script>([\s\S]*?)<\/script>/)[1]
.replace(/import[\s\S]*?from\s+['"][^'"]+['"];?[^\n]*/g,'').replace('export default','return');
function setup() {
let stored,scheduled,delay;
const calls=[];
const page=new Function('uni','playerLookup','setTimeout','clearTimeout',script)(
{getStorageSync:()=>structuredClone(stored),setStorageSync:(k,v)=>stored=structuredClone(v),
showLoading(){},hideLoading(){},$u:{toast(){}}},
async params=>{calls.push(params);return {success:true,data:{englishName:'Original Name',tierName:'Gold'}};},
(fn,ms)=>{scheduled=fn;delay=ms;return 1;},()=>{});
const vm={modelBooking:{sharerList:[{playerId:'80001',name:'',tierName:''}]},
playerData:{playerId:'90001'},userData:{userId:'1'},$t:k=>k,currentTask:null,getPlayerTimer:null};
for(const [k,fn] of Object.entries(page.methods))vm[k]=fn.bind(vm);
return {vm,calls,run:()=>scheduled(),delay:()=>delay};
}
test('Daylight delayed lookup and tier fill survive; editing resolved name clears only player ID',async()=>{
const {vm,calls,run,delay}=setup();
await vm.getPlayer(0);assert.equal(delay(),800);assert.equal(calls.length,0);
await run();assert.equal(calls[0].playerId,'80001');
const item=vm.modelBooking.sharerList[0];
assert.equal(item.name,'Original Name');assert.equal(item.tierName,'Gold');
await vm.getPlayerName(0);assert.equal(item.playerId,'80001');
item.name='Edited Name';await vm.getPlayerName(0);
assert.equal(item.playerId,'');assert.equal(item.name,'Edited Name');
});
test('source length threshold is retained for partial IDs',async()=>{
const {vm,run}=setup();await vm.getPlayer(0);await run();
const item=vm.modelBooking.sharerList[0];item.name='Edited Name';item.playerId='1234';
await vm.getPlayerName(0);assert.equal(item.playerId,'1234');
item.playerId='12345';await vm.getPlayerName(0);assert.equal(item.playerId,'');
});