onboarding.mjs 904 B

123456789101112
  1. /** Enter through the native local-admin flow, then set isolated fixture credentials. */
  2. export async function enterLocal(page, { username = 'desktop-fixture', password = 'desktop-fixture-password' } = {}) {
  3. await page.waitForURL(url => url.protocol === 'http:' || url.protocol === 'https:', { timeout: 90000 })
  4. await page.evaluate(async ({username,password}) => {
  5. const bootstrap = await (await fetch('/api/app/bootstrap')).json()
  6. if (!bootstrap.user?.localDesktop) throw new Error('Native administrator session was not established')
  7. const response = await fetch('/api/app/account/credentials', { method: 'PUT',
  8. headers: {'Content-Type':'application/json','X-CSRF-Token':bootstrap.csrfToken},
  9. body: JSON.stringify({username,currentPassword:'',newPassword:password}) })
  10. if (!response.ok) throw new Error('Fixture account configuration failed')
  11. }, {username,password})
  12. }