45 lines
1.0 KiB
TypeScript
45 lines
1.0 KiB
TypeScript
import { expect, it } from "vitest";
|
|
|
|
import type { BrokerageOperation } from "@/entities/broker-operation";
|
|
|
|
import { toInstrumentEventRows } from "./operation-rows";
|
|
|
|
const operation: BrokerageOperation = {
|
|
accruedInterest: null,
|
|
category: "trade",
|
|
commission: null,
|
|
description: "Покупка",
|
|
figi: null,
|
|
id: "first",
|
|
instrumentType: "stock",
|
|
instrumentUid: "uid",
|
|
logoName: null,
|
|
occurredAt: "2026-01-01T00:00:00Z",
|
|
payment: null,
|
|
price: null,
|
|
quantity: null,
|
|
ticker: null,
|
|
type: "OPERATION_TYPE_BUY",
|
|
};
|
|
|
|
it("fills only missing identity without changing rows or their order", () => {
|
|
const items = [operation, {
|
|
...operation,
|
|
id: "second",
|
|
logoName: "",
|
|
ticker: "own",
|
|
}];
|
|
|
|
const original = structuredClone(items);
|
|
expect(toInstrumentEventRows(items, {
|
|
logoName: "fallback.png",
|
|
ticker: "fallback",
|
|
})).toEqual([
|
|
{ ...operation, logoName: "fallback.png", ticker: "fallback" },
|
|
items[1],
|
|
]);
|
|
expect(items).toEqual(original);
|
|
expect(toInstrumentEventRows(items)).toEqual(items);
|
|
expect(toInstrumentEventRows()).toEqual([]);
|
|
});
|