/** * Reusable test helpers for Magnitude tests * * These helpers encapsulate common test patterns to reduce code duplication * and make tests more maintainable. */ const TEST_HANDLE = process.env.TEST_BLUESKY_HANDLE; const TEST_PASSWORD = process.env.TEST_BLUESKY_PASSWORD; if (!TEST_HANDLE || !TEST_PASSWORD) { throw new Error('TEST_BLUESKY_HANDLE and TEST_BLUESKY_PASSWORD must be set in .env'); } /** * Performs complete OAuth login flow * * This function navigates to the login page and completes the full OAuth flow: * 1. Navigate to /login * 2. Enter handle and click "Log in with Bluesky" * 3. Wait for redirect to Bluesky OAuth page * 4. Enter password and click "Sign in" * 5. Click "Authorize" button * 6. Wait for redirect to /chat * * @param agent - The Magnitude test agent */ export async function loginFlow(agent: any) { // Navigate to login page await agent.act('Navigate to /login'); // Fill in handle and initiate OAuth await agent.act(`Type "${TEST_HANDLE}" into the "Your Handle" input field`); await agent.act('Click the "Log in with Bluesky" button'); // Wait for redirect to Bluesky OAuth page await agent.check('The page URL contains "bsky.social"'); // Fill in credentials on Bluesky OAuth page await agent.act(`Type "${TEST_HANDLE}" into the username/identifier field`); await agent.act(`Type "${TEST_PASSWORD}" into the password field`); // Submit login form await agent.act('Click the submit/authorize button'); // Wait for and click authorize button await agent.act('Click the "Authorize" button'); // Verify successful login await agent.check('The page URL contains "/chat"'); } /** * Test credentials for use in tests that need them directly */ export const TEST_CREDENTIALS = { handle: TEST_HANDLE, password: TEST_PASSWORD, } as const;