Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-ae committed Jul 29, 2024
1 parent 05f43ed commit 71e1c1a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
14 changes: 14 additions & 0 deletions tests/__mocks__/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ export const handlers = [
}
return HttpResponse.json(item);
}),
//get member
http.get("https://api.github.com/orgs/:org/memberships/:username", ({ params: { username } }) => {
switch (username) {
case "ubiquity":
case "gentlementlegen":
return HttpResponse.json({ role: "admin" });
case "billing":
return HttpResponse.json({ role: "billing_manager" });
case "collaborator":
return HttpResponse.json({role: "collaborator"})
default:
return HttpResponse.json({ role: "member" });
}
}),
// get issue
http.get("https://api.github.com/repos/:owner/:repo/issues", ({ params: { owner, repo } }: { params: { owner: string; repo: string } }) => {
return HttpResponse.json(db.issue.findMany({ where: { owner: { equals: owner }, repo: { equals: repo } } }));
Expand Down
20 changes: 4 additions & 16 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ type Sender = Context["payload"]["sender"];

const octokit = jest.requireActual("@octokit/rest");

const url = process.env.SUPABASE_URL;
const key = process.env.SUPABASE_KEY;
const url = "https://sbxscxthunnhozvgtshx.supabase.co";
const key =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InNieHNjeHRodW5uaG96dmd0c2h4Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTE0Nzg2MDcsImV4cCI6MjAyNzA1NDYwN30.-DstUzIspsRlLQPHR1da6nY5GBBs5I4Wd0jlK5zFzyU";

if (!url || !key) {
throw new Error("Supabase URL and Key are required");
Expand Down Expand Up @@ -196,12 +197,6 @@ describe("User start/stop", () => {
});

test("should return the role with the smallest task limit if user role is not defined in config", async () => {
jest.mock("../src/handlers/shared/get-user-role.ts", () => ({
getUserRole: jest.fn().mockReturnValue({
role: "unknown-role",
}),
}));

jest.mock("../src/utils/issue", () => ({
getAvailableOpenedPullRequests: jest.fn().mockResolvedValue([
{
Expand Down Expand Up @@ -248,13 +243,6 @@ describe("User start/stop", () => {
});

test("should set maxLimits to 5 if the user is a member", async () => {
jest.mock("../src/handlers/shared/get-user-role.ts", () => ({
getUserRole: jest.fn().mockReturnValue({
role: "Member",
limit: 5,
}),
}));

jest.mock("../src/utils/issue", () => ({
getAvailableOpenedPullRequests: jest.fn().mockResolvedValue([
{
Expand Down Expand Up @@ -466,7 +454,7 @@ function createContext(issue: Record<string, unknown>, sender: Record<string, un
maxConcurrentTasks: [
{
role: "Admin",
limit: null,
limit: 10,
},
{
role: "Member",
Expand Down

0 comments on commit 71e1c1a

Please sign in to comment.