Browse Source

Improve the central X-ray rule settings

pull/7887/head
Thomas Kaul 4 weeks ago
parent
commit
3eeebe7d4c
  1. 72
      apps/api/src/models/rules/rule-settings.spec.ts
  2. 44
      apps/api/src/models/rules/rule-settings.ts

72
apps/api/src/models/rules/rule-settings.spec.ts

@ -16,6 +16,20 @@ describe('Rule settings', () => {
});
});
it('gets a default threshold of zero for a rule', () => {
expect(
getRuleSettings({
key: 'BuyingPower',
userSettings: {}
})
).toEqual({
baseCurrency: 'USD',
isActive: true,
locale: 'en-US',
thresholdMin: 0
});
});
it('applies the configured settings for a rule', () => {
expect(
getRuleSettings({
@ -41,6 +55,44 @@ describe('Rule settings', () => {
});
});
it('applies the default for a threshold which is not configured', () => {
expect(
getRuleSettings({
key: 'AssetClassClusterRiskEquity',
userSettings: {
xRayRules: {
AssetClassClusterRiskEquity: { isActive: true, thresholdMax: 0.9 }
}
}
})
).toEqual({
baseCurrency: 'USD',
isActive: true,
locale: 'en-US',
thresholdMax: 0.9,
thresholdMin: 0.78
});
});
it('applies a configured threshold of zero', () => {
expect(
getRuleSettings({
key: 'AssetClassClusterRiskEquity',
userSettings: {
xRayRules: {
AssetClassClusterRiskEquity: { isActive: true, thresholdMin: 0 }
}
}
})
).toEqual({
baseCurrency: 'USD',
isActive: true,
locale: 'en-US',
thresholdMax: 0.82,
thresholdMin: 0
});
});
it('omits the base currency when it is not used by a rule', () => {
expect(
getRuleSettings({
@ -54,6 +106,24 @@ describe('Rule settings', () => {
});
it('gets settings for all rules', () => {
expect(Object.keys(getXRayRulesSettings({}))).toHaveLength(17);
expect(Object.keys(getXRayRulesSettings({})).sort()).toEqual([
'AccountClusterRiskCurrentInvestment',
'AccountClusterRiskSingleAccount',
'AssetClassClusterRiskEquity',
'AssetClassClusterRiskFixedIncome',
'BuyingPower',
'CurrencyClusterRiskBaseCurrencyCurrentInvestment',
'CurrencyClusterRiskCurrentInvestment',
'EconomicMarketClusterRiskDevelopedMarkets',
'EconomicMarketClusterRiskEmergingMarkets',
'EmergencyFundCoverage',
'EmergencyFundSetup',
'FeeRatioTotalInvestmentVolume',
'RegionalMarketClusterRiskAsiaPacific',
'RegionalMarketClusterRiskEmergingMarkets',
'RegionalMarketClusterRiskEurope',
'RegionalMarketClusterRiskJapan',
'RegionalMarketClusterRiskNorthAmerica'
]);
});
});

44
apps/api/src/models/rules/rule-settings.ts

@ -62,32 +62,28 @@ export function getRuleSettings<T extends RuleSettings>({
userSettings: UserSettings;
}): T {
const configuration: RuleSettingsConfiguration =
RULE_SETTINGS_CONFIGURATIONS[key];
RULE_SETTINGS_CONFIGURATIONS[key] ?? {};
const configuredSettings = userSettings.xRayRules?.[key];
const settings: RuleSettings & {
baseCurrency?: string;
thresholdMax?: number;
thresholdMin?: number;
} = {
isActive: configuredSettings?.isActive ?? true,
locale: userSettings.locale ?? DEFAULT_LOCALE
};
if (configuration.withBaseCurrency !== false) {
settings.baseCurrency = userSettings.baseCurrency ?? DEFAULT_CURRENCY;
}
if (configuration.thresholdMax !== undefined) {
settings.thresholdMax =
configuredSettings?.thresholdMax ?? configuration.thresholdMax;
}
if (configuration.thresholdMin !== undefined) {
settings.thresholdMin =
configuredSettings?.thresholdMin ?? configuration.thresholdMin;
}
return settings as T;
return {
...(configuration.withBaseCurrency === false
? {}
: { baseCurrency: userSettings.baseCurrency ?? DEFAULT_CURRENCY }),
isActive: configuredSettings?.isActive ?? true,
locale: userSettings.locale ?? DEFAULT_LOCALE,
...(configuration.thresholdMax === undefined
? {}
: {
thresholdMax:
configuredSettings?.thresholdMax ?? configuration.thresholdMax
}),
...(configuration.thresholdMin === undefined
? {}
: {
thresholdMin:
configuredSettings?.thresholdMin ?? configuration.thresholdMin
})
} as T;
}
export function getXRayRulesSettings(

Loading…
Cancel
Save