diff --git a/apps/api/src/app/core/portfolio-calculator.spec.ts b/apps/api/src/app/core/portfolio-calculator.spec.ts index 3ca9e08e4..551eeded1 100644 --- a/apps/api/src/app/core/portfolio-calculator.spec.ts +++ b/apps/api/src/app/core/portfolio-calculator.spec.ts @@ -19,53 +19,51 @@ import { } from 'date-fns'; function mockGetValue(symbol: string, date: Date) { - const today = new Date(); - if (symbol === 'VTI') { - if (isSameDay(today, date)) { - return { marketPrice: 213.32 }; - } else { - const startDate = parseDate('2019-02-01'); - const daysInBetween = differenceInCalendarDays(date, startDate); - - const marketPrice = new Big('144.38').plus( - new Big('0.08').mul(daysInBetween) - ); - return { marketPrice: marketPrice.toNumber() }; - } - } else if (symbol === 'AMZN') { - return { marketPrice: 2021.99 }; - } else if (symbol === 'MFA') { - if (isSameDay(parseDate('2010-12-31'), date)) { - return { marketPrice: 1 }; - } else if (isSameDay(parseDate('2011-08-15'), date)) { - return { marketPrice: 1.162484 }; // 1162484 / 1000000 - } else if (isSameDay(parseDate('2011-12-31'), date)) { - return { marketPrice: 1.097884981 }; // 1192328 / 1086022.689344541 - } + switch (symbol) { + case 'AMZN': + return { marketPrice: 2021.99 }; + case 'MFA': + if (isSameDay(parseDate('2010-12-31'), date)) { + return { marketPrice: 1 }; + } else if (isSameDay(parseDate('2011-08-15'), date)) { + return { marketPrice: 1.162484 }; // 1162484 / 1000000 + } else if (isSameDay(parseDate('2011-12-31'), date)) { + return { marketPrice: 1.097884981 }; // 1192328 / 1086022.689344541 + } - return { marketPrice: 0 }; - } else if (symbol === 'SPA') { - if (isSameDay(parseDate('2013-12-31'), date)) { - return { marketPrice: 1.025 }; // 205 / 200 - } + return { marketPrice: 0 }; + case 'SPA': + if (isSameDay(parseDate('2013-12-31'), date)) { + return { marketPrice: 1.025 }; // 205 / 200 + } - return { marketPrice: 0 }; - } else if (symbol === 'SPB') { - if (isSameDay(parseDate('2013-12-31'), date)) { - return { marketPrice: 1.04 }; // 312 / 300 - } + return { marketPrice: 0 }; + case 'SPB': + if (isSameDay(parseDate('2013-12-31'), date)) { + return { marketPrice: 1.04 }; // 312 / 300 + } - return { marketPrice: 0 }; - } else if (symbol === 'TSLA') { - if (isSameDay(parseDate('2021-07-26'), date)) { - return { marketPrice: 657.62 }; - } else if (isSameDay(parseDate('2021-01-02'), date)) { - return { marketPrice: 666.66 }; - } + return { marketPrice: 0 }; + case 'TSLA': + if (isSameDay(parseDate('2021-07-26'), date)) { + return { marketPrice: 657.62 }; + } else if (isSameDay(parseDate('2021-01-02'), date)) { + return { marketPrice: 666.66 }; + } - return { marketPrice: 0 }; - } else { - return { marketPrice: 0 }; + return { marketPrice: 0 }; + case 'VTI': + return { + marketPrice: new Big('144.38') + .plus( + new Big('0.08').mul( + differenceInCalendarDays(date, parseDate('2019-02-01')) + ) + ) + .toNumber() + }; + default: + return { marketPrice: 0 }; } } diff --git a/apps/api/src/models/portfolio.spec.ts b/apps/api/src/models/portfolio.spec.ts index 45d5932aa..cf28763a7 100644 --- a/apps/api/src/models/portfolio.spec.ts +++ b/apps/api/src/models/portfolio.spec.ts @@ -210,77 +210,6 @@ describe('Portfolio', () => { }); }); - describe(`works with today's orders`, () => { - it('should return ["BTC"]', async () => { - await portfolio.setOrders([ - { - accountId: DEFAULT_ACCOUNT_ID, - accountUserId: USER_ID, - createdAt: null, - currency: Currency.USD, - dataSource: DataSource.YAHOO, - fee: 0, - date: new Date(), - id: '8d999347-dee2-46ee-88e1-26b344e71fcc', - quantity: 1, - symbol: 'BTCUSD', - symbolProfileId: null, - type: Type.BUY, - unitPrice: 49631.24, - updatedAt: null, - userId: USER_ID - } - ]); - - const details = await portfolio.getDetails('1d'); - expect(details).toMatchObject({ - BTCUSD: { - accounts: { - [UNKNOWN_KEY]: { - /*current: exchangeRateDataService.toCurrency( - 1 * 49631.24, - Currency.USD, - baseCurrency - ),*/ - original: exchangeRateDataService.toCurrency( - 1 * 49631.24, - Currency.USD, - baseCurrency - ) - } - }, - allocationCurrent: 1, - allocationInvestment: 1, - countries: [], - currency: Currency.USD, - exchange: UNKNOWN_KEY, - grossPerformance: 0, - grossPerformancePercent: 0, - investment: exchangeRateDataService.toCurrency( - 1 * 49631.24, - Currency.USD, - baseCurrency - ), - marketPrice: 57973.008, - marketState: MarketState.open, - name: 'Bitcoin USD', - quantity: 1, - symbol: 'BTCUSD', - transactionCount: 1, - type: 'Cryptocurrency' - } - }); - - expect(portfolio.getFees()).toEqual(0); - - expect(portfolio.getPositions(getYesterday())).toMatchObject({}); - - expect(portfolio.getSymbols(getYesterday())).toEqual([]); - - expect(portfolio.getSymbols(new Date())).toEqual(['BTCUSD']); - }); - }); - describe('works with orders', () => { it('should return ["ETHUSD"]', async () => { await portfolio.setOrders([