fix login issue in production
Build & Push / Pipeline Tests (push) Successful in 1m53s
Test / Type Check (all packages) (push) Successful in 55s
Build & Push / Build & Push Docker Image (push) Successful in 4m32s
Test / API Unit Tests (push) Successful in 1m17s
Test / Homepage Unit Tests (push) Successful in 50s
Test / Carplace Unit Tests (push) Successful in 43s
Test / Admin Unit Tests (push) Successful in 44s
Test / Dashboard Unit Tests (push) Successful in 45s
Test / API Integration Tests (push) Successful in 1m12s
Build & Push / Pipeline Tests (push) Successful in 1m53s
Test / Type Check (all packages) (push) Successful in 55s
Build & Push / Build & Push Docker Image (push) Successful in 4m32s
Test / API Unit Tests (push) Successful in 1m17s
Test / Homepage Unit Tests (push) Successful in 50s
Test / Carplace Unit Tests (push) Successful in 43s
Test / Admin Unit Tests (push) Successful in 44s
Test / Dashboard Unit Tests (push) Successful in 45s
Test / API Integration Tests (push) Successful in 1m12s
This commit is contained in:
@@ -1,17 +1,68 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { normalizeApiBase } from '@/lib/api';
|
||||
function installBrowser() {
|
||||
Object.defineProperty(globalThis, 'window', {
|
||||
configurable: true,
|
||||
value: {
|
||||
location: {
|
||||
origin: 'https://rentaldrivego.ma',
|
||||
hostname: 'rentaldrivego.ma',
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
Reflect.deleteProperty(globalThis, 'window');
|
||||
delete process.env.API_INTERNAL_URL;
|
||||
delete process.env.NEXT_PUBLIC_API_URL;
|
||||
delete process.env.NEXT_PUBLIC_HOMEPAGE_DIRECT_API;
|
||||
vi.resetModules();
|
||||
});
|
||||
|
||||
describe('homepage API base URL', () => {
|
||||
it('keeps API URLs that already include the version prefix', () => {
|
||||
it('keeps API URLs that already include the version prefix', async () => {
|
||||
const { normalizeApiBase } = await import('@/lib/api');
|
||||
|
||||
expect(normalizeApiBase('https://api.rentaldrivego.ma/api/v1')).toBe('https://api.rentaldrivego.ma/api/v1');
|
||||
});
|
||||
|
||||
it('adds the version prefix when production env only contains the API host', () => {
|
||||
it('adds the version prefix when production env only contains the API host', async () => {
|
||||
const { normalizeApiBase } = await import('@/lib/api');
|
||||
|
||||
expect(normalizeApiBase('https://api.rentaldrivego.ma')).toBe('https://api.rentaldrivego.ma/api/v1');
|
||||
});
|
||||
|
||||
it('normalizes trailing slashes before appending the version prefix', () => {
|
||||
it('normalizes trailing slashes before appending the version prefix', async () => {
|
||||
const { normalizeApiBase } = await import('@/lib/api');
|
||||
|
||||
expect(normalizeApiBase('https://api.rentaldrivego.ma/')).toBe('https://api.rentaldrivego.ma/api/v1');
|
||||
});
|
||||
|
||||
it('uses the same-origin API proxy in browsers by default', async () => {
|
||||
installBrowser();
|
||||
process.env.NEXT_PUBLIC_API_URL = 'https://api.rentaldrivego.ma/api/v1';
|
||||
|
||||
const { API_BASE } = await import('@/lib/api');
|
||||
|
||||
expect(API_BASE).toBe('/api/v1');
|
||||
});
|
||||
|
||||
it('allows direct browser API calls only when explicitly enabled', async () => {
|
||||
installBrowser();
|
||||
process.env.NEXT_PUBLIC_API_URL = 'https://api.rentaldrivego.ma';
|
||||
process.env.NEXT_PUBLIC_HOMEPAGE_DIRECT_API = 'true';
|
||||
|
||||
const { API_BASE } = await import('@/lib/api');
|
||||
|
||||
expect(API_BASE).toBe('https://api.rentaldrivego.ma/api/v1');
|
||||
});
|
||||
|
||||
it('uses the internal API URL on the server', async () => {
|
||||
process.env.API_INTERNAL_URL = 'http://api:4000/api/v1';
|
||||
|
||||
const { API_BASE } = await import('@/lib/api');
|
||||
|
||||
expect(API_BASE).toBe('http://api:4000/api/v1');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import nextConfig from '../../next.config';
|
||||
|
||||
describe('homepage next config', () => {
|
||||
it('proxies same-origin API requests to the API service before app rewrites', async () => {
|
||||
const rewrites = await nextConfig.rewrites?.();
|
||||
|
||||
expect(rewrites).toEqual(
|
||||
expect.arrayContaining([
|
||||
{
|
||||
source: '/api/:path*',
|
||||
destination: 'http://api:4000/api/:path*',
|
||||
},
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user