Files
textbee/web/test/msw/handlers.test.ts
isra el c92740c401 test: add vitest + rtl + msw + playwright harness with mocked api
Establish the testing safety net for the web dashboard before refactoring.

- Vitest + React Testing Library + jsdom for unit/component tests
- MSW node server mocks the API; unhandled requests throw so tests can
  never reach a real backend
- Playwright e2e boots the real Next app but intercepts every /api/v1 call
  with shared fixtures, and mints a NextAuth session cookie to run authed
- Shared fixtures in test/fixtures.ts back both layers
- Seed tests: Button unit tests, MSW sanity checks, and a dashboard e2e
  happy path plus an auth-guard redirect

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-11 01:01:05 +03:00

27 lines
1.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import httpBrowserClient from '@/lib/httpBrowserClient'
import { ApiEndpoints } from '@/config/api'
import { mockStats, mockSubscription, mockUser } from '../fixtures'
// Sanity checks that the MSW layer intercepts the real axios client the app
// uses, so every later data-layer test is trustworthy. No real backend runs.
describe('MSW mocked API', () => {
it('returns the mocked current user for whoAmI', async () => {
const res = await httpBrowserClient.get(ApiEndpoints.auth.whoAmI())
expect(res.data.data.email).toBe(mockUser.email)
})
it('returns the mocked subscription', async () => {
const res = await httpBrowserClient.get(
ApiEndpoints.billing.currentSubscription()
)
expect(res.data.plan.name).toBe(mockSubscription.plan.name)
expect(res.data.status).toBe('active')
})
it('returns mocked gateway stats', async () => {
const res = await httpBrowserClient.get(ApiEndpoints.gateway.getStats())
expect(res.data.data.totalSentSMSCount).toBe(mockStats.totalSentSMSCount)
})
})