Inherit email link addresses from hosting and proxy settings
Magent CI/CD / verify (push) Successful in 2m2s
Magent CI/CD / deploy-prod (push) Skipped
Magent CI/CD / deploy-beta (push) Skipped

This commit is contained in:
2026-09-11 22:46:46 +12:00
parent 4f7853b17b
commit 956fb3ecb1
13 changed files with 141 additions and 18 deletions
+24
View File
@@ -0,0 +1,24 @@
const assert = require('node:assert/strict');
const { chromium } = require(process.env.PLAYWRIGHT_PACKAGE || 'playwright');
const base = process.env.REVIEW_BASE || 'http://localhost:3114';
(async()=>{const browser=await chromium.launch();try{
const context=await browser.newContext();await context.addCookies([{name:'magent_logged_in',value:'1',url:base}]);
const configs={recaps:{enabled:false,day:2,hour:9,public_url:'https://public.example.test'},newsletters:{enabled:false,weekday:4,hour:9,limit_titles:12,intro:'',revision:1,public_url:'https://public.example.test'}};const writes=[];
await context.route('**/api/**',async route=>{const req=route.request(),path=new URL(req.url()).pathname;
if(path==='/api/auth/me')return route.fulfill({json:{username:'Admin',role:'admin'}});
const key=path==='/api/admin/email-recaps'?'recaps':path==='/api/admin/newsletters'?'newsletters':null;
if(key){if(req.method()==='PUT'){const data=req.postDataJSON();assert(!Object.hasOwn(data,'public_url'));writes.push(key);Object.assign(configs[key],data);return route.fulfill({json:configs[key]});}
return route.fulfill({json:{settings:configs[key],ready:true,detail:'Ready',months:['2026-08'],editions:[],deliveries:[],total:0,subscribers:0,worker_enabled:true}});}
return route.fulfill({json:{}});
});
const page=await context.newPage();const errors=[];page.on('pageerror',e=>errors.push(e.message));
for(const width of [1440,390]){await page.setViewportSize({width,height:950});for(const key of ['recaps','newsletters']){
await page.goto(base+'/admin/'+key);
if(key==='newsletters')await page.getByRole('button',{name:'Weekly schedule',exact:true}).click();
const input=page.locator(key==='recaps'?'#recap-public-url':'#newsletter-public-url');await input.waitFor();assert(await input.evaluate(e=>e.readOnly));assert.equal(await input.inputValue(),'https://public.example.test');
assert(await page.getByRole('link',{name:'Hosting & proxy',exact:true}).count());assert(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth));
if(key==='recaps')await page.getByLabel('Day of the month').selectOption(configs[key].day===2?'3':'2');else await page.locator('#newsletter-weekday').selectOption(configs[key].weekday===4?'5':'4');
await page.getByRole('button',{name:key==='recaps'?'Save schedule':'Save weekly settings',exact:true}).click();await page.waitForFunction(()=>!Array.from(document.querySelectorAll('button')).some(b=>b.textContent==='Saving…'));
assert.equal(await input.inputValue(),'https://public.example.test');
}}assert.equal(writes.length,4);assert.deepEqual(errors,[]);console.log('Passed: desktop/mobile inherited read-only addresses, Hosting & proxy links, schedule saves without duplicate URLs, and no overflow/errors. All APIs intercepted.');
}finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1});