Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 37 additions & 61 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"license": "MIT",
"devDependencies": {
"mocha": "^12.0.3",
"nock": "^14.0.17",
"nock": "^15.0.1",
"nyc": "^18.0.0",
"smee-client": "^5.0.0",
"uvu": "^0.5.6"
Expand Down
38 changes: 26 additions & 12 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { suite } = require("uvu");
const assert = require("uvu/assert");

const nock = require("nock");
const nock = require("nock").default;
nock.disableNetConnect();

const {
Expand Down Expand Up @@ -339,6 +339,7 @@ test.before.each(() => {
});

test.after.each(() => {
nock.cleanAll();
delete process.env.APPROVE_PR;
delete process.env.CREATE_ISSUE;
delete process.env.MERGE_PR;
Expand Down Expand Up @@ -577,7 +578,8 @@ test("receives pull_request.labeled event, check team membership, merge the PR",
.put("/repos/robandpdx/superbigmono/pulls/1/merge").reply(200);

// mock the request to check if the user is a member of the emergency team
mock.get(`/orgs/robandpdx/teams/emergency-team/memberships/robandpdx?org=robandpdx&team_slug=emergency-team&username=robandpdx`)
mock.get("/orgs/robandpdx/teams/emergency-team/memberships/robandpdx")
.query({ org: "robandpdx", team_slug: "emergency-team", username: "robandpdx" })
.reply(200, payloadMembershipResponse);

await probot.receive(payloadPrLabeled);
Expand Down Expand Up @@ -645,7 +647,8 @@ test("receives pull_request.labeled event from a non-app bot, do not merge the P
// mock self-introspection — the detected bot login differs from the sender
.get("/app").reply(200, { slug: "emergency-pr" })
// mock the membership check returning 404 — the bot is not on the team
.get(`/orgs/robandpdx/teams/emergency-team/memberships/dependabot[bot]?org=robandpdx&team_slug=emergency-team&username=dependabot%5Bbot%5D`)
.get("/orgs/robandpdx/teams/emergency-team/memberships/dependabot[bot]")
.query({ org: "robandpdx", team_slug: "emergency-team", username: "dependabot[bot]" })
.reply(404);

// mock the unauthorized comment
Expand Down Expand Up @@ -680,7 +683,8 @@ test("receives pull_request.labeled event from a bot when self-introspection fai
// self-introspection fails
.get("/app").reply(500)
// membership check returns 404 — the bot is not on the team
.get(`/orgs/robandpdx/teams/emergency-team/memberships/dependabot[bot]?org=robandpdx&team_slug=emergency-team&username=dependabot%5Bbot%5D`)
.get("/orgs/robandpdx/teams/emergency-team/memberships/dependabot[bot]")
.query({ org: "robandpdx", team_slug: "emergency-team", username: "dependabot[bot]" })
.reply(404);

mock.post("/repos/robandpdx/superbigmono/issues/1/comments",
Expand Down Expand Up @@ -710,7 +714,8 @@ test("receives pull_request.labeled event, check non team membership, do not mer

// mock the request to check if the user is a member of the emergency team
const mock = nock("https://api.github.com")
.get(`/orgs/robandpdx/teams/emergency-team/memberships/robandpdx?org=robandpdx&team_slug=emergency-team&username=robandpdx`)
.get("/orgs/robandpdx/teams/emergency-team/memberships/robandpdx")
.query({ org: "robandpdx", team_slug: "emergency-team", username: "robandpdx" })
.reply(200, payloadNonMembershipResponse);

// mock the request to create the issue comment
Expand Down Expand Up @@ -742,7 +747,8 @@ test("receives pull_request.labeled event, non team membership, do not merge the

// mock the request to check if the user is a member of the emergency team
const mock = nock("https://api.github.com")
.get(`/orgs/robandpdx/teams/emergency-team/memberships/robandpdx?org=robandpdx&team_slug=emergency-team&username=robandpdx`)
.get("/orgs/robandpdx/teams/emergency-team/memberships/robandpdx")
.query({ org: "robandpdx", team_slug: "emergency-team", username: "robandpdx" })
.reply(404);

// mock the request to create the issue comment
Expand Down Expand Up @@ -1079,14 +1085,16 @@ test("receives pull_request.opened event, applies emergency label checking team
const mock = nock("https://api.github.com")
.post("/repos/robandpdx/superbigmono/issues/1/labels",
(requestBody) => {
if (!requestBody?.labels) return false;
assert.equal(requestBody.labels[0], "emergency");
return true;
}
)
.reply(200);

// mock the request to check if the user is a member of the emergency team
mock.get(`/orgs/robandpdx/teams/emergency-team/memberships/robandpdx?org=robandpdx&team_slug=emergency-team&username=robandpdx`)
mock.get("/orgs/robandpdx/teams/emergency-team/memberships/robandpdx")
.query({ org: "robandpdx", team_slug: "emergency-team", username: "robandpdx" })
.reply(200, payloadMembershipResponse);

await probot.receive(payloadPrOpened);
Expand All @@ -1099,7 +1107,8 @@ test("receives pull_request.opened event, does not apply emergency label due to

// mock the request to apply the emergency label
const mock = nock("https://api.github.com")
.get(`/orgs/robandpdx/teams/emergency-team/memberships/robandpdx?org=robandpdx&team_slug=emergency-team&username=robandpdx`)
.get("/orgs/robandpdx/teams/emergency-team/memberships/robandpdx")
.query({ org: "robandpdx", team_slug: "emergency-team", username: "robandpdx" })
.reply(200, payloadNonMembershipResponse);

// mock the request to create the issue comment
Expand Down Expand Up @@ -1166,14 +1175,16 @@ test("receives issue_comment.created event, applies emergency label", async func
const mock = nock("https://api.github.com")
.post("/repos/robandpdx/superbigmono/issues/1/labels",
(requestBody) => {
if (!requestBody?.labels) return false;
assert.equal(requestBody.labels[0], "emergency");
return true;
}
)
.reply(200);

// mock the request to check if the user is a member of the emergency team
mock.get(`/orgs/robandpdx/teams/emergency-team/memberships/robandpdx?org=robandpdx&team_slug=emergency-team&username=robandpdx`)
mock.get("/orgs/robandpdx/teams/emergency-team/memberships/robandpdx")
.query({ org: "robandpdx", team_slug: "emergency-team", username: "robandpdx" })
.reply(200, payloadMembershipResponse);

await probot.receive(payloadPrComment);
Expand All @@ -1186,7 +1197,8 @@ test("receives issue_comment.created event, does not apply emergency label due t

// mock the request to apply the emergency label
const mock = nock("https://api.github.com")
.get(`/orgs/robandpdx/teams/emergency-team/memberships/robandpdx?org=robandpdx&team_slug=emergency-team&username=robandpdx`)
.get("/orgs/robandpdx/teams/emergency-team/memberships/robandpdx")
.query({ org: "robandpdx", team_slug: "emergency-team", username: "robandpdx" })
.reply(200, payloadNonMembershipResponse);

// mock the request to create the issue comment
Expand All @@ -1207,7 +1219,8 @@ test("receives issue_comment.created event, does not apply emergency label due t

// mock the request to apply the emergency label
const mock = nock("https://api.github.com")
.get(`/orgs/robandpdx/teams/emergency-team/memberships/robandpdx?org=robandpdx&team_slug=emergency-team&username=robandpdx`)
.get("/orgs/robandpdx/teams/emergency-team/memberships/robandpdx")
.query({ org: "robandpdx", team_slug: "emergency-team", username: "robandpdx" })
.reply(500);

try {
Expand All @@ -1224,7 +1237,8 @@ test("receives issue_comment.created event, does not applies emergency label, fa

// mock the request to apply the emergency label
const mock = nock("https://api.github.com")
.get(`/orgs/robandpdx/teams/emergency-team/memberships/robandpdx?org=robandpdx&team_slug=emergency-team&username=robandpdx`)
.get("/orgs/robandpdx/teams/emergency-team/memberships/robandpdx")
.query({ org: "robandpdx", team_slug: "emergency-team", username: "robandpdx" })
.reply(200, payloadNonMembershipResponse);

// mock the request to create the issue comment
Expand Down
Loading