Prepare isolated Firebase push configuration for pre-production
This commit is contained in:
@@ -8,7 +8,7 @@ const id = '12345678-1234-1234-1234-123456789abc';
|
||||
const tag = 'a'.repeat(64);
|
||||
|
||||
async function setup(options={}) {
|
||||
const listeners = {}, navigations = [], elements = [];
|
||||
const listeners = {}, navigations = [], elements = [], requests = [];
|
||||
const session = {authenticated:true, session_tag:tag, ...options.session};
|
||||
const config = {textContent:JSON.stringify({openNotification:'Open new notification'})};
|
||||
const main = {prepend(node) { elements.push(node); }};
|
||||
@@ -25,11 +25,22 @@ async function setup(options={}) {
|
||||
const device = {getInfo:async()=>({deviceId:id,appVersion:'1.1.0',binding:options.binding ?? tag}), prepareSession:async()=>{}};
|
||||
vm.runInNewContext(source, {document, window:{Capacitor:{getPlatform:()=> 'android',Plugins:{PushNotifications:push,MetalCircleDevice:device}},addEventListener(){}},
|
||||
location:{pathname:'/',assign(value){navigations.push(value);}},
|
||||
fetch:async()=>({ok:true,json:async()=>session}), localStorage:{getItem(){return 'seen';}}});
|
||||
fetch:async(url,options)=>{requests.push({url,options});return {ok:true,json:async()=>session};}, localStorage:{getItem(){return 'seen';}}});
|
||||
await new Promise(resolve=>setImmediate(resolve));
|
||||
return {listeners,navigations,elements};
|
||||
return {listeners,navigations,elements,requests};
|
||||
}
|
||||
|
||||
test('registration uses the loaded backend origin and its authenticated session',async()=>{
|
||||
const app=await setup();
|
||||
await app.listeners.registration({value:'synthetic-device-token'});
|
||||
await new Promise(resolve=>setImmediate(resolve));
|
||||
const sent=app.requests.find(request=>request.url==='/api/push/devices');
|
||||
assert.ok(sent);
|
||||
assert.equal(sent.options.credentials,'same-origin');
|
||||
assert.equal(JSON.parse(sent.options.body).session_tag,tag);
|
||||
assert.ok(app.requests.every(request=>request.url.startsWith('/api/push/')));
|
||||
});
|
||||
|
||||
test('tap opens only backend-resolved destination for the matching session',async()=>{
|
||||
const app=await setup();
|
||||
await app.listeners.pushNotificationActionPerformed({notification:{data:{notification_id:id,session_tag:tag,url:'https://evil.invalid'}}});
|
||||
|
||||
Reference in New Issue
Block a user