From 1ea66e203fee7c36d4d6ab22f826c2f8ce2acdee Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Tue, 15 Oct 2024 13:32:13 +0900 Subject: [PATCH] test: add fee tests for GithubCommentModule Created detailed unit tests to verify fee calculation. --- tests/fees.test.ts | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tests/fees.test.ts diff --git a/tests/fees.test.ts b/tests/fees.test.ts new file mode 100644 index 00000000..8db57cca --- /dev/null +++ b/tests/fees.test.ts @@ -0,0 +1,88 @@ +import { GithubCommentModule } from "../src/parser/github-comment-module"; +import { Result } from "../src/parser/processor"; + +const issueUrl = "https://github.com/ubiquity/work.ubq.fi/issues/69"; + +jest.mock("../src/parser/command-line", () => { + const cfg = require("./__mocks__/results/valid-configuration.json"); + const dotenv = require("dotenv"); + dotenv.config(); + return { + stateId: 1, + eventName: "issues.closed", + authToken: process.env.GITHUB_TOKEN, + ref: "", + eventPayload: { + issue: { + html_url: issueUrl, + number: 69, + state_reason: "completed", + }, + repository: { + name: "conversation-rewards", + owner: { + login: "ubiquity-os", + id: 76412717, + }, + }, + }, + settings: JSON.stringify(cfg), + }; +}); + +jest.mock("../src/helpers/web3", () => ({ + getErc20TokenSymbol() { + return "WXDAI"; + }, +})); + +describe("GithubCommentModule Fee Tests", () => { + let githubCommentModule: GithubCommentModule; + + beforeEach(() => { + githubCommentModule = new GithubCommentModule(); + }); + + it("should display the fee message when a fee percentage is applied", async () => { + const result: Result = { + "ubiquity-os": { + comments: [], + total: 100, // Example value + task: { + reward: 50, // Example value + multiplier: 1.5, // Example value + }, + feeRate: 0.2, // This implies a 5% fee + permitUrl: "https://pay.ubq.fi", // Example URL + userId: 12345, // Example user ID + evaluationCommentHtml: "", + }, + }; + + jest.spyOn(githubCommentModule, "_generateHtml"); + + const bodyContent = await githubCommentModule.getBodyContent(result); + + expect(bodyContent).toEqual( + '

 [ 100 WXDAI ] 

@ubiquity-os
⚠️ 20% fee rate has been applied. Consider using theUbiquity Dollarfor no fees.
Contributions Overview
ViewContributionCountReward
IssueTask1.550
Conversation Incentives
CommentFormattingRelevanceReward
\n' + + "" + ); + }); +});