diff --git a/process/payments/lib/__tests__/seasons.test.js b/process/payments/lib/__tests__/seasons.test.js index dd15625..9bedb98 100644 --- a/process/payments/lib/__tests__/seasons.test.js +++ b/process/payments/lib/__tests__/seasons.test.js @@ -1,6 +1,6 @@ -import { getPositionIndex } from '../seasons'; +import { getPositionIndex } from '../seasons-tools'; -describe('process/payments/lib/seasons', () => { +describe('process/payments/lib/seasons-tools', () => { describe('[function] getPositionIndex', () => { test('should return 0', () => { const result = getPositionIndex(100_000_001, 0); diff --git a/process/payments/lib/seasons-constants.ts b/process/payments/lib/seasons-constants.ts new file mode 100644 index 0000000..889bc29 --- /dev/null +++ b/process/payments/lib/seasons-constants.ts @@ -0,0 +1,15 @@ +export const SEASONS_PERIODS: Record> = { + 100_000_000: [0, 6], + 100_000_001: [0, 8], + 100_000_002: [0, 4, 8], +}; + +export const FORBIDDEN_HIGH_SEASON_START: Record> = { + 100_000_000: ['9', '10'], + 100_000_001: ['7', '8', '9'], + 100_000_002: ['11'], +}; + +export const SEASONS_PERIOD_NUMBER = 12; + +export const DEFAULT_SEASONS_VALUES = [100, 75, 50]; diff --git a/process/payments/lib/seasons.ts b/process/payments/lib/seasons-tools.ts similarity index 80% rename from process/payments/lib/seasons.ts rename to process/payments/lib/seasons-tools.ts index da7133b..f930165 100644 --- a/process/payments/lib/seasons.ts +++ b/process/payments/lib/seasons-tools.ts @@ -1,25 +1,10 @@ /* eslint-disable implicit-arrow-linebreak */ import type { CalculationValues } from 'stores/calculation/values/types'; +import { SEASONS_PERIODS, SEASONS_PERIOD_NUMBER } from './seasons-constants'; type SeasonType = NonNullable; type LeasingPeriod = CalculationValues['leasingPeriod']; -const SEASONS_PERIODS: Record> = { - 100_000_000: [0, 6], - 100_000_001: [0, 8], - 100_000_002: [0, 4, 8], -}; - -export const FORBIDDEN_HIGH_SEASON_START: Record> = { - 100_000_000: ['9', '10'], - 100_000_001: ['7', '8', '9'], - 100_000_002: ['11'], -}; - -export const SEASONS_PERIOD_NUMBER = 12; - -export const DEFAULT_SEASONS_VALUES = [100, 75, 50]; - export function getPositionIndex(seasonType: SeasonType, seasonsIndex: number) { let positionIndex = 0; diff --git a/process/payments/reactions.ts b/process/payments/reactions.ts index 86ef1e3..3feaa30 100644 --- a/process/payments/reactions.ts +++ b/process/payments/reactions.ts @@ -8,12 +8,8 @@ import type { CalculationOptions } from 'stores/calculation/options/types'; import type RootStore from 'stores/root'; import type { Row } from 'stores/tables/payments/types'; import { difference, shift } from 'tools/array'; -import * as seasonsTools from './lib/seasons'; -import { - DEFAULT_SEASONS_VALUES, - FORBIDDEN_HIGH_SEASON_START, - SEASONS_PERIOD_NUMBER, -} from './lib/seasons'; +import * as seasonsConstants from './lib/seasons-constants'; +import * as seasonsTools from './lib/seasons-tools'; import validatePaymentsTable from './validation'; export default function paymentsReactions( @@ -401,7 +397,7 @@ export default function paymentsReactions( } const highSeasonStartOptions = selectHighSeasonStart.filter( - (option) => !FORBIDDEN_HIGH_SEASON_START[seasonType].includes(option.label) + (option) => !seasonsConstants.FORBIDDEN_HIGH_SEASON_START[seasonType].includes(option.label) ); $calculation.setElementOptions('selectHighSeasonStart', highSeasonStartOptions); @@ -431,7 +427,10 @@ export default function paymentsReactions( return; } - const seasons = seasonsTools.generateSeasons(seasonType, DEFAULT_SEASONS_VALUES); + const seasons = seasonsTools.generateSeasons( + seasonType, + seasonsConstants.DEFAULT_SEASONS_VALUES + ); const shiftNumber = Number.parseInt(highSeasonStartOption.label, 10) - 2; const payments = seasonsTools.generateSeasonsPayments( leasingPeriod, @@ -439,7 +438,7 @@ export default function paymentsReactions( ); const rows: Row[] = payments.map((value, i) => ({ value, - status: i < SEASONS_PERIOD_NUMBER ? 'Default' : 'Disabled', + status: i < seasonsConstants.SEASONS_PERIOD_NUMBER ? 'Default' : 'Disabled', })); const firstPaymentPerc = $calculation.getElementValue('tbxFirstPaymentPerc'); const lastPaymentPerc = $calculation.getElementValue('tbxLastPaymentPerc'); @@ -461,7 +460,7 @@ export default function paymentsReactions( reaction( () => { const payments = toJS($tables.payments.values); - const seasons = payments.slice(1, SEASONS_PERIOD_NUMBER + 1); + const seasons = payments.slice(1, seasonsConstants.SEASONS_PERIOD_NUMBER + 1); return seasons; }, @@ -495,7 +494,7 @@ export default function paymentsReactions( const rows: Row[] = payments.map((value, i) => ({ value, - status: i < SEASONS_PERIOD_NUMBER ? 'Default' : 'Disabled', + status: i < seasonsConstants.SEASONS_PERIOD_NUMBER ? 'Default' : 'Disabled', })); const firstPaymentPerc = $calculation.getElementValue('tbxFirstPaymentPerc'); const lastPaymentPerc = $calculation.getElementValue('tbxLastPaymentPerc');