Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1e1757842 | ||
|
|
288b9d7fcc |
@@ -249,9 +249,8 @@ breaking changes относительно предыдущего выпуска.
|
|||||||
настраивается отдельно. История migrations применяется штатным `migrate deploy`.
|
настраивается отдельно. История migrations применяется штатным `migrate deploy`.
|
||||||
|
|
||||||
Регрессия самого запуска: `node test/sqlite-regression.cjs`. Она выполняет
|
Регрессия самого запуска: `node test/sqlite-regression.cjs`. Она выполняет
|
||||||
три последовательных и два параллельных запуска двух обычных e2e suites,
|
три последовательных и два параллельных полных e2e, проверяет уникальность DB,
|
||||||
проверяет уникальность DB, сохранность вымышленного внешнего файла, отказ migration
|
сохранность вымышленного внешнего файла, отказ migration и SIGINT/SIGTERM cleanup.
|
||||||
и SIGINT/SIGTERM cleanup. Полный e2e набор остаётся в `npm run test:e2e`.
|
|
||||||
Логи остаются в каталоге из вывода. Для одной suite:
|
Логи остаются в каталоге из вывода. Для одной suite:
|
||||||
`node test/sqlite.cjs app.e2e-spec.ts`.
|
`node test/sqlite.cjs app.e2e-spec.ts`.
|
||||||
|
|
||||||
|
|||||||
@@ -91,101 +91,6 @@ export class BankOperationsService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private async pageViews(tx: Tx, rows: BankCardOperation[]) {
|
|
||||||
const userId = rows[0]?.userId;
|
|
||||||
if (!userId) return [];
|
|
||||||
const cardIds = new Set(
|
|
||||||
rows.flatMap((row) =>
|
|
||||||
[row.cardId, row.targetCardId].filter(
|
|
||||||
(id): id is string => id !== null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
const sourceIds = new Set(
|
|
||||||
rows.flatMap((row) => (row.originalExpenseId ? [row.originalExpenseId] : [])),
|
|
||||||
);
|
|
||||||
const [cards, sources] = await Promise.all([
|
|
||||||
tx.bankCard.findMany({ where: { userId, id: { in: [...cardIds] } } }),
|
|
||||||
tx.bankCardOperation.findMany({
|
|
||||||
where: { userId, id: { in: [...sourceIds] } },
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
const categoryIds = new Set(
|
|
||||||
rows
|
|
||||||
.map(
|
|
||||||
(row) =>
|
|
||||||
sources.find((source) => source.id === row.originalExpenseId)
|
|
||||||
?.categoryId ?? row.categoryId,
|
|
||||||
)
|
|
||||||
.filter((id): id is string => id !== null),
|
|
||||||
);
|
|
||||||
const expenseIds = new Set(
|
|
||||||
rows.flatMap((row) => {
|
|
||||||
const source = sources.find((item) => item.id === row.originalExpenseId);
|
|
||||||
return row.kind === BankOperationKind.Expense || source
|
|
||||||
? [source?.id ?? row.id]
|
|
||||||
: [];
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const [categories, refunds] = await Promise.all([
|
|
||||||
tx.expenseCategory.findMany({
|
|
||||||
where: { userId, id: { in: [...categoryIds] } },
|
|
||||||
}),
|
|
||||||
tx.bankCardOperation.findMany({
|
|
||||||
where: {
|
|
||||||
userId,
|
|
||||||
originalExpenseId: { in: [...expenseIds] },
|
|
||||||
deletedAt: null,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
const cardsById = new Map(cards.map((card) => [card.id, card]));
|
|
||||||
const sourcesById = new Map(sources.map((source) => [source.id, source]));
|
|
||||||
const categoriesById = new Map(categories.map((category) => [category.id, category]));
|
|
||||||
return rows.map((row) => {
|
|
||||||
const card = cardsById.get(row.cardId) as { name: string };
|
|
||||||
const target = row.targetCardId ? cardsById.get(row.targetCardId) : null;
|
|
||||||
const source = row.originalExpenseId
|
|
||||||
? sourcesById.get(row.originalExpenseId)
|
|
||||||
: null;
|
|
||||||
const categoryId = source?.categoryId ?? row.categoryId;
|
|
||||||
const relatedRefunds =
|
|
||||||
row.kind === BankOperationKind.Expense || source
|
|
||||||
? refunds.filter(
|
|
||||||
(refund) =>
|
|
||||||
refund.originalExpenseId === (source?.id ?? row.id) &&
|
|
||||||
(!source || refund.id !== row.id),
|
|
||||||
)
|
|
||||||
: [];
|
|
||||||
return {
|
|
||||||
id: row.id,
|
|
||||||
kind: row.kind as BankOperationDto['kind'],
|
|
||||||
cardId: row.cardId,
|
|
||||||
cardName: card.name,
|
|
||||||
targetCardId: row.targetCardId,
|
|
||||||
targetCardName: target?.name ?? null,
|
|
||||||
categoryId,
|
|
||||||
categoryName: categoriesById.get(categoryId ?? '')?.name ?? null,
|
|
||||||
originalExpenseId: row.originalExpenseId,
|
|
||||||
amount: rubMoney(row.amountKopecks),
|
|
||||||
availableRefund:
|
|
||||||
row.kind === BankOperationKind.Expense || source
|
|
||||||
? rubMoney(
|
|
||||||
(source?.amountKopecks ?? row.amountKopecks) -
|
|
||||||
relatedRefunds.reduce(
|
|
||||||
(sum, refund) => sum + refund.amountKopecks,
|
|
||||||
ZERO_KOPECKS,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
date: row.date,
|
|
||||||
description: row.description,
|
|
||||||
version: row.version,
|
|
||||||
createdAt: row.createdAt.toISOString(),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private async validateOperation(
|
private async validateOperation(
|
||||||
tx: Tx,
|
tx: Tx,
|
||||||
userId: string,
|
userId: string,
|
||||||
@@ -454,7 +359,9 @@ export class BankOperationsService {
|
|||||||
take: limit,
|
take: limit,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
items: await this.pageViews(tx, rows),
|
items: await Promise.all(
|
||||||
|
rows.map((row) => this.operationView(tx, row)),
|
||||||
|
),
|
||||||
total,
|
total,
|
||||||
page,
|
page,
|
||||||
hasNext: page * limit < total,
|
hasNext: page * limit < total,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ writeFileSync(sentinel, 'fictional user database: must never be opened');
|
|||||||
const before = readFileSync(sentinel);
|
const before = readFileSync(sentinel);
|
||||||
const databases = new Set();
|
const databases = new Set();
|
||||||
async function check(name, overrides = {}, signal) {
|
async function check(name, overrides = {}, signal) {
|
||||||
const child = spawn(process.execPath, ['test/sqlite.cjs'], {
|
const child = spawn(process.execPath, ['test/sqlite.cjs', '--all'], {
|
||||||
cwd,
|
cwd,
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
|
|||||||
Reference in New Issue
Block a user