All files / libs/amalia-lang/formula/evaluate/shared/src/functions/currency/convert-currency index.ts

97.72% Statements 43/44
100% Branches 3/3
100% Functions 6/6
100% Lines 40/40

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 411x 1x 1x 1x 1x 67x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 2x 2x 2x 69x 1x  
import { AmaliaFunctionCategory, AmaliaFunctionKeys, type AmaliaFormula } from '@amalia/amalia-lang/formula/types';
 
import { CalculationParser } from '../../../CalculationParser';
import { AmaliaFunctionRawArgs } from '../../AmaliaFunction';
 
export const currencyConvertCurrency = new AmaliaFunctionRawArgs<number | null>({
  name: AmaliaFunctionKeys.convertCurrency,
  category: AmaliaFunctionCategory.CURRENCY,
  hiddenFromLibrary: true,
 
  execMock: () => 1,
  exec: (args, _, scope) => CalculationParser.getFunctionResult(args, scope, AmaliaFunctionKeys.convertCurrency),
 
  nbParamsRequired: 3,
 
  description: 'Return an amount converted from a source currency to a target currency`',
 
  params: [
    { name: 'amount', description: 'Amount to convert' },
    { name: 'sourceCurrency', description: 'Source currency: currency code, variables, fields, properties, keywords' },
    { name: 'targetCurrency', description: 'Target currency: currency code, variables, fields, properties, keywords' },
  ],
 
  examples: [
    {
      desc: 'Converts Payout from EUR to USD.',
      formula: 'convertCurrency(opportunity.payout, "EUR", "USD")' as AmaliaFormula,
    },
    {
      desc: "Converts opportunity's amount from opportunity currency to user's currency.",
      formula: 'convertCurrency(opportunity.amount, opportunity.currency, user.currency)' as AmaliaFormula,
    },
  ],
 
  generateComputedFunctionResult: (args) => ({
    formula: args[0].toString() as AmaliaFormula,
    fromCurrencyCode: args[1].toString() as AmaliaFormula,
    toCurrencyCode: args[2].toString() as AmaliaFormula,
  }),
});