Skip to content

Commit

Permalink
feat: added test for wallet link
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Jun 25, 2024
1 parent 8ecca13 commit e059e13
Show file tree
Hide file tree
Showing 11 changed files with 376 additions and 38 deletions.
3 changes: 2 additions & 1 deletion jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"collectCoverage": true,
"coverageReporters": ["json", "lcov", "text", "clover", "json-summary"],
"reporters": ["default", "jest-junit", "jest-md-dashboard"],
"coverageDirectory": "coverage"
"coverageDirectory": "coverage",
"setupFiles": ["dotenv/config"]
}
4 changes: 2 additions & 2 deletions src/adapters/supabase/helpers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class Wallet extends Super {
}
const { data, error } = await this.supabase.from("wallets").select("*").eq("id", userData.wallet_id).maybeSingle();

return { data: data as WalletRow, error };
return { data, error };
}

private async _updateWalletId(walletId: number, userId: number) {
Expand Down Expand Up @@ -168,7 +168,7 @@ export class Wallet extends Super {
if (walletData.location_id === null) {
throw new Error("Location ID is null");
}
logger.info("Enriching wallet location metadata", locationMetaData);
logger.debug("Enriching wallet location metadata", locationMetaData);
return this.supabase.from("locations").update(locationMetaData).eq("id", walletData.location_id);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/command-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export class CommandParser {
.version(packageJson.version);
program.configureOutput({
async writeOut(str: string) {
await context.logger.info(str);
context.logger.debug(str);
},
async writeErr(str: string) {
await context.logger.error(str);
context.logger.warn(str);
},
getErrHelpWidth(): number {
return 0;
Expand Down
32 changes: 20 additions & 12 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,32 @@ export async function plugin(inputs: PluginInputs, env: Env) {
},
async info(message: unknown, ...optionalParams: unknown[]) {
console.log(message, ...optionalParams);
await octokit.issues.createComment({
owner: context.payload.repository.owner.login,
issue_number: context.payload.issue.number,
repo: context.payload.repository.name,
body: `\`\`\`diff\n${message}`,
});
try {
await octokit.issues.createComment({
owner: context.payload.repository.owner.login,
issue_number: context.payload.issue.number,
repo: context.payload.repository.name,
body: `\`\`\`diff\n${message}`,
});
} catch (e) {
console.error("Failed to post info comment", e);
}
},
warn(message: unknown, ...optionalParams: unknown[]) {
console.warn(message, ...optionalParams);
},
async error(message: unknown, ...optionalParams: unknown[]) {
console.error(message, ...optionalParams);
await octokit.issues.createComment({
owner: context.payload.repository.owner.login,
issue_number: context.payload.issue.number,
repo: context.payload.repository.name,
body: `\`\`\`diff\n- ${message} ${optionalParams}`,
});
try {
await octokit.issues.createComment({
owner: context.payload.repository.owner.login,
issue_number: context.payload.issue.number,
repo: context.payload.repository.name,
body: `\`\`\`diff\n- ${message} ${optionalParams}`,
});
} catch (e) {
console.error("Failed to post error comment", e);
}
},
fatal(message: unknown, ...optionalParams: unknown[]) {
console.error(message, ...optionalParams);
Expand Down
10 changes: 10 additions & 0 deletions src/types/environment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
declare global {
namespace NodeJS {
interface ProcessEnv {
SUPABASE_KEY: string;
SUPABASE_URL: string;
}
}
}

export {};
15 changes: 15 additions & 0 deletions tests/__mocks__/db-seed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"users": [
{
"id": 1,
"login": "ubiquibot",
"wallet_id": 1
}
],
"wallets": [
{
"id": 1,
"address": "0x0000000000000000000000000000000000000001"
}
]
}
7 changes: 6 additions & 1 deletion tests/__mocks__/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ 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({
wallets: {
id: primaryKey(Number),
address: String,
},
users: {
id: primaryKey(Number),
name: String,
login: String,
wallet_id: Number,
},
});
33 changes: 31 additions & 2 deletions tests/__mocks__/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,36 @@ import { db } from "./db";
* Intercepts the routes and returns a custom payload
*/
export const handlers = [
http.get("https://api.ubiquity.com/users", () => {
return HttpResponse.json(db.users.getAll());
http.get(`${process.env.SUPABASE_URL}/rest/v1/users*`, ({ request }) => {
const url = new URL(request.url);
const id = url.searchParams.get("id");

if (!id) {
return HttpResponse.text("", { status: 400 });
}
const idNumber = Number(id.match(/\d+/)?.[0]);
return HttpResponse.json(db.users.findFirst({ where: { id: { equals: idNumber } } }));
}),
http.get(`${process.env.SUPABASE_URL}/rest/v1/wallets*`, ({ request }) => {
const url = new URL(request.url);
const id = url.searchParams.get("id");

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

if (!id) {
return HttpResponse.text("", { status: 400 });
}
const idNumber = Number(id.match(/\d+/)?.[0]);
const data = (await request.json()) as object;
return HttpResponse.json(db.wallets.update({ data, where: { id: { equals: idNumber } } }));
}),
http.post("https://api.github.com/repos/:owner/:repo/issues/:id/comments", () => HttpResponse.json()),
];
Loading

0 comments on commit e059e13

Please sign in to comment.