Skip to content

Commit ba1b28b

Browse files
TEST UPDATE: Added flags for mock data and authentication setting on the server (#10)
1 parent 2ca2d1a commit ba1b28b

File tree

5 files changed

+255
-15
lines changed

5 files changed

+255
-15
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,30 @@ each time.
4545
Simply run the below command in the `server` directory
4646

4747
```sh
48-
npm run start-dev
48+
npm run dev
4949
```
5050

5151
This will start a development server with the `ts-node` and `nodemon` packages. This allows for easy development via cold-reloading. `ts-node` allows for running the typescript code without the need for compliation while `nodemon` monitors for changes to any `.ts` or `.js` files.
5252

53+
_Flags_
54+
55+
56+
| Flag | Descriptions |
57+
| --- | --- |
58+
| MOCK_DATA | Enables Mock paper data for testing |
59+
| AUTH_OFF | Disables authentication when set to 'false' |
60+
61+
Flags can be called with the following commands
62+
63+
```sh
64+
MOCK_DATA=true npm run dev
65+
66+
AUTH_OFF=true npm run dev
67+
68+
MOCK_DATA=true AUTH_OFF=true npm run dev
69+
```
70+
71+
5372
## Testing
5473

5574
Tests are stored in the `test/` directory and end with `*.test.ts`. Testing is done using jest.js and is setup with npm.

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"main": "index.js",
55
"scripts": {
66
"test": "jest",
7-
"start-dev": "npx nodemon",
7+
"dev": "cross-env MOCK_DATA=${MOCK_DATA:-false} AUTH_OFF=${AUTH_OFF:-false} npx nodemon",
88
"start": "npm run build && node build/index.js",
99
"build": "./build && tsc"
1010
},

server/src/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const config = {
2+
MockData: process.env.MOCK_DATA === 'true',
3+
AuthEnable: process.env.AUTH_OFF === 'false'
4+
};
5+
6+
export default config;

server/src/routes/admin-router.ts

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import jwt from "jsonwebtoken";
66
import authenticateJWT from "../auth/jwt-auth";
77
import { GPTController } from "../gpt-controller";
88
import multer from "multer";
9+
import config from "../config";
910

1011
// Set up custom storage for multer
1112
const storage = multer.diskStorage({
@@ -25,6 +26,13 @@ const upload = multer({
2526
limits: { fileSize: 10 * 1024 * 1024 },
2627
}); // 10mb limit
2728

29+
function getAuthMiddleware() {
30+
if (config.AuthEnable) {
31+
return authenticateJWT;
32+
}
33+
return (req: Request, res: Response, next: Function) => next();
34+
}
35+
2836
export default function adminRouter(
2937
dbController: DatabaseController,
3038
gptController: GPTController,
@@ -37,7 +45,7 @@ export default function adminRouter(
3745
// THIS WILL NOT WORK WITH RAW PAPERS, Data MUST be in InsertData format
3846
router.post(
3947
"/insertPapers",
40-
authenticateJWT,
48+
getAuthMiddleware(),
4149
async (req: Request, res: Response) => {
4250
try {
4351
await insertRows(
@@ -55,23 +63,35 @@ export default function adminRouter(
5563

5664
router.post(
5765
"/parseRequest",
58-
//authenticateJWT,
66+
getAuthMiddleware(),
5967
upload.array("pdfs"),
6068
(req: Request, res: Response) => {
61-
try {
62-
// TODO
63-
parsePapers(req.files, gptController).then((result: GPTResponse[]) => {
64-
res.send(responseToJSON(result));
65-
});
66-
} catch (error) {
67-
console.error(`${error}`);
68-
}
69-
},
69+
try {
70+
// TODO
71+
72+
if (config.MockData) {
73+
import("../../test/testfiles/parse_response.json").then(
74+
(module) => {
75+
res.send(module.default);
76+
},
77+
);
78+
} else {
79+
parsePapers(req.files, gptController).then(
80+
(result: GPTResponse[]) => {
81+
console.log(responseToJSON(result));
82+
res.send(responseToJSON(result));
83+
},
84+
);
85+
}
86+
} catch (error) {
87+
console.error(`${error}`);
88+
}
89+
},
7090
);
7191

7292
router.post(
7393
"/getFullPapers",
74-
/*authenticateJWT,*/ (req: Request, res: Response) => {
94+
getAuthMiddleware(), (req: Request, res: Response) => {
7595
try {
7696
// More intricate searches can be employed later similar to the table filter
7797
getFullPaperRows(req.body.search, dbController).then(
@@ -151,7 +171,9 @@ async function parsePapers(
151171
files: any,
152172
gptController: GPTController,
153173
): Promise<GPTResponse[]> {
154-
const fileList: string[] = files.map((file: Express.Multer.File) => file.path);
174+
const fileList: string[] = files.map(
175+
(file: Express.Multer.File) => file.path,
176+
);
155177
console.log(fileList);
156178
const gptResults = await gptController.runGPTAnalysis(fileList);
157179
return gptResults;
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
[
2+
{
3+
"pass_1": {
4+
"paper_name": "A Radiation Tolerant Video Camera for High Total Dose Environments",
5+
"year": 2000,
6+
"author": [
7+
"G. R. Hopkinson",
8+
"M. D. Skipper",
9+
"B. Taylor"
10+
],
11+
"part_no": "Star-250",
12+
"type": "CMOS active pixel sensor",
13+
"manufacturer": "FillFactory NV, Belgium",
14+
"testing_location": "Terrestrial",
15+
"testing_type": "TID",
16+
"data_type": 0
17+
},
18+
"pass_2": {
19+
"paper_name": "A Radiation Tolerant Video Camera for High Total Dose Environments",
20+
"year": 2002,
21+
"author": [
22+
"G. R. Hopkinson",
23+
"M. D. Skipper",
24+
"B. Taylor"
25+
],
26+
"part_no": "Star-250",
27+
"type": "CMOS active pixel sensor",
28+
"manufacturer": "FillFactory NV, Belgium",
29+
"testing_location": "Terrestrial",
30+
"testing_type": "TID",
31+
"data_type": 0
32+
},
33+
"pass_3": {
34+
"paper_name": "A Radiation Tolerant Video Camera for High Total Dose Environments",
35+
"year": 2002,
36+
"author": [
37+
"G. R. Hopkinson",
38+
"M. D. Skipper",
39+
"B. Taylor"
40+
],
41+
"part_no": "Star-250",
42+
"type": "CMOS active pixel sensor",
43+
"manufacturer": "FillFactory NV, Belgium",
44+
"testing_location": "Terrestrial",
45+
"testing_type": "TID",
46+
"data_type": 0
47+
}
48+
},
49+
{
50+
"pass_1": {
51+
"paper_name": "Solar Flare Proton Environment for Estimating Downtime of Spacecraft CCDs",
52+
"year": 2002,
53+
"author": [
54+
"E. Mikkelson ",
55+
"W. Baba"
56+
],
57+
"part_no": "N/A",
58+
"type": "charge-coupled device",
59+
"manufacturer": "Boeing Satellite Systems ¶ TRW, Inc.",
60+
"testing_location": "Flight",
61+
"testing_type": "SEE",
62+
"data_type": 0
63+
},
64+
"pass_2": {
65+
"paper_name": "Solar Flare Proton Environment for Estimating Downtime of Spacecraft CCDs",
66+
"year": 2000,
67+
"author": [
68+
"E. Mikkelson ",
69+
"W. Baba"
70+
],
71+
"part_no": "N/A",
72+
"type": "charge-coupled device",
73+
"manufacturer": "Boeing Satellite Systems ¶ TRW, Inc.",
74+
"testing_location": "Flight",
75+
"testing_type": "SEE",
76+
"data_type": 0
77+
},
78+
"pass_3": {
79+
"paper_name": "Solar Flare Proton Environment for Estimating Downtime of Spacecraft CCDs",
80+
"year": 2002,
81+
"author": [
82+
"E. Mikkelson ",
83+
"W. Baba"
84+
],
85+
"part_no": "N/A",
86+
"type": "charge-coupled device",
87+
"manufacturer": "Boeing Satellite Systems ¶ TRW, Inc.",
88+
"testing_location": "Flight",
89+
"testing_type": "SEE",
90+
"data_type": 0
91+
}
92+
},
93+
{
94+
"pass_1": {
95+
"paper_name": "SEE In-Flight Data for two Static 32KB Memories on High Earth Orbit",
96+
"year": 2002,
97+
"author": [
98+
"S. Duzellier ",
99+
"S. Bourdarie ",
100+
"R. Velazco ",
101+
"B. Nicolescu ",
102+
"R. Ecoffet"
103+
],
104+
"part_no": "HM62256 ¶ HM65756",
105+
"type": "32KB SRAM",
106+
"manufacturer": "Hitachi ¶ Matra-MHS",
107+
"testing_location": "Flight",
108+
"testing_type": "SEE",
109+
"data_type": 0
110+
},
111+
"pass_2": {
112+
"paper_name": "SEE In-Flight Data for two Static 32KB Memories on High Earth Orbit",
113+
"year": 2002,
114+
"author": [
115+
"S. Duzellier ",
116+
"S. Bourdarie ",
117+
"R. Velazco ",
118+
"B. Nicolescu ",
119+
"R. Ecoffet"
120+
],
121+
"part_no": "HM62256 ¶ HM65756",
122+
"type": "SRAM",
123+
"manufacturer": "Hitachi ¶ Matra-MHS",
124+
"testing_location": "Flight",
125+
"testing_type": "SEE",
126+
"data_type": 0
127+
},
128+
"pass_3": {
129+
"paper_name": "SEE In-Flight Data for two Static 32KB Memories on High Earth Orbit",
130+
"year": 2002,
131+
"author": [
132+
"S. Duzellier ",
133+
"S. Bourdarie ",
134+
"R. Velazco ",
135+
"B. Nicolescu ",
136+
"R. Ecoffet"
137+
],
138+
"part_no": "HM62256 ¶ HM65756",
139+
"type": "32KB SRAM",
140+
"manufacturer": "Hitachi ¶ Matra-MHS",
141+
"testing_location": "Flight",
142+
"testing_type": "SEE",
143+
"data_type": 0
144+
}
145+
},
146+
{
147+
"pass_1": {
148+
"paper_name": "Radiation Effects Predicted, Observed, and Compared for Spacecraft Systems",
149+
"year": 2002,
150+
"author": [
151+
"B. E. Pritchard ",
152+
"G. M. Swift ",
153+
"A. H. Johnston"
154+
],
155+
"part_no": "N/A",
156+
"type": "N/A",
157+
"manufacturer": "Jet Propulsion Laboratory",
158+
"testing_location": "Flight",
159+
"testing_type": "SEE",
160+
"data_type": 0
161+
},
162+
"pass_2": {
163+
"paper_name": "Radiation Effects Predicted, Observed, and Compared for Spacecraft Systems",
164+
"year": 2024,
165+
"author": [
166+
"B. E. Pritchard",
167+
"G. M. Swift",
168+
"A. H. Johnston"
169+
],
170+
"part_no": "N/A",
171+
"type": "N/A",
172+
"manufacturer": "Jet Propulsion Laboratory",
173+
"testing_location": "Flight",
174+
"testing_type": "SEE",
175+
"data_type": 0
176+
},
177+
"pass_3": {
178+
"paper_name": "Radiation Effects Predicted, Observed, and Compared for Spacecraft Systems",
179+
"year": 2002,
180+
"author": [
181+
"B. E. Pritchard",
182+
"G. M. Swift",
183+
"A. H. Johnston"
184+
],
185+
"part_no": "N/A",
186+
"type": "N/A",
187+
"manufacturer": "Jet Propulsion Laboratory",
188+
"testing_location": "Flight",
189+
"testing_type": "SEE",
190+
"data_type": 0
191+
}
192+
}
193+
]

0 commit comments

Comments
 (0)