Skip to content

Commit 667e6ee

Browse files
mergerd improvements1
2 parents ac84484 + eccad39 commit 667e6ee

34 files changed

+28905
-5759
lines changed

API_Gateway/babel.config.cjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
"@babel/preset-env",
5+
{
6+
targets: { node: "current" },
7+
},
8+
],
9+
],
10+
};

API_Gateway/jest.config.js

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

API_Gateway/package-lock.json

Lines changed: 6485 additions & 535 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

API_Gateway/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"start": "node src/server.js",
88
"dev": "nodemon src/server.js",
9-
"test": "echo \"Error: no test specified\" && exit 1"
9+
"test":"jest"
1010
},
1111
"keywords": [],
1212
"author": "Anuja Kalhara",
@@ -22,6 +22,10 @@
2222
"morgan": "^1.10.1"
2323
},
2424
"devDependencies": {
25-
"nodemon": "^3.1.10"
25+
"@babel/preset-env": "^7.28.3",
26+
"babel-jest": "^30.1.2",
27+
"jest": "^30.1.3",
28+
"nodemon": "^3.1.10",
29+
"supertest": "^7.1.4"
2630
}
2731
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import request from "supertest";
2+
import express from "express";
3+
import jwt from "jsonwebtoken";
4+
5+
import setupAuth from "../middleware/auth.js";
6+
import setupRateLimit from "../middleware/ratelimit.js";
7+
import setupLogging from "../middleware/logging.js";
8+
import setupProxies from "../middleware/proxy.js";
9+
import ROUTES from "../routes.js";
10+
11+
jest.mock("http-proxy-middleware", () => ({
12+
createProxyMiddleware: () => (req, res, next) => {
13+
res.status(200).send(`Mocked proxy response for ${req.url}`);
14+
},
15+
}));
16+
17+
describe("API Gateway", () => {
18+
let app;
19+
const TEST_SECRET = "test_secret";
20+
21+
beforeAll(() => {
22+
process.env.SUPABASE_JWT_SECRET = TEST_SECRET;
23+
24+
app = express();
25+
26+
setupLogging(app);
27+
setupRateLimit(app, ROUTES);
28+
setupAuth(app, ROUTES);
29+
30+
const mockServer = { on: () => {} };
31+
setupProxies(app, ROUTES, mockServer);
32+
33+
app.get("/health", (req, res) => {
34+
res.json({ message: "Welcome to the API Gateway" });
35+
});
36+
});
37+
38+
it("should return health status", async () => {
39+
const res = await request(app).get("/health");
40+
expect(res.status).toBe(200);
41+
expect(res.body.message).toBe("Welcome to the API Gateway");
42+
});
43+
44+
it("should allow /codespaces with valid JWT", async () => {
45+
const token = jwt.sign({ sub: "user1", email: "user1@test.com" }, TEST_SECRET);
46+
const res = await request(app)
47+
.get("/codespaces")
48+
.set("Authorization", token);
49+
50+
expect(res.status).toBe(200);
51+
52+
});
53+
it("should respect rate limit on /free", async () => {
54+
const limit = ROUTES.find(r => r.url === "/free").rateLimit.limit;
55+
56+
for (let i = 0; i < limit; i++) {
57+
await request(app).get("/free");
58+
}
59+
60+
const res = await request(app).get("/free");
61+
expect(res.status).toBe(429);
62+
});
63+
64+
it("should pass through unauthenticated route /free", async () => {
65+
const res = await request(app).get("/free");
66+
expect([429]).toContain(res.status);
67+
});
68+
});

Codespace_Service/babel.config.cjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
"@babel/preset-env",
5+
{
6+
targets: { node: "current" },
7+
},
8+
],
9+
],
10+
};

Codespace_Service/jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
testEnvironment: "node",
3+
4+
};

0 commit comments

Comments
 (0)