Files
MikrotikManager/lib/app-switcher-config.test.ts
T

19 lines
1.0 KiB
TypeScript

import assert from 'node:assert/strict'
import {authPortalBaseUrl} from './app-switcher-config'
import {ensureAuthConfig} from './auth'
import {test} from 'node:test'
test('runtime Portal links override the build address',async()=>{
const previous=process.env.NEXT_PUBLIC_AUTH_PORTAL_URL,originalFetch=globalThis.fetch
try{
process.env.NEXT_PUBLIC_AUTH_PORTAL_URL='https://build.example/'
assert.equal(authPortalBaseUrl(),'https://build.example')
globalThis.fetch=async()=>new Response(JSON.stringify({required:true,portal_url:'http://localhost:5175/'}),{headers:{'content-type':'application/json'}})
await ensureAuthConfig()
assert.equal(authPortalBaseUrl(),'http://localhost:5175','header links and switcher fetch share runtime Portal')
}finally{
globalThis.fetch=originalFetch
if(previous===undefined)delete process.env.NEXT_PUBLIC_AUTH_PORTAL_URL;else process.env.NEXT_PUBLIC_AUTH_PORTAL_URL=previous
}
console.log('app switcher: runtime Portal overrides build URL; fallback and trailing slash passed')
})