test(web): add middleware + i18n + messages test suites (GOO-60)

Cover frontend middleware auth/locale logic, i18n config/routing/request/navigation,
and vi/en message parity — 91 new tests across 6 files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ho Ngoc Hai
2026-04-23 10:47:30 +07:00
parent 7a854373b3
commit 0924f0cb9b
15 changed files with 1356 additions and 61 deletions

View File

@@ -0,0 +1,53 @@
import { describe, expect, it, vi } from 'vitest';
const { mockDefineRouting } = vi.hoisted(() => ({
mockDefineRouting: vi.fn((config: unknown) => config),
}));
// Mock the config module before importing routing
vi.mock('../config', () => ({
locales: ['vi', 'en'] as const,
defaultLocale: 'vi' as const,
}));
// Mock next-intl/routing
vi.mock('next-intl/routing', () => ({
defineRouting: mockDefineRouting,
}));
import { routing } from '../routing';
describe('i18n/routing', () => {
it('calls defineRouting with the correct configuration', () => {
expect(mockDefineRouting).toHaveBeenCalledWith({
locales: ['vi', 'en'],
defaultLocale: 'vi',
localePrefix: 'as-needed',
});
});
it('exports a routing object', () => {
expect(routing).toBeDefined();
});
it('includes all supported locales', () => {
const routingConfig = mockDefineRouting.mock.calls[0][0] as {
locales: readonly string[];
};
expect(routingConfig.locales).toEqual(['vi', 'en']);
});
it('sets defaultLocale to vi', () => {
const routingConfig = mockDefineRouting.mock.calls[0][0] as {
defaultLocale: string;
};
expect(routingConfig.defaultLocale).toBe('vi');
});
it('uses as-needed locale prefix strategy', () => {
const routingConfig = mockDefineRouting.mock.calls[0][0] as {
localePrefix: string;
};
expect(routingConfig.localePrefix).toBe('as-needed');
});
});