Skip to content

Commit f9498b0

Browse files
committed
Resolve comment issues
-fix code execution test bug -update tests and swagger for qn history -return bearer token only if token exists, else auth context useeffect will run even when token does not exist since accesstoken still returns a non falsy value
1 parent fd03c79 commit f9498b0

File tree

7 files changed

+29
-10
lines changed

7 files changed

+29
-10
lines changed

backend/code-execution-service/tests/codeExecutionRoutes.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe("Code execution routes", () => {
9090
expect(response.body.data).toBeInstanceOf(Array);
9191
expect(response.body.data[0]).toHaveProperty("isMatch", true);
9292
expect(response.body.data[0]["isMatch"]).toBe(true);
93-
expect(response.body.data[1]["isMatch"]).toBe(false);
93+
expect(response.body.data[1]["isMatch"]).toBe(true);
9494
});
9595
});
9696
});

backend/qn-history-service/swagger.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ info:
55
version: 1.0.0
66

77
components:
8+
securitySchemes:
9+
bearerAuth:
10+
type: http
11+
scheme: bearer
12+
bearerFormat: JWT
13+
814
schemas:
915
QnHistory:
1016
properties:
@@ -28,7 +34,7 @@ components:
2834
description: Date that question was attempted
2935
timeTaken:
3036
type: number
31-
description: Time taken for question attempt in minutes
37+
description: Time taken for question attempt in seconds
3238
code:
3339
type: string
3440
description: Code submitted
@@ -63,7 +69,7 @@ definitions:
6369
description: Date that question was attempted
6470
timeTaken:
6571
type: number
66-
description: Time taken for question attempt in minutes
72+
description: Time taken for question attempt in seconds
6773
code:
6874
type: string
6975
description: Code submitted
@@ -119,6 +125,8 @@ paths:
119125
- qnhistories
120126
summary: Creates a question history
121127
description: Creates a question history
128+
security:
129+
- bearerAuth: []
122130
requestBody:
123131
required: true
124132
content:
@@ -218,6 +226,8 @@ paths:
218226
- qnhistories
219227
summary: Updates a question history
220228
description: Updates a question history
229+
security:
230+
- bearerAuth: []
221231
parameters:
222232
- in: path
223233
name: id

backend/qn-history-service/tests/qnHistoryRoutes.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { NextFunction, Request, Response } from "express";
12
import { faker } from "@faker-js/faker";
23
import supertest from "supertest";
34
import app from "../src/app";
@@ -16,6 +17,12 @@ const BASE_URL = "/api/qnhistories";
1617

1718
faker.seed(0);
1819

20+
jest.mock("../src/middlewares/basicAccessControl", () => ({
21+
verifyToken: jest.fn((res: Request, req: Response, next: NextFunction) =>
22+
next()
23+
),
24+
}));
25+
1926
describe("Qn History Routes", () => {
2027
describe("POST / ", () => {
2128
it("Creates new qn history", async () => {

frontend/src/components/CodeEditor/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ const CodeEditor: React.FC<CodeEditorProps> = (props) => {
7575

7676
const loadTemplate = async () => {
7777
if (matchUser && partner && matchCriteria && questionId && questionTitle) {
78-
await initDocument(uid, roomId, template, matchUser.id, partner.id, matchCriteria.language, questionId, questionTitle);
7978
checkDocReady();
79+
await initDocument(uid, roomId, template, matchUser.id, partner.id, matchCriteria.language, questionId, questionTitle);
8080
setIsDocumentLoaded(true);
8181
}
8282
};

frontend/src/reducers/qnHistoryReducer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Dispatch } from "react";
22
import { qnHistoryClient } from "../utils/api";
33
import { isString, isStringArray } from "../utils/typeChecker";
4+
import { getToken } from "../utils/token";
45

56
type QnHistoryDetail = {
67
id: string;
@@ -151,7 +152,6 @@ export const updateQnHistoryById = async (
151152
>,
152153
dispatch: Dispatch<QnHistoryActions>
153154
): Promise<boolean> => {
154-
const accessToken = localStorage.getItem("token");
155155
return qnHistoryClient
156156
.put(
157157
`/${qnHistoryId}`,
@@ -163,7 +163,7 @@ export const updateQnHistoryById = async (
163163
},
164164
{
165165
headers: {
166-
Authorization: `Bearer ${accessToken}`,
166+
Authorization: getToken(),
167167
},
168168
}
169169
)

frontend/src/utils/sessionTime.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ export const extractMinutesFromTime = (time: number) =>
55

66
export const extractSecondsFromTime = (time: number) => time % 60; // after extracting hours and minutes
77

8-
export const extractMinutesOnly = (time: number) => time / 60;
9-
108
export const convertDateString = (date: string): string => {
119
const convertedDate = new Date(date);
1210
const dateString = convertedDate.toLocaleDateString("en-GB", {

frontend/src/utils/token.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ export const setToken = (token: string) => {
44

55
export const getToken = () => {
66
const token = localStorage.getItem("accessToken");
7-
const bearerToken = `Bearer ${token}`;
8-
return bearerToken;
7+
if (token) {
8+
const bearerToken = `Bearer ${token}`;
9+
return bearerToken;
10+
} else {
11+
return null;
12+
}
913
};
1014

1115
export const removeToken = () => {

0 commit comments

Comments
 (0)