chore: strengthen backend eslint profile
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { setTimeout as delay } from 'node:timers/promises';
|
||||
import { CandleService } from '../src/modules/investments/instruments/application/candle.service';
|
||||
|
||||
import { TbankAccessService } from '../src/integrations/tbank/tbank-access.service';
|
||||
import { TbankTokenService } from '../src/integrations/tbank/tbank-token.service';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { PrismaService } from '../src/prisma/prisma.service';
|
||||
import { CandleRepository } from '../src/modules/investments/instruments/infrastructure/candle.repository';
|
||||
import { CandleService } from '../src/modules/investments/instruments/application/candle.service';
|
||||
import {
|
||||
candleGaps,
|
||||
type CandleRange,
|
||||
} from '../src/modules/investments/instruments/domain/candle-coverage';
|
||||
import { CandleRepository } from '../src/modules/investments/instruments/infrastructure/candle.repository';
|
||||
import { PrismaService } from '../src/prisma/prisma.service';
|
||||
|
||||
describe('atomic shared candle reconciliation (SQLite)', () => {
|
||||
const prisma = new PrismaService(
|
||||
@@ -56,8 +57,9 @@ describe('atomic shared candle reconciliation (SQLite)', () => {
|
||||
);
|
||||
async function settled() {
|
||||
for (let i = 0; i < 500; i++) {
|
||||
if (!(await prisma.tbankSyncWork.count({ where: { state: 'running' } })))
|
||||
if (!(await prisma.tbankSyncWork.count({ where: { state: 'running' } }))) {
|
||||
return;
|
||||
}
|
||||
await delay(5);
|
||||
}
|
||||
throw new Error('Candle work did not settle');
|
||||
@@ -225,10 +227,11 @@ describe('atomic shared candle reconciliation (SQLite)', () => {
|
||||
string,
|
||||
Date,
|
||||
Date,
|
||||
][])
|
||||
][]) {
|
||||
expect(call[3].valueOf() - call[2].valueOf()).toBeLessThanOrEqual(
|
||||
365 * 86400000,
|
||||
);
|
||||
}
|
||||
await prisma.$disconnect();
|
||||
const reopened = createService();
|
||||
expect((await reopened.read('owner', input)).data?.candles).toEqual([]);
|
||||
@@ -353,13 +356,13 @@ describe('atomic shared candle reconciliation (SQLite)', () => {
|
||||
...sources,
|
||||
ensureDetail: jest.fn().mockResolvedValue(history),
|
||||
};
|
||||
if (phase === 'before loading')
|
||||
if (phase === 'before loading') {
|
||||
selectedSources.ensureDetail.mockImplementationOnce(async () => {
|
||||
entered();
|
||||
await blocked;
|
||||
return history;
|
||||
});
|
||||
else {
|
||||
} else {
|
||||
const publish = repository.publish.bind(repository);
|
||||
jest
|
||||
.spyOn(repository, 'publish')
|
||||
@@ -377,8 +380,9 @@ describe('atomic shared candle reconciliation (SQLite)', () => {
|
||||
Awaited<ReturnType<CandleRepository['read']>> | undefined;
|
||||
upstream.getCandles.mockImplementation(
|
||||
async (_token, _uid, _from, to: Date) => {
|
||||
if (laterFailure && forcedStates.length)
|
||||
if (laterFailure && forcedStates.length) {
|
||||
throw new Error('Forced reconciliation second window unavailable');
|
||||
}
|
||||
if (to.valueOf() === forcedAt.valueOf()) {
|
||||
beforeForced = await repository.read('uid', fullRange);
|
||||
const work = await repository.work(
|
||||
@@ -424,12 +428,16 @@ describe('atomic shared candle reconciliation (SQLite)', () => {
|
||||
await settled();
|
||||
|
||||
if (laterFailure) {
|
||||
// eslint-disable-next-line jest/no-conditional-expect -- The parameterized fixture chooses the scenario; each branch asserts its outcome and the test also asserts common invariants.
|
||||
expect(beforeForced).toBeDefined();
|
||||
// eslint-disable-next-line jest/no-conditional-expect -- The parameterized fixture chooses the scenario; each branch asserts its outcome and the test also asserts common invariants.
|
||||
expect(await repository.read('uid', fullRange)).toEqual(beforeForced);
|
||||
} else
|
||||
} else {
|
||||
// eslint-disable-next-line jest/no-conditional-expect -- The parameterized fixture chooses the scenario; each branch asserts its outcome and the test also asserts common invariants.
|
||||
expect((await repository.read('uid', covered)).data).toEqual([
|
||||
{ ...old, close: '200.000000001' },
|
||||
]);
|
||||
}
|
||||
expect(forcedStates).toEqual(['running']);
|
||||
expect(
|
||||
await repository.work(userId, 'revision', 'candles:uid:all'),
|
||||
@@ -442,7 +450,9 @@ describe('atomic shared candle reconciliation (SQLite)', () => {
|
||||
now: forcedAt.toISOString(),
|
||||
},
|
||||
});
|
||||
// eslint-disable-next-line jest/no-conditional-expect -- The parameterized fixture chooses the scenario; each branch asserts its outcome and the test also asserts common invariants.
|
||||
if (userId === owner.userId) expect(forcedId).toBe(ordinaryId);
|
||||
// eslint-disable-next-line jest/no-conditional-expect -- The parameterized fixture chooses the scenario; each branch asserts its outcome and the test also asserts common invariants.
|
||||
else expect(forcedId).not.toBe(ordinaryId);
|
||||
},
|
||||
);
|
||||
@@ -495,8 +505,9 @@ describe('atomic shared candle reconciliation (SQLite)', () => {
|
||||
{ instrumentUid: 'not-supported', type: 'FUND' },
|
||||
{ instrumentUid: null, type: 'BOND' },
|
||||
]);
|
||||
for (let i = 0; i < 100 && !upstream.getCandles.mock.calls.length; i++)
|
||||
for (let i = 0; i < 100 && !upstream.getCandles.mock.calls.length; i++) {
|
||||
await delay(5);
|
||||
}
|
||||
expect((upstream.getCandles.mock.calls as unknown[][])[0]?.[1]).toBe('uid');
|
||||
await service.read('owner', {
|
||||
uid: 'opened',
|
||||
@@ -510,7 +521,7 @@ describe('atomic shared candle reconciliation (SQLite)', () => {
|
||||
);
|
||||
expect(
|
||||
new Set(upstream.getCandles.mock.calls.map((call: unknown[]) => call[1])),
|
||||
).toEqual(new Set(['uid', 'opened']));
|
||||
).toEqual(new Set(['opened', 'uid']));
|
||||
const count = upstream.getCandles.mock.calls.length;
|
||||
await service.prefetch('owner', 'revision', [
|
||||
{ instrumentUid: 'uid', type: 'STOCK' },
|
||||
|
||||
Reference in New Issue
Block a user