Skip to content

Commit dc7bce2

Browse files
committed
Fix: Run linter on previously touched files
1 parent 9ebc4e8 commit dc7bce2

File tree

2 files changed

+59
-53
lines changed

2 files changed

+59
-53
lines changed

src/infrastructure/discord/authz.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ const roles: {
1919

2020
export const can = (discordUserID: string, perms: string[]): boolean => {
2121
const userEntry = Object.values(githubDiscordMap).find(
22-
(entry: any) => entry.discordId === discordUserID
22+
(entry: any) => entry.discordId === discordUserID,
2323
);
2424

2525
if (!userEntry || !userEntry.roles) {
26-
return false;
27-
}
26+
return false;
27+
}
2828

2929
const userPermissions = new Set(
30-
userEntry.roles.flatMap((role: string) => roles[role]?.permissions || [])
30+
userEntry.roles.flatMap((role: string) => roles[role]?.permissions || []),
3131
);
3232

33-
return perms.every(perm => userPermissions.has(perm));
34-
};
33+
return perms.every((perm) => userPermissions.has(perm));
34+
};
Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,59 @@
11
import { can } from "@infrastructure/discord/authz";
22

33
describe("auth tests", () => {
4-
it("will accept one role with all permissions", () =>{
5-
const discordID = "693093284998021141";
6-
jest.mock(
7-
"../../../../data/githubDiscordMap.json",
8-
() => ({
9-
User1: {
10-
discordID: discordID,
11-
roles: ["admin"],
12-
},
13-
}),
14-
{ virtual: true },
15-
);
16-
expect(can(discordID, ["githubIssue:write", "githubIssue:read"])).toBe(true);
17-
});
4+
it("will accept one role with all permissions", () => {
5+
const discordID = "693093284998021141";
6+
jest.mock(
7+
"../../../../data/githubDiscordMap.json",
8+
() => ({
9+
User1: {
10+
discordID: discordID,
11+
roles: ["admin"],
12+
},
13+
}),
14+
{ virtual: true },
15+
);
16+
expect(can(discordID, ["githubIssue:write", "githubIssue:read"])).toBe(
17+
true,
18+
);
19+
});
1820

19-
it("will throw an error if user has no roles", () =>{
20-
const discordID = "12345";
21-
jest.mock(
22-
"../../../../data/githubDiscordMap.json",
23-
() => ({
24-
User1: {
25-
discordID: discordID,
26-
roles: [],
27-
},
28-
}),
29-
{ virtual: true },
30-
);
31-
expect(can(discordID, ["githubIssue:read", "githubIssue:write"])).toBe(false);
32-
});
21+
it("will throw an error if user has no roles", () => {
22+
const discordID = "12345";
23+
jest.mock(
24+
"../../../../data/githubDiscordMap.json",
25+
() => ({
26+
User1: {
27+
discordID: discordID,
28+
roles: [],
29+
},
30+
}),
31+
{ virtual: true },
32+
);
33+
expect(can(discordID, ["githubIssue:read", "githubIssue:write"])).toBe(
34+
false,
35+
);
36+
});
3337

34-
it("will throw an error if user does not have all of the required permissions", () =>{
35-
const discordID = "142782738615762944";
36-
jest.mock(
37-
"../../../../data/githubDiscordMap.json",
38-
() => ({
39-
User1: {
40-
discordID: discordID,
41-
roles: ["readonly"],
42-
},
43-
}),
44-
{ virtual: true },
45-
);
46-
expect(can(discordID, ["githubIssue:read", "githubIssue:write"])).toBe(false);
47-
});
38+
it("will throw an error if user does not have all of the required permissions", () => {
39+
const discordID = "142782738615762944";
40+
jest.mock(
41+
"../../../../data/githubDiscordMap.json",
42+
() => ({
43+
User1: {
44+
discordID: discordID,
45+
roles: ["readonly"],
46+
},
47+
}),
48+
{ virtual: true },
49+
);
50+
expect(can(discordID, ["githubIssue:read", "githubIssue:write"])).toBe(
51+
false,
52+
);
53+
});
4854

49-
it('will throw an error if the user is not in the map', () => {
50-
const id = "12345";
51-
expect(can(id, ["githubIssue:write", "githubIssue:read"])).toBe(false);
52-
});
53-
});
55+
it("will throw an error if the user is not in the map", () => {
56+
const id = "12345";
57+
expect(can(id, ["githubIssue:write", "githubIssue:read"])).toBe(false);
58+
});
59+
});

0 commit comments

Comments
 (0)