gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb99cce69b99cce69|||PR Update calendar login and logout through session pushesAtlasb99cce69/tests/calendar30.mjs

5.9 KB

  1. // Login, identity switch and logout patch two standing tabs, without fetching a page.
  2. import {spawn} from 'node:child_process';
  3. import {mkdirSync,writeFileSync,rmSync} from 'node:fs';
  4. import {resolve,join} from 'node:path';
  5. import {launchBrowser,sleep} from './cdp.mjs';
  6. import {startIdent} from './identkit.mjs';
  7. const APP=resolve(process.env.TEST_APP||'.'), G=join(APP,'.scratch/calendar30'), PORT=Number(process.env.CALENDAR_GATE_PORT||8800), BASE='http://127.0.0.1:'+PORT;
  8. rmSync(G,{recursive:true,force:true});mkdirSync(G,{recursive:true});
  9. let ident,server,browser,log='',passed=0,failed=0,seq=0;
  10. const check=(s,v)=>{console.log((v?'ok ':'FAIL ')+s);v?passed++:failed++};
  11. const pages=[];
  12. try {
  13. ident=await startIdent({identDir:process.env.CALENDAR_GATE_IDENT_DIR||'/media/STORAGE/projects/WorldAPI/ident.worldapi.org',workDir:join(G,'ident'),port:Number(process.env.CALENDAR_GATE_IDENT_PORT||8801)});
  14. const alice=await ident.signIn('[email protected]'),bob=await ident.signIn('[email protected]'),key=await ident.registerApp(alice,'calendar30',[BASE]);
  15. server=spawn(join(APP,'bin/hybriel'),['project.hl'],{cwd:APP,env:{...process.env,CALENDAR_PORT:''+PORT,CALENDAR_WATCH:'0',CALENDAR_PUBLIC_URL:BASE,CALENDAR_STORAGE:join(G,'db'),CALENDAR_SESSIONS:join(G,'sessions')+'/',IDENT_URL:ident.base,IDENT_EXCHANGE_URL:ident.base,IDENT_API_KEY:key.key,IDENT_API_SECRET:key.secret},stdio:['ignore','pipe','pipe']});
  16. console.log('server PID '+server.pid+' ident PID '+ident.proc.pid);
  17. server.stdout.on('data',x=>log+=x);server.stderr.on('data',x=>log+=x);
  18. for(let i=0;;i++){try{if((await fetch(BASE)).ok)break}catch{}if(i>600)throw Error('boot '+log);await sleep(250)}
  19. // Prepare private data through ordinary callback + faces before opening the standing tabs.
  20. const cookies=[];
  21. for(const [who,title] of [[alice,'Alice private'],[bob,'Bob private']]){
  22. const code=await ident.selectorCode(who,key,BASE),r=await fetch(BASE+'/login/callback?ident_code='+code,{redirect:'manual'}),cookie=r.headers.get('set-cookie').split(';')[0];cookies.push(cookie);
  23. const date=new Date().toISOString().slice(0,10);
  24. const response=await fetch(BASE+'/__hl/emit',{method:'POST',headers:{'content-type':'application/json',cookie},body:JSON.stringify({t:'emit',i:++seq,event:'calSave',payload:[{title,allDay:true,startDate:date,endDate:'',place:'',notes:'',zone:'UTC',custom:false,reminders:[]},date,date]})});
  25. if((await response.json()).value?.error)throw Error('seed failed');
  26. }
  27. browser=await launchBrowser({debugPortRange:[8803,8803]});
  28. const a=await browser.newPage();pages.push(a);await a.send('Network.setCookie',{name:'calendarsid',value:cookies[0].split('=')[1],url:BASE});await a.goto(BASE);
  29. await a.waitFor('!!window.__hl?.socket && window.__hl.socket.readyState===1',{timeout:120000});
  30. // Sign out the established session before opening its second tab.
  31. await a.click('#logout');await a.waitFor('!document.querySelector("#logout")');
  32. const b=await browser.newPage();pages.push(b);await b.goto(BASE);await b.waitFor('!!window.__hl?.socket && window.__hl.socket.readyState===1',{timeout:120000});
  33. for(const p of pages)await p.evaluate('window.__calendar30Node=document.querySelector("month-view");window.__calendar30Requests=[]');
  34. // Observe all requests, including framework fetches; preserving a node alone would miss an in-shell page fetch.
  35. const requests=[],frames=[];
  36. for(const p of pages){await p.send('Network.enable');p.conn.onEvent(m=>{if(m.sessionId===p.sessionId&&m.method==='Network.requestWillBeSent')requests.push(m.params.request.url);if(m.sessionId===p.sessionId&&m.method==='Network.webSocketFrameSent')frames.push(m.params.response.payloadData)})}
  37. async function login(who){const code=await ident.selectorCode(who,key,BASE);await a.evaluate(`(()=>{const e=document.querySelector('#identcode');e.value=${JSON.stringify(code)};e.dispatchEvent(new Event('change',{bubbles:true}))})()`)}
  38. for(const [who,title,other] of [[alice,'Alice private','Bob private'],[bob,'Bob private','Alice private']]){
  39. await login(who);
  40. for(const [i,p] of pages.entries()){
  41. await p.waitFor(`document.querySelector('#month-days').textContent.includes(${JSON.stringify(title)})`,{timeout:30000});
  42. check(title+' tab '+i+' has only its own events',await p.evaluate(`!document.querySelector('#month-days').textContent.includes(${JSON.stringify(other)}) && !!document.querySelector('#settings-open')`));
  43. check(title+' tab '+i+' keeps its component',await p.evaluate('window.__calendar30Node===document.querySelector("month-view")'));
  44. }
  45. }
  46. await a.click('#month-days button.event');
  47. await a.waitFor('document.querySelector("#f-title").value==="Bob private"');
  48. await a.click('#event-cancel');
  49. await a.click('#logout');
  50. for(const [i,p] of pages.entries()){
  51. await p.waitFor('!document.querySelector("#settings-open") && !document.querySelector("#logout") && !document.querySelector("#month-days").textContent.includes("private")',{timeout:30000});
  52. check('logout tab '+i+' clears private data in place',await p.evaluate('window.__calendar30Node===document.querySelector("month-view") && document.querySelector("#f-title").value==="" && document.querySelector("#f-startdate").value===""'));
  53. }
  54. check('login/switch/logout fetched no page',!frames.some(f=>{try{return JSON.parse(f).event==='page'}catch{return false}})&&!requests.some(u=>{const x=new URL(u);return x.origin===BASE&&(x.pathname==='/'||/\/(navigate|page|values)$/.test(x.pathname))}));
  55. await login(alice);await a.waitFor('document.querySelector("#month-days").textContent.includes("Alice private")');check('second login restores Alice',true);
  56. }catch(e){check(e.stack,false)}finally{
  57. for(const p of pages)try{await p.close()}catch{}
  58. if(browser)await browser.close();
  59. if(server){server.kill('SIGTERM');await new Promise(r=>{if(server.exitCode!==null||server.signalCode!==null)return r();server.once('exit',r);setTimeout(r,5000)})}
  60. if(ident)await ident.stop();writeFileSync(join(G,'server.log'),log)
  61. }
  62. console.log(`${passed} passed, ${failed} failed`);process.exitCode=failed?1:0;

Branches

Latest commits

  • b99cce69|||PR Update calendar login and logout through session pushesAtlas
  • fff2f537Merge branch 'calendar31-lib' into mainAtlas
  • 07cde3dc|||PR keep worker records out of the repo; README vendor is day72Atlas
  • a753b0ab|||PR move shared calendar logic to libAtlas
  • b32a921dMerge branch 'vendor-day72' into mainAtlas
  • 60a0dd19|||PR Hybriel day72 (00c9dbb8) instead of the withdrawn day73Atlas
  • 53f5464dMerge branch 'calendar26-day73' into mainAtlas
  • 338499ec|||PR Keep reminder settings open during editing and rejected savesAtlas
  • ad9e8d59|||PR Use framework page and popover state, Hybriel day73Atlas
  • cab224a1Re-vendor calendar to verified Hybriel day73Atlas
  • f9b8f918Merge branch 'calendar-vendor-day61' into mainAtlas
  • 66341793|||PR Vendor Hybriel day61Atlas
  • 36fc596bMerge branch 'vendor-day59' into mainAtlas
  • b37cc1da|||PR Vendor Hybriel day59Atlas
  • 05665102Merge branch 'vendor-day56' into mainAtlas
  • 687296fb|||PR Vendor Hybriel day56Atlas
  • a6166d4eMerge branch 'hl-standard-3' into mainAtlas
  • 6d0eb3b0|||PR Calendar day add buttons only when signed in (Kunibert minor)Atlas
  • add4b499|||PR Make calendar day actions keyboard accessibleAtlas
  • 79e49b4dMerge branch 'hl-standard' into mainAtlas