-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbaseDistributed.handler.spec.ts
More file actions
76 lines (61 loc) · 2.64 KB
/
baseDistributed.handler.spec.ts
File metadata and controls
76 lines (61 loc) · 2.64 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { beforeEach, describe, expect, it, vi } from "vitest";
import { IRoundReadRepository, Round } from "@grants-stack-indexer/repository";
import { ChainId, ILogger, ProcessorEvent } from "@grants-stack-indexer/shared";
import { BaseDistributedHandler } from "../../../src/processors/strategy/common/baseDistributed.handler.js";
import { createMockEvent } from "../../mocks/index.js";
describe("BaseDistributedHandler", () => {
let handler: BaseDistributedHandler;
let mockRoundRepository: IRoundReadRepository;
let mockEvent: ProcessorEvent<"Strategy", "DistributedWithRecipientAddress">;
const chainId = 10 as ChainId;
const eventName = "DistributedWithRecipientAddress";
const defaultParams = {
amount: "1000",
recipientAddress: "0x1234567890123456789012345678901234567890",
recipientId: "0x1234567890123456789012345678901234567890",
sender: "0x1234567890123456789012345678901234567890",
} as const;
const defaultStrategyId = "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0";
const logger: ILogger = {
debug: vi.fn(),
verbose: vi.fn(),
error: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
};
beforeEach(() => {
mockRoundRepository = {
getRoundByStrategyAddress: vi.fn(),
} as unknown as IRoundReadRepository;
});
it("increments round total distributed when round is found", async () => {
mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId);
const mockRound = { id: "round1" } as Round;
vi.spyOn(mockRoundRepository, "getRoundByStrategyAddress").mockResolvedValue(mockRound);
handler = new BaseDistributedHandler(mockEvent, chainId, {
roundRepository: mockRoundRepository,
logger,
});
const result = await handler.handle();
expect(result).toEqual([
{
type: "IncrementRoundTotalDistributed",
args: {
chainId,
roundId: "round1",
amount: BigInt(mockEvent.params.amount),
},
},
]);
});
it("returns an empty array when round is not found", async () => {
mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId);
vi.spyOn(mockRoundRepository, "getRoundByStrategyAddress").mockResolvedValue(undefined);
handler = new BaseDistributedHandler(mockEvent, chainId, {
roundRepository: mockRoundRepository,
logger,
});
const result = await handler.handle();
expect(result).toEqual([]);
});
});