58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import type { BrokerageEvent } from "../api/useBrokerageEvents";
|
|
|
|
import { brokerageEventGroupKey } from "./event-key";
|
|
|
|
const base: BrokerageEvent = {
|
|
account: { id: "account-1", name: "Брокерский" },
|
|
date: "2026-08-20",
|
|
dateKind: "event",
|
|
displayName: "ОФЗ 26238",
|
|
figi: "FIGI",
|
|
instrumentUid: "UID",
|
|
isin: "RU000A0JX0J2",
|
|
logoName: null,
|
|
projectedAmount: { currency: "RUB", value: "100" },
|
|
ticker: "OFZ",
|
|
type: "coupon",
|
|
};
|
|
|
|
describe("brokerageEventGroupKey", () => {
|
|
it("uses date, preferred identity, exact type and dateKind", () => {
|
|
const key = brokerageEventGroupKey(base);
|
|
|
|
expect(brokerageEventGroupKey({
|
|
...base,
|
|
account: { id: "account-2", name: "ИИС" },
|
|
figi: "OTHER-FIGI",
|
|
})).toBe(key);
|
|
expect(brokerageEventGroupKey({ ...base, date: "2026-08-21" }))
|
|
.not.toBe(key);
|
|
expect(brokerageEventGroupKey({ ...base, dateKind: "registry" }))
|
|
.not.toBe(key);
|
|
expect(brokerageEventGroupKey({ ...base, type: "dividend" }))
|
|
.not.toBe(key);
|
|
});
|
|
|
|
it("falls back through FIGI and ISIN and rejects missing identity", () => {
|
|
expect(brokerageEventGroupKey({ ...base, instrumentUid: null }))
|
|
.toBe(brokerageEventGroupKey({ ...base, instrumentUid: "" }));
|
|
expect(brokerageEventGroupKey({
|
|
...base,
|
|
figi: null,
|
|
instrumentUid: null,
|
|
})).toBe(brokerageEventGroupKey({
|
|
...base,
|
|
figi: "",
|
|
instrumentUid: null,
|
|
}));
|
|
expect(brokerageEventGroupKey({
|
|
...base,
|
|
figi: null,
|
|
instrumentUid: null,
|
|
isin: null,
|
|
})).toBeNull();
|
|
});
|
|
});
|