Browse Source

fix(api): address PR review comments in symbol and symbol-profile services

pull/8404/head
KenTandrian 3 weeks ago
parent
commit
613826be91
  1. 85
      apps/api/src/services/symbol-profile/symbol-profile.service.spec.ts
  2. 4
      apps/api/src/services/symbol-profile/symbol-profile.service.ts
  3. 2
      apps/api/src/services/symbol/symbol.service.ts

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

@ -81,4 +81,89 @@ describe('SymbolProfileService', () => {
).resolves.toEqual([expect.objectContaining({ name: 'Apple' })]); ).resolves.toEqual([expect.objectContaining({ name: 'Apple' })]);
}); });
}); });
describe('getSymbolProfiles', () => {
let findManySymbolProfiles: jest.Mock;
let symbolProfileService: SymbolProfileService;
beforeEach(() => {
findManySymbolProfiles = jest.fn();
symbolProfileService = new SymbolProfileService({
symbolProfile: { findMany: findManySymbolProfiles }
} as unknown as PrismaService);
});
it('enhances the symbol profile and excludes relational metadata', async () => {
const dateOfFirstActivity = new Date('2024-01-15T00:00:00.000Z');
findManySymbolProfiles.mockResolvedValue([
{
_count: { activities: 3, watchedBy: 1 },
activities: [{ date: dateOfFirstActivity }],
assetProfileOverrides: { name: 'Apple Inc. (Custom)' },
currency: 'USD',
dataSource: DataSource.YAHOO,
isin: 'US0378331005',
name: 'Apple Inc.',
scraperConfiguration: {
defaultMarketPrice: 100,
headers: { 'User-Agent': 'Test' },
locale: 'en',
mode: 'lazy',
selector: '.price',
url: 'https://example.com'
},
symbol: 'AAPL'
}
]);
const [result] = await symbolProfileService.getSymbolProfiles([
{ dataSource: DataSource.YAHOO, symbol: 'AAPL' }
]);
expect(result).toEqual(
expect.objectContaining({
activitiesCount: 3,
dateOfFirstActivity,
name: 'Apple Inc. (Custom)',
scraperConfiguration: {
defaultMarketPrice: 100,
headers: { 'User-Agent': 'Test' },
locale: 'en',
mode: 'lazy',
selector: '.price',
url: 'https://example.com'
},
watchedByCount: 1
})
);
expect(result).not.toHaveProperty('_count');
expect(result).not.toHaveProperty('activities');
expect(result).not.toHaveProperty('assetProfileOverrides');
});
it('gives null for scraperConfiguration if none exists', async () => {
findManySymbolProfiles.mockResolvedValue([
{
_count: { activities: 0 },
assetProfileOverrides: null,
currency: 'USD',
dataSource: DataSource.YAHOO,
isin: 'US0378331005',
name: 'Apple Inc.',
scraperConfiguration: null,
symbol: 'AAPL'
}
]);
const [result] = await symbolProfileService.getSymbolProfiles([
{ dataSource: DataSource.YAHOO, symbol: 'AAPL' }
]);
expect(result.scraperConfiguration).toBeNull();
expect(result.dateOfFirstActivity).toBeUndefined();
expect(result.watchedByCount).toBe(0);
});
});
}); });

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

@ -357,7 +357,7 @@ export class SymbolProfileService {
private getScraperConfiguration( private getScraperConfiguration(
symbolProfile: SymbolProfile symbolProfile: SymbolProfile
): ScraperConfiguration | undefined { ): ScraperConfiguration | null {
const scraperConfiguration = const scraperConfiguration =
symbolProfile.scraperConfiguration as Prisma.JsonObject; symbolProfile.scraperConfiguration as Prisma.JsonObject;
@ -374,7 +374,7 @@ export class SymbolProfileService {
}; };
} }
return undefined; return null;
} }
private getSectors(aSectors: Prisma.JsonArray = []): Sector[] { private getSectors(aSectors: Prisma.JsonArray = []): Sector[] {

2
apps/api/src/services/symbol/symbol.service.ts

@ -41,7 +41,7 @@ export class SymbolService {
includeHistoricalData?: number; includeHistoricalData?: number;
useIntradayData?: boolean; useIntradayData?: boolean;
}): Promise<SymbolItem | undefined> { }): Promise<SymbolItem | undefined> {
let currency = ''; let currency: string;
let marketPrice: number; let marketPrice: number;
if (useIntradayData) { if (useIntradayData) {

Loading…
Cancel
Save