MariaDB returns JSON columns as strings via mysql2 driver. Added parseJsonValue() to handle both string and object values. Fixes config not loading on production (always showing defaults). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { parseOrgConfig, type OrgConfig } from '$lib/server/config';
|
|
|
|
describe('config', () => {
|
|
it('parses org config rows into structured object', () => {
|
|
const rows = [
|
|
{ key: 'branding', value: { primaryColor: '#0d9488', accentColor: '#f59e0b', logoUrl: '' } },
|
|
{ key: 'org_info', value: { name: 'Test Rescue', city: 'Sioux Falls', state: 'SD' } },
|
|
{ key: 'locale', value: { language: 'en', currency: 'USD', dateFormat: 'MM/DD/YYYY' } }
|
|
];
|
|
|
|
const config = parseOrgConfig(rows);
|
|
expect(config.branding.primaryColor).toBe('#0d9488');
|
|
expect(config.orgInfo.name).toBe('Test Rescue');
|
|
expect(config.locale.language).toBe('en');
|
|
});
|
|
|
|
it('handles JSON string values from MariaDB', () => {
|
|
const rows = [
|
|
{ key: 'branding', value: '{"primaryColor":"#ea580c","accentColor":"#0d9488","logoUrl":""}' },
|
|
{ key: 'org_info', value: '{"name":"Sunny Paws Rescue","city":"Austin","state":"TX"}' },
|
|
{ key: 'setup_complete', value: 'true' }
|
|
];
|
|
|
|
const config = parseOrgConfig(rows);
|
|
expect(config.branding.primaryColor).toBe('#ea580c');
|
|
expect(config.orgInfo.name).toBe('Sunny Paws Rescue');
|
|
expect(config.setupComplete).toBe(true);
|
|
});
|
|
|
|
it('provides defaults for missing keys', () => {
|
|
const config = parseOrgConfig([]);
|
|
expect(config.branding.primaryColor).toBe('#0d9488');
|
|
expect(config.orgInfo.name).toBe('My Rescue');
|
|
expect(config.locale.language).toBe('en');
|
|
});
|
|
});
|