Files
carmanagement/apps/homepage/tests/unit/proxy.test.ts
T
root 56c3bcf666
Build & Deploy / Build & Push Docker Image (push) Successful in 2m50s
Test / Type Check (all packages) (push) Successful in 52s
Build & Deploy / Deploy to VPS (push) Successful in 3s
Test / API Unit Tests (push) Successful in 54s
Test / Homepage Unit Tests (push) Successful in 44s
Test / Storefront Unit Tests (push) Successful in 41s
Test / Admin Unit Tests (push) Successful in 42s
Test / Dashboard Unit Tests (push) Successful in 41s
Test / API Integration Tests (push) Successful in 1m0s
fix homepage storefront proxy and CSP
2026-07-02 13:55:10 -04:00

72 lines
1.7 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest';
const nextServer = vi.hoisted(() => {
const next = vi.fn((init?: { request?: { headers?: Headers } }) => ({
kind: 'next',
init,
cookies: {
set: vi.fn(),
},
headers: new Headers(),
}));
const redirect = vi.fn((url: URL) => ({
kind: 'redirect',
url: url.toString(),
cookies: {
set: vi.fn(),
},
headers: new Headers(),
}));
return { next, redirect };
});
vi.mock('next/server', () => ({
NextResponse: {
next: nextServer.next,
redirect: nextServer.redirect,
},
}));
function cloneableUrl(input: string): URL {
const url = new URL(input);
(url as URL & { clone: () => URL }).clone = () => cloneableUrl(url.toString());
return url;
}
function request(input: string) {
return {
nextUrl: cloneableUrl(input),
cookies: {
get: vi.fn(),
},
headers: new Headers(),
};
}
beforeEach(() => {
nextServer.next.mockClear();
nextServer.redirect.mockClear();
});
describe('homepage proxy app boundaries', () => {
it('does not localize storefront proxy paths', async () => {
const { proxy } = await import('@/proxy');
const response = proxy(request('https://rentaldrivego.ma/storefront/en') as never) as any;
expect(response.kind).toBe('next');
expect(nextServer.redirect).not.toHaveBeenCalled();
});
it('redirects locale-prefixed storefront paths back to the storefront proxy mount', async () => {
const { proxy } = await import('@/proxy');
const response = proxy(request('https://rentaldrivego.ma/en/storefront/en') as never) as any;
expect(response).toMatchObject({
kind: 'redirect',
url: 'https://rentaldrivego.ma/storefront/en',
});
});
});