Skip to content

Commit 42588fb

Browse files
committed
Fixed typecheck in Adminpage & created new vitest group for linkadmin and corrected unit test
1 parent 53f3397 commit 42588fb

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/ui/pages/linkry/LinkShortenerAdmin.page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export type LinkryAdminGetResponse = z.infer<typeof getLinkryAdminSchema>;
6666

6767
export const LinkShortenerAdmin: React.FC = () => {
6868
const [isLoading, setIsLoading] = useState<boolean>(false);
69-
const [adminLinks, setAdminLinks] = useState<LinkryAdminGetResponse[]>([]);
69+
const [adminLinks, setAdminLinks] = useState<LinkryGetResponse[]>([]);
7070
const api = useApi('core');
7171
const [opened, { open, close }] = useDisclosure(false);
7272
const [showPrevious, { toggle: togglePrevious }] = useDisclosure(false); // Changed default to false

tests/unit/linkry.test.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,24 @@ ddbMock.on(QueryCommand).resolves({
6262
Items: [],
6363
});
6464

65-
const testJwt = createJwt(undefined, "83c275f8-e533-4987-b537-a94b86c9d28e");
65+
const testAdminJwt = createJwt(undefined, "LINKS_ADMIN");
66+
const testAccessDeniedJwt = createJwt(undefined, "1");
6667

67-
const allLinkryResponse = await app.inject({
68+
const adminLinkryResponse = await app.inject({
6869
method: "GET",
6970
url: "/api/v1/linkry/redir",
7071
headers: {
71-
Authorization: `Bearer ${testJwt}`,
72+
Authorization: `Bearer ${testAdminJwt}`,
7273
},
7374
});
7475

75-
expect(allLinkryResponse.statusCode).toBe(200);
76+
const accessDeniedLinkryResponse = await app.inject({
77+
method: "GET",
78+
url: "/api/v1/linkry/redir",
79+
headers: {
80+
Authorization: `Bearer ${testAccessDeniedJwt}`,
81+
},
82+
});
83+
84+
expect(adminLinkryResponse.statusCode).toBe(200);
85+
expect(accessDeniedLinkryResponse.statusCode).toBe(401);

tests/unit/vitest.setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ vi.mock(
4242
const mockGroupRoles = {
4343
"0": allAppRoles,
4444
"1": [],
45+
LINKS_ADMIN: [AppRoles.LINKS_ADMIN],
4546
"scanner-only": [AppRoles.TICKETS_SCANNER],
4647
};
4748

0 commit comments

Comments
 (0)