Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

E2E tests #640

Open
wants to merge 18 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/kebab-case.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
"^\.\/build"
"^\.\/vendor"
"^\.\/\.next"
"^\.\/tests"
"\.sql$"
"\.md$"
"\.d.ts$"
Expand Down
4 changes: 4 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rootDir": "lib/",
"maxConcurrency": 1
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"start:serverless": "tsx src/adapters/github/github-actions.ts",
"start:watch": "nodemon --exec 'yarn start'",
"start": "probot run ./lib/src/index.js",
"prepare": "husky install"
"prepare": "husky install",
"test": "jest"
},
"dependencies": {
"@actions/core": "^1.10.0",
Expand Down Expand Up @@ -58,20 +59,22 @@
"node-html-parser": "^6.1.5",
"node-html-to-image": "^3.3.0",
"nodemon": "^2.0.19",
"octokit": "^3.1.0",
"prettier": "^2.7.1",
"probot": "^12.2.4",
"telegraf": "^4.11.2",
"tsx": "^3.12.7",
"yaml": "^2.2.2"
},
"devDependencies": {
"@jest/globals": "^29.6.2",
"@types/eslint": "^8.40.2",
"@types/jest": "^28.1.0",
"@types/libsodium-wrappers": "^0.7.10",
"@types/node": "^14.18.37",
"@types/source-map-support": "^0.5.6",
"eslint": "^8.43.0",
"jest": "^26.6.3",
"jest": "^29.6.2",
"nock": "^13.0.5",
"rimraf": "3.0.2",
"smee-client": "^1.2.2",
Expand Down
166 changes: 166 additions & 0 deletions tests/commands.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import { describe, expect, test } from "@jest/globals";
import { Probot, Server, run } from "probot";
import { EmitterWebhookEventName } from "@octokit/webhooks";
import { bindEvents } from "../src/bindings";
import { GithubEvent, Issue } from "../src/types";
import { Octokit } from "octokit";
import "dotenv/config";

let server: Server;
let octokit: Octokit;
const repo = process.env.TEST_REPO || "ubiquibot";
const owner = process.env.TEST_OWNER || "staging";
const pat = process.env.TEST_PAT;
let username = "";

beforeAll(async () => {
if (!pat) {
throw new Error("missing TEST_PAT");
}

server = await run(function main(app: Probot) {
const allowedEvents = Object.values(GithubEvent) as EmitterWebhookEventName[];
app.on(allowedEvents, bindEvents);
});

octokit = new Octokit({ auth: pat });

const { data } = await octokit.rest.users.getAuthenticated();
username = data.login;
});

afterAll(async () => {
await server.stop();
});

const waitForNWebhooks = (n: number) =>
new Promise<void>((resolve, reject) => {
const timer = setTimeout(() => {
reject(new Error("timeout"));
}, 10000);

let i = 0;
server.probotApp.onAny(() => {
i += 1;
if (i == n) {
clearTimeout(timer);
resolve();
}
});
});

const createComment = (issueNumber: number, body: string) => {
return octokit.rest.issues.createComment({
repo,
owner,
issue_number: issueNumber,
body: body,
});
};

const getLastComment = async (issueNumber: number) => {
const { data } = await octokit.rest.issues.listComments({
repo,
owner,
issue_number: issueNumber,
});
expect(data.length).toBeGreaterThan(0);
return data[data.length - 1];
};

const checkLastComment = async (issueNumber: number, expectedComment: string) => {
const lastComment = await getLastComment(issueNumber);
expect(lastComment.body).toBe(expectedComment);
};

describe("commmands test", () => {
let issue: Issue;

beforeAll(async () => {
const res = await octokit.rest.issues.create({
repo,
owner,
title: "E2E TEST",
});
issue = res.data as Issue;

await waitForNWebhooks(1);
}, 10000);

test("/wallet correct address", async () => {
const newWallet = "0x82AcFE58e0a6bE7100874831aBC56Ee13e2149e7";
await createComment(issue.number, `/wallet ${newWallet}`);
await waitForNWebhooks(2);
await checkLastComment(issue.number, `Updated the wallet address for @${username} successfully!\t Your new address: \`${newWallet}\``);
}, 10000);

test("/wallet wrong address", async () => {
const newWallet = "0x82AcFE58e0a6bE7100874831aBC56";
await createComment(issue.number, `/wallet ${newWallet}`);
await waitForNWebhooks(2);
await checkLastComment(issue.number, `Please include your wallet or ENS address.\n usage: /wallet 0x0000000000000000000000000000000000000000`);
}, 10000);

test("/multiplier", async () => {
await createComment(issue.number, `/multiplier @${username}`);
await waitForNWebhooks(2);

await checkLastComment(issue.number, `Successfully changed the payout multiplier for @${username} to 1. The reason is not provided.`);

await createComment(issue.number, `/multiplier @${username} 2`);
await waitForNWebhooks(2);

await checkLastComment(
issue.number,
`Successfully changed the payout multiplier for @${username} to 2. The reason is not provided. This feature is designed to limit the contributor's compensation for any bounty on the current repository due to other compensation structures (i.e. salary.) are you sure you want to use a bounty multiplier above 1?`
0x4007 marked this conversation as resolved.
Show resolved Hide resolved
);

await createComment(issue.number, `/multiplier @${username} 2 "Testing reason"`);
await waitForNWebhooks(2);

await checkLastComment(
issue.number,
`Successfully changed the payout multiplier for @${username} to 2. The reason provided is "Testing reason". This feature is designed to limit the contributor's compensation for any bounty on the current repository due to other compensation structures (i.e. salary.) are you sure you want to use a bounty multiplier above 1?`
);

await createComment(issue.number, `/multiplier @${username} abcd`);
await waitForNWebhooks(2);

await checkLastComment(issue.number, `Successfully changed the payout multiplier for @${username} to 1. The reason provided is "abcd".`);

await createComment(issue.number, `/multiplier abcd`);
await waitForNWebhooks(2);

await checkLastComment(issue.number, `Successfully changed the payout multiplier for @${username} to 1. The reason provided is "abcd".`);
}, 60000);

test("/query", async () => {
const newWallet = "0x82AcFE58e0a6bE7100874831aBC56Ee13e2149e7";
await createComment(issue.number, `/wallet ${newWallet}`);
await waitForNWebhooks(2);

const multiplier = "5";
await createComment(issue.number, `/multiplier @${username} ${multiplier} 'Testing'`);
await waitForNWebhooks(2);

await createComment(issue.number, `/query @${username}`);
await waitForNWebhooks(2);

await checkLastComment(issue.number, `@${username}'s wallet address is ${newWallet} and multiplier is ${multiplier}`);
}, 20000);

test("/query wrong username", async () => {
await createComment(issue.number, `/query @INVALID_$USERNAME`);
await waitForNWebhooks(2);

await checkLastComment(issue.number, `Invalid syntax for query command \n usage /query @user`);
}, 10000);

test("/help", async () => {
await createComment(issue.number, `/help`);
await waitForNWebhooks(2);

const lastComment = await getLastComment(issue.number);
expect(lastComment.body?.includes("Available commands")).toBe(true);
}, 10000);
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@
"pretty": false,
"skipLibCheck": true
},
"include": ["src/"],
"include": ["src/", "tests/"],
"compileOnSave": false
}
Loading