Skip to content

Commit

Permalink
chore: fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Dec 12, 2024
1 parent 8380526 commit 099ee70
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
14 changes: 9 additions & 5 deletions tests/__mocks__/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ export const handlers = [
http.get(`${process.env.SUPABASE_URL}/rest/v1/users*`, ({ request }) => {
const url = new URL(request.url);
const id = url.searchParams.get("id");
const walletId = url.searchParams.get("wallet_id");

if (!id) {
return HttpResponse.text("", { status: 400 });
if (id) {
const idNumber = Number(id.match(/\d+/)?.[0]);
return HttpResponse.json(db.users.findFirst({ where: { id: { equals: idNumber } } }));
} else if (walletId) {
const idNumber = Number(walletId.match(/\d+/)?.[0]);
return HttpResponse.json(db.users.findFirst({ where: { wallet_id: { equals: idNumber } } }));
}
const idNumber = Number(id.match(/\d+/)?.[0]);
return HttpResponse.json(db.users.findFirst({ where: { id: { equals: idNumber } } }));
return HttpResponse.text("", { status: 400 });
}),
http.patch(`${process.env.SUPABASE_URL}/rest/v1/users*`, async ({ request }) => {
const url = new URL(request.url);
Expand All @@ -38,7 +42,7 @@ export const handlers = [
}),
http.patch(`${process.env.SUPABASE_URL}/rest/v1/wallets*`, async ({ request }) => {
const url = new URL(request.url);
const id = url.searchParams.get("id");
const id = url.searchParams.get("id") ?? url.searchParams.get("wallet_id");

if (!id) {
return HttpResponse.text("", { status: 400 });
Expand Down
17 changes: 10 additions & 7 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, jest } from "@jest/globals";
import { drop } from "@mswjs/data";
import { ethers } from "ethers";
import { plugin } from "../src/plugin";
import { Context } from "../src/types";
Expand All @@ -11,12 +12,6 @@ import { Octokit } from "@octokit/rest";

beforeAll(() => {
server.listen();
for (const dbTable of Object.keys(dbSeed)) {
const tableName = dbTable as keyof typeof dbSeed;
for (const dbRow of dbSeed[tableName]) {
db[tableName].create(dbRow);
}
}
});
afterEach(() => {
server.resetHandlers();
Expand All @@ -40,7 +35,15 @@ jest.mock("@ubiquity-os/plugin-sdk", () => ({
}));

describe("Wallet command tests", () => {
beforeEach(() => {});
beforeEach(() => {
drop(db);
for (const dbTable of Object.keys(dbSeed)) {
const tableName = dbTable as keyof typeof dbSeed;
for (const dbRow of dbSeed[tableName]) {
db[tableName].create(dbRow);
}
}
});

it("Should handle /wallet comment", async () => {
const spy = jest.spyOn(Logs.prototype, "ok");
Expand Down

0 comments on commit 099ee70

Please sign in to comment.