Spaces:
Running
Running
File size: 1,906 Bytes
a551982 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | import test from 'node:test';
import assert from 'node:assert/strict';
import {
DEFAULT_ADMIN_SETTINGS,
resolveCompanyId,
settingsFromSystemSettingsRow,
settingsToSystemSettingsRow,
} from './adminSettingsPersistence.js';
test('maps a system_settings row into admin UI settings', () => {
const settings = settingsFromSystemSettingsRow({
ai_confidence_threshold: 0.7,
duplicate_sensitivity: 0.9,
enable_auto_resolve: true,
auto_close_days: 14,
email_notifications: true,
admin_alerts: false,
});
assert.deepEqual(settings, {
aiConfidenceThreshold: 0.7,
duplicateSensitivity: 0.9,
enableAutoResolve: true,
autoCloseDays: 14,
emailNotifications: true,
adminAlerts: false,
});
});
test('preserves fallback values when database columns are absent', () => {
const settings = settingsFromSystemSettingsRow({}, DEFAULT_ADMIN_SETTINGS);
assert.deepEqual(settings, DEFAULT_ADMIN_SETTINGS);
});
test('maps admin UI settings into an upsert payload', () => {
const row = settingsToSystemSettingsRow({
aiConfidenceThreshold: '0.75',
duplicateSensitivity: 0.8,
enableAutoResolve: 1,
autoCloseDays: '3',
emailNotifications: false,
adminAlerts: true,
}, 'company-123');
assert.deepEqual(row, {
company_id: 'company-123',
ai_confidence_threshold: 0.75,
duplicate_sensitivity: 0.8,
enable_auto_resolve: true,
auto_close_days: 3,
email_notifications: false,
admin_alerts: true,
});
});
test('resolves company id from profile before auth metadata', () => {
const companyId = resolveCompanyId(
{ company_id: 'profile-company' },
{ user_metadata: { company_id: 'metadata-company' } },
);
assert.equal(companyId, 'profile-company');
});
|