Skip to content

Commit

Permalink
[ABF-7927] dev(capital gains inclusion): ajout d'une fonction pour ca…
Browse files Browse the repository at this point in the history
…lculer le montant d'inclusion pour les gains en capital (#447)

* added function to calculate amount that will be taxed for capital gains

added babel dependencies to support debugging jest tests from intellij

* fix var declaration

* exporting file

* floor version for babel

* cleanup function
  • Loading branch information
alexelie120 authored May 9, 2024
1 parent d396bdb commit 22cdf99
Show file tree
Hide file tree
Showing 7 changed files with 1,454 additions and 112 deletions.
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {presets: ['@babel/preset-env', '@babel/preset-typescript']}
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@
"watch": "tsc --watch"
},
"devDependencies": {
"@babel/core": "7.24.5",
"@babel/preset-env": "7.24.5",
"@babel/preset-typescript": "7.24.1",
"@equisoft/eslint-config": "3.0.6",
"@equisoft/eslint-config-typescript": "3.0.6",
"@equisoft/typescript-config": "2.0.0",
"@microsoft/eslint-formatter-sarif": "3.1.0",
"@types/babel__core": "^7",
"@types/babel__preset-env": "^7",
"@types/jest": "29.5.12",
"@types/node": "20.12.9",
"@typescript-eslint/eslint-plugin": "6.21.0",
"@typescript-eslint/parser": "6.21.0",
"babel-jest": "29.7.0",
"eslint": "8.57.0",
"eslint-import-resolver-node": "0.3.9",
"eslint-import-resolver-typescript": "3.6.1",
Expand Down
1 change: 1 addition & 0 deletions src/investments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './life-income-fund';
export * from './registered-retirement-income-fund';
export * from './registered-retirement-savings-plan';
export * from './tax-free-savings-account';
export * from './non-registered-savings-plan';
26 changes: 26 additions & 0 deletions src/investments/non-registered-savings-plan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Rate } from '../taxes';

export const CAPITAL_GAINS_BRACKETS: Rate[] = [
{
FROM: 0,
TO: 250000,
RATE: 0.5,
},
{
FROM: 250000,
TO: Infinity,
RATE: 0.667,
},
];

export function getCapitalGainsTaxableAmount(totalCapitalGains: number): number {
return CAPITAL_GAINS_BRACKETS.reduce((taxableAmount, currentBracket) => {
const currentBracketRate = currentBracket.RATE;

const bracketTaxableAmount = Math.min(totalCapitalGains, currentBracket.TO);

if (bracketTaxableAmount <= currentBracket.FROM) return taxableAmount;

return taxableAmount + ((bracketTaxableAmount - currentBracket.FROM) * currentBracketRate);
}, 0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { getCapitalGainsTaxableAmount } from '../non-registered-savings-plan';

describe('getCapitalGainsTaxableAmount', () => {
it('should calculate taxable amount on capital gains income', () => {
const capitalGainsList = [
{ capitalGains: 150000, taxableAmount: 75000 },
{ capitalGains: 0, taxableAmount: 0 },
{ capitalGains: -50, taxableAmount: 0 },
{ capitalGains: 250000, taxableAmount: 125000 },
{ capitalGains: 350000, taxableAmount: 125000 + 66700 },
{ capitalGains: 350001, taxableAmount: 125000 + 66700.667 },
{ capitalGains: 250100, taxableAmount: 125000 + 66.7 },
{ capitalGains: 249000, taxableAmount: 124500 },
{ capitalGains: 250001, taxableAmount: 125000 + 0.667 },
];

capitalGainsList.forEach((item) => {
const taxableAmount = getCapitalGainsTaxableAmount(item.capitalGains);
expect(taxableAmount).toBe(item.taxableAmount);
});
});
});
1 change: 1 addition & 0 deletions tests/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
},
],
'^.+\\.(js|jsx)$': 'babel-jest',
},
clearMocks: true,
errorOnDeprecated: true,
Expand Down
Loading

0 comments on commit 22cdf99

Please sign in to comment.