generated from defi-wonderland/ts-turborepo-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: dvmd direct transfer strategy handler
- Loading branch information
Showing
1 changed file
with
101 additions
and
2 deletions.
There are no files selected for viewing
103 changes: 101 additions & 2 deletions
103
...trategy/donationVotingMerkleDistributionDirectTransfer/dvmdDirectTransfer.handler.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,104 @@ | ||
import { describe, it } from "vitest"; | ||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
||
import type { IMetadataProvider } from "@grants-stack-indexer/metadata"; | ||
import type { | ||
IProjectReadRepository, | ||
IRoundReadRepository, | ||
} from "@grants-stack-indexer/repository"; | ||
import { ChainId, ProtocolEvent, StrategyEvent } from "@grants-stack-indexer/shared"; | ||
|
||
import { UnsupportedEventException } from "../../../src/internal.js"; | ||
import { DVMDDirectTransferHandler } from "../../../src/strategy/donationVotingMerkleDistributionDirectTransfer/dvmdDirectTransfer.handler.js"; | ||
import { | ||
DVMDDistributedHandler, | ||
DVMDRegisteredHandler, | ||
} from "../../../src/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/index.js"; | ||
|
||
vi.mock( | ||
"../../../src/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/index.js", | ||
() => { | ||
const DVMDRegisteredHandler = vi.fn(); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
DVMDRegisteredHandler.prototype.handle = vi.fn(); | ||
const DVMDDistributedHandler = vi.fn(); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
DVMDDistributedHandler.prototype.handle = vi.fn(); | ||
return { | ||
DVMDRegisteredHandler, | ||
DVMDDistributedHandler, | ||
}; | ||
}, | ||
); | ||
|
||
describe("DVMDDirectTransferHandler", () => { | ||
it.skip("handle the direct transfer event", () => {}); | ||
const mockChainId = 10 as ChainId; | ||
let handler: DVMDDirectTransferHandler; | ||
let mockMetadataProvider: IMetadataProvider; | ||
let mockRoundRepository: IRoundReadRepository; | ||
let mockProjectRepository: IProjectReadRepository; | ||
|
||
beforeEach(() => { | ||
mockMetadataProvider = {} as IMetadataProvider; | ||
mockRoundRepository = {} as IRoundReadRepository; | ||
mockProjectRepository = {} as IProjectReadRepository; | ||
|
||
handler = new DVMDDirectTransferHandler(mockChainId, { | ||
metadataProvider: mockMetadataProvider, | ||
roundRepository: mockRoundRepository, | ||
projectRepository: mockProjectRepository, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it("calls RegisteredHandler for Registered event", async () => { | ||
const mockEvent = { | ||
eventName: "Registered", | ||
} as ProtocolEvent<"Strategy", "Registered">; | ||
|
||
vi.spyOn(DVMDRegisteredHandler.prototype, "handle").mockResolvedValue([]); | ||
|
||
await handler.handle(mockEvent); | ||
|
||
expect(DVMDRegisteredHandler).toHaveBeenCalledWith(mockEvent, mockChainId, { | ||
metadataProvider: mockMetadataProvider, | ||
roundRepository: mockRoundRepository, | ||
projectRepository: mockProjectRepository, | ||
}); | ||
expect(DVMDRegisteredHandler.prototype.handle).toHaveBeenCalled(); | ||
}); | ||
|
||
it("calls DistributedHandler for Distributed event", async () => { | ||
const mockEvent = { | ||
eventName: "Distributed", | ||
} as ProtocolEvent<"Strategy", "Distributed">; | ||
|
||
vi.spyOn(DVMDDistributedHandler.prototype, "handle").mockResolvedValue([]); | ||
|
||
await handler.handle(mockEvent); | ||
|
||
expect(DVMDDistributedHandler).toHaveBeenCalledWith(mockEvent, mockChainId, { | ||
metadataProvider: mockMetadataProvider, | ||
roundRepository: mockRoundRepository, | ||
projectRepository: mockProjectRepository, | ||
}); | ||
expect(DVMDDistributedHandler.prototype.handle).toHaveBeenCalled(); | ||
}); | ||
|
||
it.skip("calls AllocatedHandler for Allocated event"); | ||
it.skip("calls TimestampsUpdatedHandler for TimestampsUpdated event"); | ||
it.skip("calls RecipientStatusUpdatedHandler for RecipientStatusUpdated event"); | ||
it.skip("calls DistributionUpdatedHandler for DistributionUpdated event"); | ||
it.skip("calls UpdatedRegistrationHandler for UpdatedRegistration event"); | ||
it.skip("calls FundsDistributedHandler for FundsDistributed event"); | ||
|
||
it("throws UnsupportedEventException for unknown event names", async () => { | ||
const mockEvent = { eventName: "UnknownEvent" } as unknown as ProtocolEvent< | ||
"Strategy", | ||
StrategyEvent | ||
>; | ||
await expect(() => handler.handle(mockEvent)).rejects.toThrow(UnsupportedEventException); | ||
}); | ||
}); |