Skip to content

Commit 80dfe42

Browse files
authored
Merge pull request #17 from ChinZJ/feature/user-service
test(user-service) Add tests to Models, Services and Utils
2 parents f2233c5 + daea573 commit 80dfe42

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4224
-187
lines changed

.github/workflows/codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
run: npx jest --coverage
2727

2828
- name: Upload results to Codecov
29+
if: always()
2930
uses: codecov/codecov-action@v5
3031
with:
3132
token: ${{ secrets.CODECOV_TOKEN }}

frontend/src/components/authContainer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const AuthContainer: React.FC = () => {
1515
}
1616
if (user) {
1717
if (!user.profileComplete && window.location.pathname !== '/complete-profile') {
18+
console.log('do i make it here bro');
19+
console.log(user);
20+
console.log('profile complete is ', user.profileComplete);
1821
return <Navigate to="/complete-profile" replace />;
1922
}
2023
const isVerified = user.verified || user.googleOAuthVerified || user.githubOAuthVerified;

jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ const config: Config = {
233233
tsconfig: {
234234
esModuleInterop: true,
235235
allowSyntheticDefaultImports: true,
236-
module: 'commonjs', // Add this line
236+
module: 'commonjs',
237237
},
238238
},
239239
],

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@types/express": "^5.0.3",
3737
"@types/jest": "^30.0.0",
3838
"@types/jsonwebtoken": "^9.0.10",
39+
"@types/mongodb-memory-server": "^1.8.0",
3940
"@types/multer": "^2.0.0",
4041
"@types/passport": "^1.0.17",
4142
"@types/passport-github2": "^1.2.9",
@@ -76,7 +77,7 @@
7677
"fast-csv": "^5.0.5",
7778
"helmet": "^8.1.0",
7879
"jsonwebtoken": "^9.0.2",
79-
"mongoose": "^8.18.2",
80+
"mongoose": "^8.19.1",
8081
"multer": "^2.0.2",
8182
"passport": "^0.7.0",
8283
"passport-github2": "^0.1.12",

user-service/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"express": "^5.1.0",
2626
"fast-csv": "^5.0.5",
2727
"jsonwebtoken": "^9.0.2",
28-
"mongoose": "^8.18.2",
28+
"mongoose": "^8.19.1",
2929
"multer": "^2.0.2",
3030
"passport": "^0.7.0",
3131
"passport-github2": "^0.1.12",
@@ -41,10 +41,12 @@
4141
"@types/cors": "^2.8.19",
4242
"@types/express": "^5.0.3",
4343
"@types/jsonwebtoken": "^9.0.10",
44+
"@types/mongodb-memory-server": "^1.8.0",
4445
"@types/node": "^24.3.1",
4546
"@types/passport": "^1.0.17",
4647
"@types/passport-github2": "^1.2.9",
4748
"@types/passport-google-oauth20": "^2.0.16",
49+
"mongodb-memory-server": "^10.2.3",
4850
"nodemon": "^3.1.10",
4951
"ts-node": "^10.9.2",
5052
"ts-node-dev": "^2.0.0",

user-service/src/constants/env.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
import dotenv from 'dotenv';
22
import path from 'path';
3-
import {fileURLToPath} from 'url';
3+
4+
// Force search to project root to bypass CJS and ESNext conflicts.
5+
const TARGET_DIR = 'cs3219-ay2526s1-project-g03';
6+
const findProjectRoot = (targetDirName = TARGET_DIR): string => {
7+
let currentDir = process.cwd();
8+
9+
while (true) {
10+
const base = path.basename(currentDir);
11+
if (base == targetDirName) {
12+
return currentDir;
13+
}
14+
15+
const parentDir = path.dirname(currentDir);
16+
if (parentDir === currentDir) {
17+
throw new Error(`Could not find directory ${targetDirName} in path hierarchy.`);
18+
}
19+
20+
currentDir = parentDir;
21+
}
22+
};
23+
24+
dotenv.config({path: path.join(findProjectRoot(), '.env')});
425

526
// Solution adapted from:
627
// https://stackoverflow.com/questions/64383909/dirname-is-not-defined-error-in-node-js-14-version
7-
const filename = fileURLToPath(import.meta.url);
8-
const dirname = path.dirname(filename);
28+
// const filename = fileURLToPath(import.meta.url);
29+
// const dirname = path.dirname(filename);
930

10-
dotenv.config({path: path.resolve(dirname, '../../../.env')});
31+
// dotenv.config({path: path.resolve(dirname, '../../../.env')});
1132

1233
/**
1334
* Processes all environment variables.

user-service/src/constants/jwtAudience.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

user-service/src/constants/oAuthTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const enum OAuthType {
1+
enum OAuthType {
22
Google = 'google',
33
GitHub = 'github',
44
}

user-service/src/constants/userRoles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const enum UserRoleTypes {
1+
enum UserRoleTypes {
22
User = 'user',
33
Admin = 'admin',
44
}

0 commit comments

Comments
 (0)