Browse Source

Fix creation of asset profiles with symbol in wrong letter case by using original symbol

pull/7727/head
Thomas Kaul 1 day ago
parent
commit
aed50bebcc
  1. 18
      apps/api/src/services/symbol-profile/symbol-profile.service.spec.ts
  2. 10
      apps/api/src/services/symbol-profile/symbol-profile.service.ts

18
apps/api/src/services/symbol-profile/symbol-profile.service.spec.ts

@ -3,12 +3,18 @@ import { DataSource } from '@prisma/client';
import { SymbolProfileService } from './symbol-profile.service'; import { SymbolProfileService } from './symbol-profile.service';
describe('SymbolProfileService', () => { describe('SymbolProfileService', () => {
let prismaService: { symbolProfile: { findMany: jest.Mock } };
let symbolProfileService: SymbolProfileService; let symbolProfileService: SymbolProfileService;
let prismaService: {
symbolProfile: { findMany: jest.Mock; findUnique: jest.Mock };
};
beforeEach(() => { beforeEach(() => {
prismaService = { prismaService = {
symbolProfile: { findMany: jest.fn().mockResolvedValue([]) } symbolProfile: {
findMany: jest.fn().mockResolvedValue([]),
findUnique: jest.fn().mockResolvedValue(null)
}
}; };
symbolProfileService = new SymbolProfileService(prismaService as any); symbolProfileService = new SymbolProfileService(prismaService as any);
@ -16,9 +22,9 @@ describe('SymbolProfileService', () => {
describe('getSymbolOfAssetProfile', () => { describe('getSymbolOfAssetProfile', () => {
it('Keeps the symbol of the existing asset profile', async () => { it('Keeps the symbol of the existing asset profile', async () => {
prismaService.symbolProfile.findMany.mockResolvedValue([ prismaService.symbolProfile.findUnique.mockResolvedValue({
{ symbol: 'AAPL' } symbol: 'AAPL'
]); });
const symbol = await symbolProfileService.getSymbolOfAssetProfile({ const symbol = await symbolProfileService.getSymbolOfAssetProfile({
dataSource: DataSource.YAHOO, dataSource: DataSource.YAHOO,
@ -27,6 +33,7 @@ describe('SymbolProfileService', () => {
}); });
expect(symbol).toEqual('AAPL'); expect(symbol).toEqual('AAPL');
expect(prismaService.symbolProfile.findMany).not.toHaveBeenCalled();
}); });
it('Keeps the letter case of the existing asset profile', async () => { it('Keeps the letter case of the existing asset profile', async () => {
@ -100,6 +107,7 @@ describe('SymbolProfileService', () => {
expect(symbol).toEqual('GF_apple'); expect(symbol).toEqual('GF_apple');
expect(prismaService.symbolProfile.findMany).not.toHaveBeenCalled(); expect(prismaService.symbolProfile.findMany).not.toHaveBeenCalled();
expect(prismaService.symbolProfile.findUnique).not.toHaveBeenCalled();
}); });
}); });
}); });

10
apps/api/src/services/symbol-profile/symbol-profile.service.ts

@ -143,6 +143,16 @@ export class SymbolProfileService {
return symbol; return symbol;
} }
const symbolProfileWithSameSymbol =
await this.prismaService.symbolProfile.findUnique({
select: { symbol: true },
where: { dataSource_symbol: { dataSource, symbol } }
});
if (symbolProfileWithSameSymbol) {
return symbol;
}
const symbolProfiles = ( const symbolProfiles = (
await this.prismaService.symbolProfile.findMany({ await this.prismaService.symbolProfile.findMany({
orderBy: { symbol: 'asc' }, orderBy: { symbol: 'asc' },

Loading…
Cancel
Save