Browse Source

Add tests for getInvestments()

pull/1089/head
Thomas 3 years ago
parent
commit
4212e9e400
  1. 7
      apps/api/src/app/portfolio/portfolio-calculator-baln-buy-and-sell.spec.ts
  2. 6
      apps/api/src/app/portfolio/portfolio-calculator-baln-buy.spec.ts
  3. 4
      apps/api/src/app/portfolio/portfolio-calculator-no-orders.spec.ts
  4. 7
      apps/api/src/app/portfolio/portfolio-calculator-novn-buy-and-sell-partially.spec.ts

7
apps/api/src/app/portfolio/portfolio-calculator-baln-buy-and-sell.spec.ts

@ -62,6 +62,8 @@ describe('PortfolioCalculator', () => {
parseDate('2021-11-22') parseDate('2021-11-22')
); );
const investments = portfolioCalculator.getInvestments();
const investmentsByMonth = portfolioCalculator.getInvestmentsByMonth(); const investmentsByMonth = portfolioCalculator.getInvestmentsByMonth();
spy.mockRestore(); spy.mockRestore();
@ -94,6 +96,11 @@ describe('PortfolioCalculator', () => {
totalInvestment: new Big('0') totalInvestment: new Big('0')
}); });
expect(investments).toEqual([
{ date: '2021-11-22', investment: new Big('285.8') },
{ date: '2021-11-30', investment: new Big('0') }
]);
expect(investmentsByMonth).toEqual([ expect(investmentsByMonth).toEqual([
{ date: '2021-11-01', investment: new Big('12.6') } { date: '2021-11-01', investment: new Big('12.6') }
]); ]);

6
apps/api/src/app/portfolio/portfolio-calculator-baln-buy.spec.ts

@ -51,6 +51,8 @@ describe('PortfolioCalculator', () => {
parseDate('2021-11-30') parseDate('2021-11-30')
); );
const investments = portfolioCalculator.getInvestments();
const investmentsByMonth = portfolioCalculator.getInvestmentsByMonth(); const investmentsByMonth = portfolioCalculator.getInvestmentsByMonth();
spy.mockRestore(); spy.mockRestore();
@ -83,6 +85,10 @@ describe('PortfolioCalculator', () => {
totalInvestment: new Big('273.2') totalInvestment: new Big('273.2')
}); });
expect(investments).toEqual([
{ date: '2021-11-30', investment: new Big('273.2') }
]);
expect(investmentsByMonth).toEqual([ expect(investmentsByMonth).toEqual([
{ date: '2021-11-01', investment: new Big('273.2') } { date: '2021-11-01', investment: new Big('273.2') }
]); ]);

4
apps/api/src/app/portfolio/portfolio-calculator-no-orders.spec.ts

@ -39,6 +39,8 @@ describe('PortfolioCalculator', () => {
new Date() new Date()
); );
const investments = portfolioCalculator.getInvestments();
const investmentsByMonth = portfolioCalculator.getInvestmentsByMonth(); const investmentsByMonth = portfolioCalculator.getInvestmentsByMonth();
spy.mockRestore(); spy.mockRestore();
@ -54,6 +56,8 @@ describe('PortfolioCalculator', () => {
totalInvestment: new Big(0) totalInvestment: new Big(0)
}); });
expect(investments).toEqual([]);
expect(investmentsByMonth).toEqual([]); expect(investmentsByMonth).toEqual([]);
}); });
}); });

7
apps/api/src/app/portfolio/portfolio-calculator-novn-buy-and-sell-partially.spec.ts

@ -62,6 +62,8 @@ describe('PortfolioCalculator', () => {
parseDate('2022-03-07') parseDate('2022-03-07')
); );
const investments = portfolioCalculator.getInvestments();
const investmentsByMonth = portfolioCalculator.getInvestmentsByMonth(); const investmentsByMonth = portfolioCalculator.getInvestmentsByMonth();
spy.mockRestore(); spy.mockRestore();
@ -94,6 +96,11 @@ describe('PortfolioCalculator', () => {
totalInvestment: new Big('75.80') totalInvestment: new Big('75.80')
}); });
expect(investments).toEqual([
{ date: '2022-03-07', investment: new Big('151.6') },
{ date: '2022-04-08', investment: new Big('75.8') }
]);
expect(investmentsByMonth).toEqual([ expect(investmentsByMonth).toEqual([
{ date: '2022-03-01', investment: new Big('151.6') }, { date: '2022-03-01', investment: new Big('151.6') },
{ date: '2022-04-01', investment: new Big('-85.73') } { date: '2022-04-01', investment: new Big('-85.73') }

Loading…
Cancel
Save