You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

113 lines
3.3 KiB

import { DataSource } from '@prisma/client';
import { SymbolProfileService } from './symbol-profile.service';
describe('SymbolProfileService', () => {
let symbolProfileService: SymbolProfileService;
let prismaService: {
symbolProfile: { findMany: jest.Mock; findUnique: jest.Mock };
};
beforeEach(() => {
prismaService = {
symbolProfile: {
findMany: jest.fn().mockResolvedValue([]),
findUnique: jest.fn().mockResolvedValue(null)
}
};
symbolProfileService = new SymbolProfileService(prismaService as any);
});
describe('getSymbolOfAssetProfile', () => {
it('Keeps the symbol of the existing asset profile', async () => {
prismaService.symbolProfile.findUnique.mockResolvedValue({
symbol: 'AAPL'
});
const symbol = await symbolProfileService.getSymbolOfAssetProfile({
dataSource: DataSource.YAHOO,
symbol: 'AAPL',
symbolOfDataProvider: 'AAPL'
});
expect(symbol).toEqual('AAPL');
expect(prismaService.symbolProfile.findMany).not.toHaveBeenCalled();
});
it('Keeps the letter case of the existing asset profile', async () => {
prismaService.symbolProfile.findMany.mockResolvedValue([
{ symbol: 'aapl' }
]);
const symbol = await symbolProfileService.getSymbolOfAssetProfile({
dataSource: DataSource.YAHOO,
symbol: 'AAPL',
symbolOfDataProvider: 'AAPL'
});
expect(symbol).toEqual('aapl');
});
it('Prefers the asset profile with the same letter case', async () => {
prismaService.symbolProfile.findMany.mockResolvedValue([
{ symbol: 'AAPL' },
{ symbol: 'aapl' }
]);
const symbol = await symbolProfileService.getSymbolOfAssetProfile({
dataSource: DataSource.YAHOO,
symbol: 'aapl',
symbolOfDataProvider: 'AAPL'
});
expect(symbol).toEqual('aapl');
});
it('Ignores an asset profile which a wildcard of the query matched', async () => {
prismaService.symbolProfile.findMany.mockResolvedValue([
{ symbol: 'AAPL' }
]);
const symbol = await symbolProfileService.getSymbolOfAssetProfile({
dataSource: DataSource.YAHOO,
symbol: 'aa_l',
symbolOfDataProvider: 'AA_L'
});
expect(symbol).toEqual('AA_L');
});
it('Uses the symbol of the data provider if no asset profile exists', async () => {
const symbol = await symbolProfileService.getSymbolOfAssetProfile({
dataSource: DataSource.YAHOO,
symbol: 'aapl',
symbolOfDataProvider: 'AAPL'
});
expect(symbol).toEqual('AAPL');
});
it('Keeps the requested symbol if the data provider reports no symbol', async () => {
const symbol = await symbolProfileService.getSymbolOfAssetProfile({
dataSource: DataSource.YAHOO,
symbol: 'aapl'
});
expect(symbol).toEqual('aapl');
});
it('Keeps the symbol of a custom asset profile', async () => {
const symbol = await symbolProfileService.getSymbolOfAssetProfile({
dataSource: DataSource.MANUAL,
symbol: 'GF_apple',
symbolOfDataProvider: 'GF_APPLE'
});
expect(symbol).toEqual('GF_apple');
expect(prismaService.symbolProfile.findMany).not.toHaveBeenCalled();
expect(prismaService.symbolProfile.findUnique).not.toHaveBeenCalled();
});
});
});