forked from crackedstudio/tikka
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduplicate-detector.spec.ts
More file actions
58 lines (52 loc) · 1.55 KB
/
Copy pathduplicate-detector.spec.ts
File metadata and controls
58 lines (52 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { DuplicateDetector } from "./duplicate-detector";
import { DomainEvent } from "./event.types";
describe("DuplicateDetector", () => {
const detector = new DuplicateDetector();
it("derives a stable event identity from raw Horizon fields", () => {
const event: DomainEvent = {
type: "TicketPurchased",
schemaVersion: 2,
raffle_id: 7,
buyer: "GBUYER",
ticket_ids: [1, 2],
total_paid: "200",
};
expect(
detector.inspect(event, { ledger: "123", paging_token: "page-1" }),
).toEqual({
ledger: 123,
txHash: "page-1",
eventId: "page-1",
handlerName: "TicketProcessor.handleTicketPurchased",
schemaVersion: 2,
needsDatabase: true,
});
});
it("prefers the raw transaction id when both id and paging token exist", () => {
const event: DomainEvent = {
type: "RaffleCancelled",
raffle_id: 1,
reason: "expired",
};
expect(
detector.inspect(event, { ledger: 50, id: "tx-1", paging_token: "page-1" })
.eventId,
).toBe("tx-1");
});
it.each([
{ type: "DrawTriggered", schemaVersion: 1, raffle_id: 1, ledger: 10 },
{ type: "RandomnessRequested", schemaVersion: 1, raffle_id: 1, request_id: 9 },
{
type: "RandomnessReceived",
schemaVersion: 1,
raffle_id: 1,
seed: "aa",
proof: "bb",
},
] satisfies DomainEvent[])(
"marks %s as not requiring durable database mutation",
(event) => {
expect(detector.inspect(event, { ledger: 1 }).needsDatabase).toBe(false);
},
);
});