Files
goodgo-platform/e2e/api/auth-login.spec.ts
Ho Ngoc Hai 9301f44119 feat(e2e): add Playwright E2E testing infrastructure and critical path tests
Set up Playwright with dual-project config (API + Web), auth test fixtures,
16 E2E tests covering registration, login, profile, token refresh, and
homepage rendering. Added GitHub Actions CI workflow for automated E2E runs.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-08 01:41:07 +07:00

40 lines
1.2 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { createTestUser, registerUser } from '../fixtures';
test.describe('POST /auth/login', () => {
test('logs in with valid credentials and returns token pair', async ({ request }) => {
const user = createTestUser();
await registerUser(request, user);
const res = await request.post('/auth/login', {
data: { phone: user.phone, password: user.password },
});
expect(res.status()).toBe(201);
const body = await res.json();
expect(body).toHaveProperty('accessToken');
expect(body).toHaveProperty('refreshToken');
});
test('rejects login with wrong password', async ({ request }) => {
const user = createTestUser();
await registerUser(request, user);
const res = await request.post('/auth/login', {
data: { phone: user.phone, password: 'WrongPassword!1' },
});
expect(res.ok()).toBeFalsy();
expect(res.status()).toBe(401);
});
test('rejects login with non-existent phone', async ({ request }) => {
const res = await request.post('/auth/login', {
data: { phone: '0900000001', password: 'Test@1234!' },
});
expect(res.ok()).toBeFalsy();
expect(res.status()).toBe(401);
});
});