mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-02 20:30:10 +00:00
94dbaf073b
Introduced a Vitest-based backend unit testing framework with supporting scripts, helpers, and GitHub Actions integration. Refactored the admin settings page to a modular architecture, splitting monolithic logic into feature-specific tabs and hooks for improved maintainability and testability. Updated documentation to reflect the new testing setup and settings architecture, and added new dependencies for testing utilities.
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
/**
|
|
* Component: URL Utilities Tests
|
|
* Documentation: documentation/backend/services/environment.md
|
|
*/
|
|
|
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
import { getBaseUrl, getCallbackUrl } from '@/lib/utils/url';
|
|
|
|
const envBackup = { ...process.env };
|
|
|
|
describe('URL utilities', () => {
|
|
beforeEach(() => {
|
|
process.env = { ...envBackup };
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.env = { ...envBackup };
|
|
});
|
|
|
|
it('prefers PUBLIC_URL and trims trailing slashes', () => {
|
|
process.env.PUBLIC_URL = 'https://example.com/';
|
|
process.env.NEXTAUTH_URL = 'https://next.example.com';
|
|
process.env.BASE_URL = 'https://base.example.com';
|
|
|
|
const url = getBaseUrl();
|
|
|
|
expect(url).toBe('https://example.com');
|
|
});
|
|
|
|
it('falls back to NEXTAUTH_URL when PUBLIC_URL is not set', () => {
|
|
delete process.env.PUBLIC_URL;
|
|
process.env.NEXTAUTH_URL = 'https://next.example.com/';
|
|
|
|
const url = getBaseUrl();
|
|
|
|
expect(url).toBe('https://next.example.com');
|
|
});
|
|
|
|
it('uses BASE_URL and keeps invalid scheme values', () => {
|
|
delete process.env.PUBLIC_URL;
|
|
delete process.env.NEXTAUTH_URL;
|
|
process.env.BASE_URL = 'example.com/';
|
|
|
|
const url = getBaseUrl();
|
|
|
|
expect(url).toBe('example.com');
|
|
});
|
|
|
|
it('defaults to localhost in production when no env vars are set', () => {
|
|
delete process.env.PUBLIC_URL;
|
|
delete process.env.NEXTAUTH_URL;
|
|
delete process.env.BASE_URL;
|
|
process.env.NODE_ENV = 'production';
|
|
|
|
const url = getBaseUrl();
|
|
|
|
expect(url).toBe('http://localhost:3030');
|
|
});
|
|
|
|
it('builds callback URLs with normalized paths', () => {
|
|
process.env.PUBLIC_URL = 'https://example.com';
|
|
|
|
const url = getCallbackUrl('api/auth/oidc/callback');
|
|
|
|
expect(url).toBe('https://example.com/api/auth/oidc/callback');
|
|
});
|
|
});
|