pull/239/head
Valentin Zickner 4 years ago committed by Thomas
parent 6a7def6c48
commit 4bbd17a37a

@ -19,53 +19,51 @@ import {
} from 'date-fns'; } from 'date-fns';
function mockGetValue(symbol: string, date: Date) { function mockGetValue(symbol: string, date: Date) {
const today = new Date(); switch (symbol) {
if (symbol === 'VTI') { case 'AMZN':
if (isSameDay(today, date)) { return { marketPrice: 2021.99 };
return { marketPrice: 213.32 }; case 'MFA':
} else { if (isSameDay(parseDate('2010-12-31'), date)) {
const startDate = parseDate('2019-02-01'); return { marketPrice: 1 };
const daysInBetween = differenceInCalendarDays(date, startDate); } else if (isSameDay(parseDate('2011-08-15'), date)) {
return { marketPrice: 1.162484 }; // 1162484 / 1000000
const marketPrice = new Big('144.38').plus( } else if (isSameDay(parseDate('2011-12-31'), date)) {
new Big('0.08').mul(daysInBetween) return { marketPrice: 1.097884981 }; // 1192328 / 1086022.689344541
); }
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
}
return { marketPrice: 0 }; return { marketPrice: 0 };
} else if (symbol === 'SPA') { case 'SPA':
if (isSameDay(parseDate('2013-12-31'), date)) { if (isSameDay(parseDate('2013-12-31'), date)) {
return { marketPrice: 1.025 }; // 205 / 200 return { marketPrice: 1.025 }; // 205 / 200
} }
return { marketPrice: 0 }; return { marketPrice: 0 };
} else if (symbol === 'SPB') { case 'SPB':
if (isSameDay(parseDate('2013-12-31'), date)) { if (isSameDay(parseDate('2013-12-31'), date)) {
return { marketPrice: 1.04 }; // 312 / 300 return { marketPrice: 1.04 }; // 312 / 300
} }
return { marketPrice: 0 }; return { marketPrice: 0 };
} else if (symbol === 'TSLA') { case 'TSLA':
if (isSameDay(parseDate('2021-07-26'), date)) { if (isSameDay(parseDate('2021-07-26'), date)) {
return { marketPrice: 657.62 }; return { marketPrice: 657.62 };
} else if (isSameDay(parseDate('2021-01-02'), date)) { } else if (isSameDay(parseDate('2021-01-02'), date)) {
return { marketPrice: 666.66 }; return { marketPrice: 666.66 };
} }
return { marketPrice: 0 }; return { marketPrice: 0 };
} else { case 'VTI':
return { marketPrice: 0 }; return {
marketPrice: new Big('144.38')
.plus(
new Big('0.08').mul(
differenceInCalendarDays(date, parseDate('2019-02-01'))
)
)
.toNumber()
};
default:
return { marketPrice: 0 };
} }
} }

@ -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', () => { describe('works with orders', () => {
it('should return ["ETHUSD"]', async () => { it('should return ["ETHUSD"]', async () => {
await portfolio.setOrders([ await portfolio.setOrders([

Loading…
Cancel
Save