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

Commit

Permalink
feat: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
whilefoo committed Sep 12, 2023
1 parent 794f793 commit 51bc95f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
17 changes: 9 additions & 8 deletions src/adapters/supabase/helpers/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,18 +347,19 @@ export const getAccessLevel = async (username: string, repository: string, label
return accessValues;
};

export const getAllAccessLevels = async (username: string, repository: string): Promise<null | AccessLevels> => {
export const getAllAccessLevels = async (username: string, repository: string): Promise<AccessLevels> => {
const logger = getLogger();
const { supabase } = getAdapters();

const { data } = await supabase.from("access").select("*").eq("user_name", username).eq("repository", repository).single();

if (!data) {
logger.info(`Access not found on the database`);
// no access
return null;
const { data, error } = await supabase.from("access").select("*").eq("user_name", username).eq("repository", repository);
if (error) {
logger.error(`Checking access control failed, error: ${JSON.stringify(error)}`);
throw new Error(`Checking access control failed, error: ${JSON.stringify(error)}`);
}
if (!data || data.length === 0) {
return { multiplier: false, time: false, priority: false, price: false };
}
return { multiplier: data.multiplier_access, time: data.time_access, priority: data.priority_access, price: data.price_access };
return { multiplier: data[0].multiplier_access, time: data[0].time_access, priority: data[0].priority_access, price: data[0].price_access };
};

/**
Expand Down
3 changes: 0 additions & 3 deletions src/handlers/comment/handlers/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export const query = async (body: string) => {

if (user) {
const data = await getAllAccessLevels(user, repo.full_name);
if (!data) {
return `Error retrieving access for @${user}`;
}
const walletInfo = await getWalletInfo(user, id?.toString());
if (!walletInfo?.address) {
return `Error retrieving multiplier and wallet address for @${user}`;
Expand Down
11 changes: 6 additions & 5 deletions tests/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ describe("commmands test", () => {
await createComment(octokitAdmin, owner, repo, issue.number, `/query @${adminUsername}`);
await waitForNWebhooks(2);

await checkLastComment(octokitAdmin, owner, repo, issue.number, `@${adminUsername}'s wallet address is ${newWallet} and multiplier is ${multiplier}`);
const lastComment = await getLastComment(octokitAdmin, owner, repo, issue.number);
expect(lastComment.body).toContain(`@${adminUsername}'s wallet address is ${newWallet}, multiplier is ${multiplier}`);
},
testTimeout
);
Expand Down Expand Up @@ -410,7 +411,7 @@ describe("commmands test", () => {
await waitForNWebhooks(2);

let lastComment = await getLastComment(octokitAdmin, owner, repo, issue.number);
expect(lastComment.body).toContain("Permit generation skipped since this issue didn't qualify as bounty");
expect(lastComment.body).toContain("Permit generation disabled because this issue didn't qualify as bounty");

await octokitAdmin.rest.issues.update({
owner,
Expand Down Expand Up @@ -465,7 +466,7 @@ describe("commmands test", () => {
await waitForNWebhooks(2);

lastComment = await getLastComment(octokitAdmin, owner, repo, issue.number);
expect(lastComment.body).toContain("Permit generation skipped since assignee is undefined");
expect(lastComment.body).toContain("Permit generation disabled because assignee is undefined");

await octokitAdmin.rest.issues.update({
owner,
Expand Down Expand Up @@ -509,7 +510,7 @@ describe("commmands test", () => {
await waitForNWebhooks(2);

lastComment = await getLastComment(octokitAdmin, owner, repo, issue.number);
expect(lastComment.body).toContain("Permit generation skipped since automatic payment for this issue is disabled.");
expect(lastComment.body).toContain("Permit generation disabled because automatic payment for this issue is disabled.");

await octokitAdmin.rest.issues.update({
owner,
Expand All @@ -535,7 +536,7 @@ describe("commmands test", () => {
await waitForNWebhooks(2);

lastComment = await getLastComment(octokitAdmin, owner, repo, issue.number);
expect(lastComment.body).toContain("Permit generation skipped because the issue was not closed as completed");
expect(lastComment.body).toContain("Permit generation disabled because this is marked as unplanned");

await octokitAdmin.rest.issues.update({
owner,
Expand Down

0 comments on commit 51bc95f

Please sign in to comment.