Skip to content

Commit

Permalink
chore: fake wallet db
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Apr 21, 2024
1 parent 77ba319 commit 6d2ff7b
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
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": "0x0000000000000000000000000000000000000001"
},
{
"id": 2,
"userId": 4975670,
"address": "0x0000000000000000000000000000000000000002"
},
{
"id": 3,
"userId": 88761781,
"address": "0x0000000000000000000000000000000000000003"
}
]
}
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,
},
});
38 changes: 38 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,41 @@ 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);
}),
http.get(`${process.env.SUPABASE_URL}/rest/v1/users`, ({ request }) => {
const url = new URL(request.url);
const select = url.searchParams.get("select");
const userId = url.searchParams.get("id");
if (!select || !userId || !select?.includes("wallets")) {
return HttpResponse.json("Wrong params.", { status: 400 });
}
const id = Number(userId.split(".")[1]);
const wallet = db.wallets.findFirst({
where: {
userId: {
equals: id,
},
},
});
if (!wallet) {
return HttpResponse.json("Wallet was not found", { status: 404 });
}
return HttpResponse.json([
{
wallets: wallet,
},
]);
}),
];
24 changes: 24 additions & 0 deletions tests/process.issue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import userCommentResults from "./__mocks__/results/user-comment-results.json";
import dataPurgeResults from "./__mocks__/results/data-purge-result.json";
import formattingEvaluatorResults from "./__mocks__/results/formatting-evaluator-results.json";
import contentEvaluatorResults from "./__mocks__/results/content-evaluator-results.json";
import dbSeed from "./__mocks__/db-seed.json";
import { FormattingEvaluatorModule } from "../src/parser/formatting-evaluator-module";
import { ContentEvaluatorModule } from "../src/parser/content-evaluator-module";
import Decimal from "decimal.js";
import { PermitGenerationModule } from "../src/parser/permit-generation-module";
import { db } from "./__mocks__/db";

const issueUrl = process.env.TEST_ISSUE_URL || "https://github.com/ubiquibot/comment-incentives/issues/22";

Expand All @@ -28,6 +31,12 @@ describe("Modules tests", () => {

beforeAll(async () => {
await activity.init();
for (const item of dbSeed.users) {
db.users.create(item);
}
for (const item of dbSeed.wallets) {
db.wallets.create(item);
}
});

it("Should extract users from comments", async () => {
Expand Down Expand Up @@ -70,4 +79,19 @@ describe("Modules tests", () => {
processor.dump();
expect(logSpy).toHaveBeenCalledWith(JSON.stringify(contentEvaluatorResults, undefined, 2));
});

it("Should generate permits", async () => {
const logSpy = jest.spyOn(console, "log");
const processor = new Processor();
processor["_transformers"] = [
new UserExtractorModule(),
new DataPurgeModule(),
new FormattingEvaluatorModule(),
new ContentEvaluatorModule(),
new PermitGenerationModule(),
];
await processor.run(activity);
processor.dump();
expect(logSpy).toHaveBeenCalledWith(JSON.stringify(contentEvaluatorResults, undefined, 2));
});
});
63 changes: 58 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@
resolved "https://registry.yarnpkg.com/@babel/regjsgen/-/regjsgen-0.8.0.tgz#f0ba69b075e1f05fb2825b7fad991e7adbb18310"
integrity sha512-x/rqGMdzj+fWZvCOYForTghzbtqPDZ5gPwaoNGHdgDfF2QA/XZbCBp4Moo5scrkAMPhB7z26XM/AaHuIJdgauA==

"@babel/runtime@^7.8.4":
"@babel/runtime@^7.21.0", "@babel/runtime@^7.8.4":
version "7.24.4"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.24.4.tgz#de795accd698007a66ba44add6cc86542aff1edd"
integrity sha512-dkxf7+hn8mFBwKjs9bvBlArzLVxVbS8usaPUDd5p2a9JCL9tB8OaOVN1isD4+Xyk4ns89/xeOmbQvgdK7IIVdA==
Expand Down Expand Up @@ -2433,6 +2433,27 @@
resolved "https://registry.yarnpkg.com/@mswjs/cookies/-/cookies-1.1.0.tgz#1528eb43630caf83a1d75d5332b30e75e9bb1b5b"
integrity sha512-0ZcCVQxifZmhwNBoQIrystCb+2sWBY2Zw8lpfJBPCHGCA/HWqehITeCRVIv4VMy8MPlaHo2w2pTHFV2pFfqKPw==

"@mswjs/data@0.16.1":
version "0.16.1"
resolved "https://registry.yarnpkg.com/@mswjs/data/-/data-0.16.1.tgz#ee41b95b8f2e954a07b0eb54154592a2459064d1"
integrity sha512-VhJvL/VmgAuU9/tDOcKcxHfNd+8nxYntZnrkaQEQPvZZnFwQQR9bzI1FTRROGxCHVoyfv9v84AEkl/7CIw4FAg==
dependencies:
"@types/lodash" "^4.14.172"
"@types/md5" "^2.3.0"
"@types/pluralize" "^0.0.29"
"@types/uuid" "^8.3.0"
date-fns "^2.21.1"
debug "^4.3.1"
graphql "^16.8.1"
lodash "^4.17.21"
md5 "^2.3.0"
outvariant "^1.2.1"
pluralize "^8.0.0"
strict-event-emitter "^0.5.0"
uuid "^8.3.1"
optionalDependencies:
msw "^2.0.8"

"@mswjs/interceptors@^0.26.14":
version "0.26.15"
resolved "https://registry.yarnpkg.com/@mswjs/interceptors/-/interceptors-0.26.15.tgz#256ad5c89f325c87d972cc27fc7d0d6d382ce804"
Expand Down Expand Up @@ -3014,6 +3035,11 @@
resolved "https://registry.yarnpkg.com/@types/linkify-it/-/linkify-it-3.0.5.tgz#1e78a3ac2428e6d7e6c05c1665c242023a4601d8"
integrity sha512-yg6E+u0/+Zjva+buc3EIb+29XEg4wltq7cSmd4Uc2EE/1nUVmxyzpX6gUXD0V8jIrG0r7YeOGVIbYRkxeooCtw==

"@types/lodash@^4.14.172":
version "4.17.0"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.17.0.tgz#d774355e41f372d5350a4d0714abb48194a489c3"
integrity sha512-t7dhREVv6dbNj0q17X12j7yDG4bD/DHYX7o5/DbDxobP0HnGPgpRz2Ej77aL7TZT3DSw13fqUTj8J4mMnqa7WA==

"@types/markdown-it@13.0.7":
version "13.0.7"
resolved "https://registry.yarnpkg.com/@types/markdown-it/-/markdown-it-13.0.7.tgz#4a495115f470075bd4434a0438ac477a49c2e152"
Expand All @@ -3022,6 +3048,11 @@
"@types/linkify-it" "*"
"@types/mdurl" "*"

"@types/md5@^2.3.0":
version "2.3.5"
resolved "https://registry.yarnpkg.com/@types/md5/-/md5-2.3.5.tgz#481cef0a896e3a5dcbfc5a8a8b02c05958af48a5"
integrity sha512-/i42wjYNgE6wf0j2bcTX6kuowmdL/6PE4IVitMpm2eYKBUuYCprdcWVK+xEF0gcV6ufMCRhtxmReGfc6hIK7Jw==

"@types/mdurl@*":
version "1.0.5"
resolved "https://registry.yarnpkg.com/@types/mdurl/-/mdurl-1.0.5.tgz#3e0d2db570e9fb6ccb2dc8fde0be1d79ac810d39"
Expand Down Expand Up @@ -3088,6 +3119,11 @@
resolved "https://registry.yarnpkg.com/@types/picomatch/-/picomatch-2.3.3.tgz#be60498568c19e989e43fb39aa84be1ed3655e92"
integrity sha512-Yll76ZHikRFCyz/pffKGjrCwe/le2CDwOP5F210KQo27kpRE46U2rDnzikNlVn6/ezH3Mhn46bJMTfeVTtcYMg==

"@types/pluralize@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/pluralize/-/pluralize-0.0.29.tgz#6ffa33ed1fc8813c469b859681d09707eb40d03c"
integrity sha512-BYOID+l2Aco2nBik+iYS4SZX0Lf20KPILP5RGmM1IgzdwNdTs0eebiFriOPcej1sX9mLnSoiNte5zcFxssgpGA==

"@types/semver@^7.5.0":
version "7.5.8"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.8.tgz#8268a8c57a3e4abd25c165ecd36237db7948a55e"
Expand All @@ -3108,6 +3144,11 @@
resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.5.tgz#cb6e2a691b70cb177c6e3ae9c1d2e8b2ea8cd304"
integrity sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==

"@types/uuid@^8.3.0":
version "8.3.4"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.4.tgz#bd86a43617df0594787d38b735f55c805becf1bc"
integrity sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==

"@types/wrap-ansi@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/wrap-ansi/-/wrap-ansi-3.0.0.tgz#18b97a972f94f60a679fd5c796d96421b9abb9fd"
Expand Down Expand Up @@ -4205,6 +4246,13 @@ data-view-byte-offset@^1.0.0:
es-errors "^1.3.0"
is-data-view "^1.0.1"

date-fns@^2.21.1:
version "2.30.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.30.0.tgz#f367e644839ff57894ec6ac480de40cae4b0f4d0"
integrity sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==
dependencies:
"@babel/runtime" "^7.21.0"

debug@4, debug@4.3.4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, debug@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
Expand Down Expand Up @@ -6397,7 +6445,7 @@ lodash.upperfirst@^4.3.1:
resolved "https://registry.yarnpkg.com/lodash.upperfirst/-/lodash.upperfirst-4.3.1.tgz#1365edf431480481ef0d1c68957a5ed99d49f7ce"
integrity sha512-sReKOYJIJf74dhJONhU4e0/shzi1trVbSWDOhKYE5XV2O+H7Sb2Dihwuc7xWxVl+DgFPyTqIN3zMfT9cq5iWDg==

lodash@^4.17.15:
lodash@^4.17.15, lodash@^4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
Expand Down Expand Up @@ -6664,7 +6712,7 @@ ms@^2.0.0:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==

msw@2.2.14:
msw@2.2.14, msw@^2.0.8:
version "2.2.14"
resolved "https://registry.yarnpkg.com/msw/-/msw-2.2.14.tgz#ed16b89f99ffc105a84b0295a6fcae2ee99f5c62"
integrity sha512-64i8rNCa1xzDK8ZYsTrVMli05D687jty8+Th+PU5VTbJ2/4P7fkQFVyDQ6ZFT5FrNR8z2BHhbY47fKNvfHrumA==
Expand Down Expand Up @@ -7135,6 +7183,11 @@ pkg-dir@^4.2.0:
dependencies:
find-up "^4.0.0"

pluralize@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-8.0.0.tgz#1a6fa16a38d12a1901e0320fa017051c539ce3b1"
integrity sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==

possible-typed-array-names@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz#89bb63c6fada2c3e90adc4a647beeeb39cc7bf8f"
Expand Down Expand Up @@ -7706,7 +7759,7 @@ statuses@^2.0.1:
resolved "https://registry.yarnpkg.com/statuses/-/statuses-2.0.1.tgz#55cb000ccf1d48728bd23c685a063998cf1a1b63"
integrity sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==

strict-event-emitter@^0.5.1:
strict-event-emitter@^0.5.0, strict-event-emitter@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/strict-event-emitter/-/strict-event-emitter-0.5.1.tgz#1602ece81c51574ca39c6815e09f1a3e8550bd93"
integrity sha512-vMgjE/GGEPEFnhFub6pa4FmJBRBVOLpIII2hvCZ8Kzb7K0hlHo7mQv6xYrBvCL2LtAIBwFUK8wvuJgTVSQ5MFQ==
Expand Down Expand Up @@ -8264,7 +8317,7 @@ util-deprecate@^1.0.1:
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==

uuid@^8.3.2:
uuid@^8.3.1, uuid@^8.3.2:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
Expand Down

0 comments on commit 6d2ff7b

Please sign in to comment.