import { beforeEach, describe, expect, it } from 'vitest'; import { load } from './+page.server'; beforeEach(() => { process.env.AUTH_URL = 'https://example.com/auth'; }); describe('login page load', () => { it('returns auth options when local auth is enabled', async () => { process.env.LOCAL_AUTH_ENABLED = 'true'; const result = await load({ url: new URL('https://example.com/login') } as Parameters[0]); expect(result.signinUrl).toBe('https://example.com/auth/signin/synology'); expect(result.localSigninUrl).toBe('https://example.com/auth/callback/local'); expect(result.callbackUrl).toBe('https://example.com'); expect(result.localAuthEnabled).toBe(true); }); it('maps credentials errors to a generic message', async () => { process.env.LOCAL_AUTH_ENABLED = 'true'; const result = await load({ url: new URL('https://example.com/login?error=CredentialsSignin') } as Parameters[0]); expect(result.error).toBe('Invalid credentials'); }); it('disables local auth in the response when disabled', async () => { process.env.LOCAL_AUTH_ENABLED = 'false'; const result = await load({ url: new URL('https://example.com/login') } as Parameters[0]); expect(result.localAuthEnabled).toBe(false); }); });