account-binding-deploy.test.mjs 1.4 KB

123456789101112131415161718192021222324
  1. import test from 'node:test';
  2. import assert from 'node:assert/strict';
  3. import {patchAccountBinding} from '../../scripts/deploy-account-binding.mjs';
  4. const base=`
  5. function attachWorkshopHandlers(app){const meta={attribution:{participantName:p.participant.name,participantKey:'x'}};}
  6. async function runDatabaseFunction(name,request,response,DATA,confirmationHtml){
  7. if(name==='ksfConfirmationPage'){
  8. return response.type('html').send(confirmationHtml);
  9. }
  10. const actor=await app.authenticate(request.headers);
  11. return response.json({result:await app.dispatch(name,{},actor)});
  12. }
  13. async function handler(request,response){return runDatabaseFunction("ksfStartWorkshopSession",request,response,{},'');}
  14. `;
  15. test('补丁保留现网独立包装,只添加账号关联模块;不带入其他bootstrap调用',()=>{
  16. const code=patchAccountBinding(base);
  17. assert.ok(code.includes("attachAccountBindingHandlers(app,{store,settings});"));
  18. assert.ok(!code.includes('attachBoardActionHandlers(app'));assert.ok(!code.includes('attachMemberGroupHandlers(app'));
  19. assert.ok(code.includes("accountProfileKey:p.participant.key"));assert.equal(patchAccountBinding(code),code);
  20. new Function(code);
  21. });
  22. test('缺少精确补丁锚点时在任何远程写入前停止',()=>{
  23. assert.throws(()=>patchAccountBinding(base.replace("if(name==='ksfConfirmationPage')", "if(name==='another')")),/BASELINE/);
  24. });