Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: tests for modules #14

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3144662
chore: formatting evaluator tests
gentlementlegen Apr 20, 2024
77ba319
chore: content evaluator tests
gentlementlegen Apr 21, 2024
6d2ff7b
chore: fake wallet db
gentlementlegen Apr 21, 2024
4b2fb40
chore: tests for permit generation
gentlementlegen Apr 21, 2024
d24b998
chore: changed body type to an array of string
gentlementlegen Apr 21, 2024
e77d749
Merge branch 'refs/heads/feat/github-comment' into feat/testing
gentlementlegen Apr 22, 2024
193a160
chore: test for github comment
gentlementlegen Apr 22, 2024
27aa759
chore: fixed knip checks
gentlementlegen Apr 22, 2024
34ad6dc
chore: fetching all the comments from pull-requests
gentlementlegen Apr 23, 2024
391e96e
chore: sanitizing content to avoid accidentally rendering html
gentlementlegen Apr 23, 2024
aef3ff4
chore: added contribution detail to formatting
gentlementlegen Apr 23, 2024
f8842a3
chore: ignore mentioned pull request for result calculation
gentlementlegen Apr 24, 2024
bb3d121
chore: fixed data purge for commands
gentlementlegen Apr 24, 2024
5794c4b
chore: merged branch
gentlementlegen Apr 24, 2024
e483216
chore: added missing comments on collect
gentlementlegen Apr 24, 2024
99c3e09
chore: updated test results
gentlementlegen Apr 24, 2024
485fc5c
chore: fixed knip and cspell
gentlementlegen Apr 24, 2024
737f371
chore: fixed knip
gentlementlegen Apr 24, 2024
a4b0f21
chore: changed fs import
gentlementlegen Apr 24, 2024
f0346c4
chore: fixed jest testing file
gentlementlegen Apr 24, 2024
90e150f
chore: renamed task to specification
gentlementlegen Apr 24, 2024
424609b
chore: added specification to details
gentlementlegen Apr 24, 2024
f531882
Merge branch 'refs/heads/development' into feat/testing
gentlementlegen Apr 25, 2024
b0c3446
chore: fixed merged reverting changes
gentlementlegen Apr 25, 2024
4156b4d
chore: removed URL cleaning from comment body
gentlementlegen May 2, 2024
7f3297a
chore: properly match all closing issue patterns in body
gentlementlegen May 2, 2024
989e56f
chore: changed default configuration
gentlementlegen May 2, 2024
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@octokit/rest": "20.1.0",
"@sinclair/typebox": "0.32.20",
"@supabase/supabase-js": "2.42.0",
"@ubiquibot/permit-generation": "1.2.1",
"@ubiquibot/permit-generation": "1.2.2",
"commander": "12.0.0",
"decimal.js": "10.4.3",
"dotenv": "16.4.5",
Expand All @@ -50,6 +50,7 @@
"@cspell/dict-node": "4.0.3",
"@cspell/dict-software-terms": "3.3.18",
"@cspell/dict-typescript": "3.1.2",
"@mswjs/data": "0.16.1",
"@types/jest": "29.5.12",
"@types/jsdom": "21.1.6",
"@types/markdown-it": "13.0.7",
Expand Down
2 changes: 1 addition & 1 deletion src/parser/command-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (process.env.NODE_ENV === "test") {
process.argv.push("-n");
process.argv.push("100");
process.argv.push("-e");
process.argv.push("privateKey");
process.argv.push(`${process.env.EVM_PRIVATE_ENCRYPTED}`);
}

const program = new Command()
Expand Down
8 changes: 2 additions & 6 deletions src/parser/permit-generation-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,14 @@ export class PermitGenerationModule implements Module {
const eventName = context.eventName as SupportedEvents;
const octokit = getOctokitInstance();
const logger = {
debug(message: unknown, optionalParams: unknown) {
console.log(message, optionalParams);
},
debug() {},
error(message: unknown, optionalParams: unknown) {
console.error(message, optionalParams);
},
fatal(message: unknown, optionalParams: unknown) {
console.error(message, optionalParams);
},
info(message: unknown, optionalParams: unknown) {
console.log(message, optionalParams);
},
info() {},
warn(message: unknown, optionalParams: unknown) {
console.warn(message, optionalParams);
},
Expand Down
123 changes: 123 additions & 0 deletions tests/__mocks__/db-seed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"users": [
{
"login": "molecula451",
"id": 41552663,
"node_id": "MDQ6VXNlcjQxNTUyNjYz",
"avatar_url": "https://avatars.githubusercontent.com/u/41552663?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/molecula451",
"html_url": "https://github.com/molecula451",
"followers_url": "https://api.github.com/users/molecula451/followers",
"following_url": "https://api.github.com/users/molecula451/following{/other_user}",
"gists_url": "https://api.github.com/users/molecula451/gists{/gist_id}",
"starred_url": "https://api.github.com/users/molecula451/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/molecula451/subscriptions",
"organizations_url": "https://api.github.com/users/molecula451/orgs",
"repos_url": "https://api.github.com/users/molecula451/repos",
"events_url": "https://api.github.com/users/molecula451/events{/privacy}",
"received_events_url": "https://api.github.com/users/molecula451/received_events",
"type": "User",
"site_admin": false,
"name": "Paul",
"company": null,
"blog": "https://molecula451.github.io/molecula451dev/",
"location": "Night City",
"email": null,
"hireable": true,
"bio": "Wizard of the Electronic Age",
"twitter_username": null,
"public_repos": 188,
"public_gists": 1,
"followers": 29,
"following": 18,
"created_at": "2018-07-22T20:57:16Z",
"updated_at": "2024-04-05T03:53:30Z"
},
{
"login": "0x4007",
"id": 4975670,
"node_id": "MDQ6VXNlcjQ5NzU2NzA=",
"avatar_url": "https://avatars.githubusercontent.com/u/4975670?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/0x4007",
"html_url": "https://github.com/0x4007",
"followers_url": "https://api.github.com/users/0x4007/followers",
"following_url": "https://api.github.com/users/0x4007/following{/other_user}",
"gists_url": "https://api.github.com/users/0x4007/gists{/gist_id}",
"starred_url": "https://api.github.com/users/0x4007/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/0x4007/subscriptions",
"organizations_url": "https://api.github.com/users/0x4007/orgs",
"repos_url": "https://api.github.com/users/0x4007/repos",
"events_url": "https://api.github.com/users/0x4007/events{/privacy}",
"received_events_url": "https://api.github.com/users/0x4007/received_events",
"type": "User",
"site_admin": false,
"name": "アレクサンダー.eth",
"company": "@ubiquity",
"blog": "",
"location": "Mainnet",
"email": null,
"hireable": null,
"bio": "Philomath. \r\nDigital media and technology pioneer.",
"twitter_username": "0x4007",
"public_repos": 53,
"public_gists": 14,
"followers": 60,
"following": 108,
"created_at": "2013-07-09T18:20:01Z",
"updated_at": "2024-04-20T14:30:52Z"
},
{
"login": "gitcoindev",
"id": 88761781,
"node_id": "MDQ6VXNlcjg4NzYxNzgx",
"avatar_url": "https://avatars.githubusercontent.com/u/88761781?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gitcoindev",
"html_url": "https://github.com/gitcoindev",
"followers_url": "https://api.github.com/users/gitcoindev/followers",
"following_url": "https://api.github.com/users/gitcoindev/following{/other_user}",
"gists_url": "https://api.github.com/users/gitcoindev/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gitcoindev/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gitcoindev/subscriptions",
"organizations_url": "https://api.github.com/users/gitcoindev/orgs",
"repos_url": "https://api.github.com/users/gitcoindev/repos",
"events_url": "https://api.github.com/users/gitcoindev/events{/privacy}",
"received_events_url": "https://api.github.com/users/gitcoindev/received_events",
"type": "User",
"site_admin": false,
"name": "korrrba",
"company": null,
"blog": "",
"location": "Web3 / Europe",
"email": null,
"hireable": null,
"bio": null,
"twitter_username": null,
"public_repos": 44,
"public_gists": 0,
"followers": 3,
"following": 5,
"created_at": "2021-08-11T05:22:33Z",
"updated_at": "2024-02-05T14:11:36Z"
}
],
"wallets": [
{
"id": 1,
"userId": 41552663,
"address": "0x4D0704f400D57Ba93eEa88765C3FcDBD826dCFc4"
},
{
"id": 2,
"userId": 4975670,
"address": "0x4D0704f400D57Ba93eEa88765C3FcDBD826dCFc4"
},
{
"id": 3,
"userId": 88761781,
"address": "0x4D0704f400D57Ba93eEa88765C3FcDBD826dCFc4"
}
]
}
17 changes: 17 additions & 0 deletions tests/__mocks__/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// cSpell:disable
import { factory, primaryKey } from "@mswjs/data";

/**
* Creates an object that can be used as a db to persist data within tests
*/
export const db = factory({
users: {
id: primaryKey(Number),
login: String,
},
wallets: {
id: primaryKey(Number),
userId: Number,
address: String,
},
});
14 changes: 14 additions & 0 deletions tests/__mocks__/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import issueTimelineGet from "./routes/issue-timeline-get.json";
import pullsGet from "./routes/pulls-get.json";
import pullsReviewsGet from "./routes/pulls-reviews-get.json";
import pullsCommentsGet from "./routes/pulls-comments-get.json";
import { db } from "./db";

/**
* Intercepts the routes and returns a custom payload
Expand All @@ -32,4 +33,17 @@ export const handlers = [
http.get("https://api.github.com/repos/ubiquibot/comment-incentives/pulls/25/comments", () => {
return HttpResponse.json(pullsCommentsGet);
}),
http.get("https://api.github.com/users/:login", ({ params: { login } }) => {
const user = db.users.findFirst({
where: {
login: {
equals: login.toString(),
},
},
});
if (!user) {
return HttpResponse.json("User was not found", { status: 404 });
}
return HttpResponse.json(user);
}),
];
Loading
Loading