Skip to content

Commit 597eb46

Browse files
committed
Merge branch 'development' of https://github.com/ruiqi7/peer-prep into feature/user-authentication
2 parents 3e7ba87 + 26edbd1 commit 597eb46

File tree

28 files changed

+10085
-2746
lines changed

28 files changed

+10085
-2746
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ dist
1212
dist-ssr
1313
*.local
1414

15+
# Coverage
16+
coverage
17+
1518
# Editor directories and files
1619
.vscode/*
1720
!.vscode/settings.json

backend/question-service/src/controllers/questionController.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
QN_RETRIEVED_MESSAGE,
1313
PAGE_LIMIT_REQUIRED_MESSAGE,
1414
PAGE_LIMIT_INCORRECT_FORMAT_MESSAGE,
15-
CATEGORIES_NOT_FOUND_MESSAGE,
1615
CATEGORIES_RETRIEVED_MESSAGE,
1716
} from "../utils/constants.ts";
1817

@@ -196,19 +195,14 @@ export const readQuestionsList = async (
196195
};
197196
}
198197

199-
const filteredTotalQuestions = await Question.countDocuments(query);
200-
if (filteredTotalQuestions == 0) {
201-
res.status(404).json({ message: QN_NOT_FOUND_MESSAGE });
202-
return;
203-
}
204-
198+
const filteredQuestionCount = await Question.countDocuments(query);
205199
const filteredQuestions = await Question.find(query)
206200
.skip((pageInt - 1) * qnLimitInt)
207201
.limit(qnLimitInt);
208202

209203
res.status(200).json({
210204
message: QN_RETRIEVED_MESSAGE,
211-
totalQns: filteredTotalQuestions,
205+
questionCount: filteredQuestionCount,
212206
questions: filteredQuestions.map(formatQuestionResponse),
213207
});
214208
} catch (error) {
@@ -239,14 +233,11 @@ export const readQuestionIndiv = async (
239233
};
240234

241235
export const readCategories = async (
242-
req: Request,
236+
_req: Request,
243237
res: Response,
244238
): Promise<void> => {
245239
try {
246240
const uniqueCats = await Question.distinct("category");
247-
if (!uniqueCats || uniqueCats.length == 0) {
248-
res.status(404).json({ message: CATEGORIES_NOT_FOUND_MESSAGE });
249-
}
250241

251242
res.status(200).json({
252243
message: CATEGORIES_RETRIEVED_MESSAGE,

backend/question-service/src/utils/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,5 @@ export const PAGE_LIMIT_REQUIRED_MESSAGE =
2222
export const PAGE_LIMIT_INCORRECT_FORMAT_MESSAGE =
2323
"Page number and question limit per page should be positive integers.";
2424

25-
export const CATEGORIES_NOT_FOUND_MESSAGE = "No categories found.";
26-
2725
export const CATEGORIES_RETRIEVED_MESSAGE =
2826
"Categories retrieved successfully.";

backend/question-service/swagger.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ paths:
176176
message:
177177
type: string
178178
description: Message
179-
totalQns:
179+
questionCount:
180180
type: integer
181181
description: Total number of questions
182182
questions:
@@ -189,12 +189,6 @@ paths:
189189
application/json:
190190
schema:
191191
$ref: "#/definitions/Error"
192-
404:
193-
description: Question Not Found
194-
content:
195-
application/json:
196-
schema:
197-
$ref: "#/definitions/Error"
198192
500:
199193
description: Internal Server Error
200194
content:
@@ -290,7 +284,7 @@ paths:
290284
required: true
291285
description: Question id
292286
responses:
293-
200:
287+
200:
294288
description: Successful Response
295289
content:
296290
application/json:
@@ -302,7 +296,7 @@ paths:
302296
description: Message
303297
question:
304298
$ref: "#/definitions/Question"
305-
404:
299+
404:
306300
description: Question Not Found
307301
content:
308302
application/json:
@@ -321,7 +315,7 @@ paths:
321315
summary: Returns question categories
322316
description: Returns list of unique question categories
323317
responses:
324-
200:
318+
200:
325319
description: Successful Response
326320
content:
327321
application/json:
@@ -336,12 +330,6 @@ paths:
336330
items:
337331
type: string
338332
description: Categories
339-
404:
340-
description: Categories Not Found
341-
content:
342-
application/json:
343-
schema:
344-
$ref: "#/definitions/Error"
345333
500:
346334
description: Internal Server Error
347335
content:

frontend/.babelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"presets": [
3+
"@babel/preset-env",
4+
"@babel/preset-typescript",
5+
["@babel/preset-react", { "runtime": "automatic" }]
6+
]
7+
}

frontend/__mocks__/styleMock.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const styleMock = {};
2+
3+
export default styleMock;

frontend/jest.config.ts

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
/**
2+
* For a detailed explanation regarding each configuration property, visit:
3+
* https://jestjs.io/docs/configuration
4+
*/
5+
6+
import type { Config } from "jest";
7+
8+
const config: Config = {
9+
// All imported modules in your tests should be mocked automatically
10+
// automock: false,
11+
12+
// Stop running tests after `n` failures
13+
// bail: 0,
14+
15+
// The directory where Jest should store its cached dependency information
16+
// cacheDirectory: "/private/var/folders/04/ng4c26hj1ksdsy_7x_21kvx80000gn/T/jest_dx",
17+
18+
// Automatically clear mock calls, instances, contexts and results before every test
19+
clearMocks: true,
20+
21+
// Indicates whether the coverage information should be collected while executing the test
22+
collectCoverage: true,
23+
24+
// An array of glob patterns indicating a set of files for which coverage information should be collected
25+
// collectCoverageFrom: undefined,
26+
27+
// The directory where Jest should output its coverage files
28+
coverageDirectory: "coverage",
29+
30+
// An array of regexp pattern strings used to skip coverage collection
31+
// coveragePathIgnorePatterns: [
32+
// "/node_modules/"
33+
// ],
34+
35+
// Indicates which provider should be used to instrument code for coverage
36+
coverageProvider: "v8",
37+
38+
// A list of reporter names that Jest uses when writing coverage reports
39+
// coverageReporters: [
40+
// "json",
41+
// "text",
42+
// "lcov",
43+
// "clover"
44+
// ],
45+
46+
// An object that configures minimum threshold enforcement for coverage results
47+
// coverageThreshold: undefined,
48+
49+
// A path to a custom dependency extractor
50+
// dependencyExtractor: undefined,
51+
52+
// Make calling deprecated APIs throw helpful error messages
53+
// errorOnDeprecated: false,
54+
55+
// The default configuration for fake timers
56+
// fakeTimers: {
57+
// "enableGlobally": false
58+
// },
59+
60+
// Force coverage collection from ignored files using an array of glob patterns
61+
// forceCoverageMatch: [],
62+
63+
// A path to a module which exports an async function that is triggered once before all test suites
64+
// globalSetup: undefined,
65+
66+
// A path to a module which exports an async function that is triggered once after all test suites
67+
// globalTeardown: undefined,
68+
69+
// A set of global variables that need to be available in all test environments
70+
// globals: {},
71+
72+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
73+
// maxWorkers: "50%",
74+
75+
// An array of directory names to be searched recursively up from the requiring module's location
76+
// moduleDirectories: [
77+
// "node_modules"
78+
// ],
79+
80+
// An array of file extensions your modules use
81+
// moduleFileExtensions: [
82+
// "js",
83+
// "mjs",
84+
// "cjs",
85+
// "jsx",
86+
// "ts",
87+
// "tsx",
88+
// "json",
89+
// "node"
90+
// ],
91+
92+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
93+
moduleNameMapper: {
94+
'\\.(css)$': '<rootDir>/__mocks__/styleMock.ts',
95+
'\\.(svg)$': '<rootDir>/__mocks__/styleMock.ts',
96+
},
97+
98+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
99+
// modulePathIgnorePatterns: [],
100+
101+
// Activates notifications for test results
102+
// notify: false,
103+
104+
// An enum that specifies notification mode. Requires { notify: true }
105+
// notifyMode: "failure-change",
106+
107+
// A preset that is used as a base for Jest's configuration
108+
// preset: undefined,
109+
110+
// Run tests from one or more projects
111+
// projects: undefined,
112+
113+
// Use this configuration option to add custom reporters to Jest
114+
// reporters: undefined,
115+
116+
// Automatically reset mock state before every test
117+
// resetMocks: false,
118+
119+
// Reset the module registry before running each individual test
120+
// resetModules: false,
121+
122+
// A path to a custom resolver
123+
// resolver: undefined,
124+
125+
// Automatically restore mock state and implementation before every test
126+
// restoreMocks: false,
127+
128+
// The root directory that Jest should scan for tests and modules within
129+
// rootDir: undefined,
130+
131+
// A list of paths to directories that Jest should use to search for files in
132+
// roots: [
133+
// "<rootDir>"
134+
// ],
135+
136+
// Allows you to use a custom runner instead of Jest's default test runner
137+
// runner: "jest-runner",
138+
139+
// The paths to modules that run some code to configure or set up the testing environment before each test
140+
// setupFiles: [],
141+
142+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
143+
// setupFilesAfterEnv: [],
144+
145+
// The number of seconds after which a test is considered as slow and reported as such in the results.
146+
// slowTestThreshold: 5,
147+
148+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
149+
// snapshotSerializers: [],
150+
151+
// The test environment that will be used for testing
152+
testEnvironment: "jsdom",
153+
154+
// Options that will be passed to the testEnvironment
155+
// testEnvironmentOptions: {},
156+
157+
// Adds a location field to test results
158+
// testLocationInResults: false,
159+
160+
// The glob patterns Jest uses to detect test files
161+
// testMatch: [
162+
// "**/__tests__/**/*.[jt]s?(x)",
163+
// "**/?(*.)+(spec|test).[tj]s?(x)"
164+
// ],
165+
166+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
167+
// testPathIgnorePatterns: [
168+
// "/node_modules/"
169+
// ],
170+
171+
// The regexp pattern or array of patterns that Jest uses to detect test files
172+
// testRegex: [],
173+
174+
// This option allows the use of a custom results processor
175+
// testResultsProcessor: undefined,
176+
177+
// This option allows use of a custom test runner
178+
// testRunner: "jest-circus/runner",
179+
180+
// A map from regular expressions to paths to transformers
181+
// transform: undefined,
182+
183+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
184+
// transformIgnorePatterns: [
185+
// "/node_modules/",
186+
// "\\.pnp\\.[^\\/]+$"
187+
// ],
188+
189+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
190+
// unmockedModulePathPatterns: undefined,
191+
192+
// Indicates whether each individual test should be reported during the run
193+
// verbose: undefined,
194+
195+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
196+
// watchPathIgnorePatterns: [],
197+
198+
// Whether to use watchman for file crawling
199+
// watchman: true,
200+
};
201+
202+
export default config;

0 commit comments

Comments
 (0)