Add auth URL config module with validation (TDD)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
47
src/config/auth.test.ts
Normal file
47
src/config/auth.test.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { resolveAuthConfig } from './auth';
|
||||
|
||||
describe('resolveAuthConfig', () => {
|
||||
it('returns both URLs and sales email from env', () => {
|
||||
const cfg = resolveAuthConfig({
|
||||
PUBLIC_AUTH_SIGNIN_URL: 'https://auth.cameleer.io/sign-in',
|
||||
PUBLIC_AUTH_SIGNUP_URL: 'https://auth.cameleer.io/sign-in?first_screen=register',
|
||||
PUBLIC_SALES_EMAIL: 'sales@cameleer.io',
|
||||
});
|
||||
expect(cfg.signInUrl).toBe('https://auth.cameleer.io/sign-in');
|
||||
expect(cfg.signUpUrl).toBe('https://auth.cameleer.io/sign-in?first_screen=register');
|
||||
expect(cfg.salesEmail).toBe('sales@cameleer.io');
|
||||
});
|
||||
|
||||
it('throws if PUBLIC_AUTH_SIGNIN_URL is missing', () => {
|
||||
expect(() => resolveAuthConfig({
|
||||
PUBLIC_AUTH_SIGNUP_URL: 'https://auth.cameleer.io/sign-in?first_screen=register',
|
||||
PUBLIC_SALES_EMAIL: 'sales@cameleer.io',
|
||||
})).toThrow(/PUBLIC_AUTH_SIGNIN_URL/);
|
||||
});
|
||||
|
||||
it('throws if a URL is not https', () => {
|
||||
expect(() => resolveAuthConfig({
|
||||
PUBLIC_AUTH_SIGNIN_URL: 'http://auth.cameleer.io/sign-in',
|
||||
PUBLIC_AUTH_SIGNUP_URL: 'https://auth.cameleer.io/sign-in?first_screen=register',
|
||||
PUBLIC_SALES_EMAIL: 'sales@cameleer.io',
|
||||
})).toThrow(/must be https/);
|
||||
});
|
||||
|
||||
it('throws if sales email is not a valid mailto target', () => {
|
||||
expect(() => resolveAuthConfig({
|
||||
PUBLIC_AUTH_SIGNIN_URL: 'https://auth.cameleer.io/sign-in',
|
||||
PUBLIC_AUTH_SIGNUP_URL: 'https://auth.cameleer.io/sign-in?first_screen=register',
|
||||
PUBLIC_SALES_EMAIL: 'not-an-email',
|
||||
})).toThrow(/PUBLIC_SALES_EMAIL/);
|
||||
});
|
||||
|
||||
it('exposes signUpUrl distinct from signInUrl', () => {
|
||||
const cfg = resolveAuthConfig({
|
||||
PUBLIC_AUTH_SIGNIN_URL: 'https://auth.cameleer.io/sign-in',
|
||||
PUBLIC_AUTH_SIGNUP_URL: 'https://auth.cameleer.io/sign-in?first_screen=register',
|
||||
PUBLIC_SALES_EMAIL: 'sales@cameleer.io',
|
||||
});
|
||||
expect(cfg.signUpUrl).not.toBe(cfg.signInUrl);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user