File tree Expand file tree Collapse file tree 11 files changed +84
-50
lines changed Expand file tree Collapse file tree 11 files changed +84
-50
lines changed Original file line number Diff line number Diff line change @@ -29,4 +29,8 @@ USER=EMAIL_ADDRESS
29
29
PASS = PASSWORD
30
30
31
31
# Redis configuration
32
- REDIS_URI = REDIS_URI
32
+ REDIS_URI = REDIS_URI
33
+
34
+ # Test
35
+ MONGO_URI_TEST = mongodb://mongo:mongo@test-mongo:27017/
36
+ REDIS_URI_TEST = redis://test-redis:6379
Original file line number Diff line number Diff line change @@ -3,7 +3,10 @@ import dotenv from "dotenv";
3
3
4
4
dotenv . config ( ) ;
5
5
6
- const REDIS_URI = process . env . REDIS_URI || "redis://localhost:6379" ;
6
+ const REDIS_URI =
7
+ process . env . NODE_ENV === "test"
8
+ ? process . env . REDIS_URI_TEST
9
+ : process . env . REDIS_URI || "redis://localhost:6379" ;
7
10
8
11
const client = createClient ( { url : REDIS_URI } ) ;
9
12
Original file line number Diff line number Diff line change @@ -155,12 +155,10 @@ export const verifyUser = async (
155
155
156
156
const updatedUser = await _updateUserVerification ( email ) ;
157
157
if ( ! updatedUser ) {
158
- return res . status ( 404 ) . json ( { message : `User ${ email } not verified.` } ) ;
158
+ return res . status ( 404 ) . json ( { message : `User not verified.` } ) ;
159
159
}
160
160
161
- return res
162
- . status ( 200 )
163
- . json ( { message : `User ${ email } verified successfully.` } ) ;
161
+ return res . status ( 200 ) . json ( { message : `User verified successfully.` } ) ;
164
162
} catch ( error ) {
165
163
return res
166
164
. status ( 500 )
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ export async function createUser(
31
31
email,
32
32
password,
33
33
isAdmin,
34
+ isVerified,
34
35
} ) ;
35
36
return user . save ( ) ;
36
37
}
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ export async function seedAdminAccount() {
38
38
adminUsername ,
39
39
adminEmail ,
40
40
hashedPassword ,
41
+ true ,
41
42
true
42
43
) ;
43
44
console . log ( "Admin account created successfully." ) ;
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import supertest from "supertest";
4
4
import app from "../app" ;
5
5
import UserModel from "../model/user-model" ;
6
6
7
+ jest . setTimeout ( 10000 ) ;
8
+
7
9
const request = supertest ( app ) ;
8
10
9
11
const AUTH_BASE_URL = "/api/auth" ;
@@ -25,6 +27,7 @@ const insertAdminUser = async () => {
25
27
email,
26
28
password : hashedPassword ,
27
29
isAdmin : true ,
30
+ isVerified : true ,
28
31
} ) . save ( ) ;
29
32
30
33
return { email, password } ;
@@ -37,6 +40,7 @@ const insertNonAdminUser = async () => {
37
40
lastName,
38
41
email,
39
42
password : hashedPassword ,
43
+ isVerified : true ,
40
44
} ) . save ( ) ;
41
45
42
46
return { email, password } ;
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import redisClient from "../config/redis";
3
3
4
4
beforeAll ( async ( ) => {
5
5
const mongoUri =
6
- process . env . MONGO_URI_TEST || "mongodb://mongo:mongo@mongo:27017/" ;
6
+ process . env . MONGO_URI_TEST || "mongodb://mongo:mongo@test- mongo:27017/" ;
7
7
8
8
await mongoose . connect ( mongoUri , { } ) ;
9
9
await redisClient . connect ( ) ;
Original file line number Diff line number Diff line change
1
+ name : peerprep-test
2
+
1
3
services :
2
4
test-user-service :
3
5
image : peerprep/user-service
4
6
build : ./backend/user-service
5
7
env_file : ./backend/user-service/.env
6
- environment :
7
- - MONGO_URI_TEST=mongodb://mongo:mongo@mongo:27017/
8
8
depends_on :
9
- - mongo
10
- - redis
9
+ - test- mongo
10
+ - test- redis
11
11
networks :
12
12
- peerprep-network
13
13
volumes :
@@ -16,17 +16,17 @@ services:
16
16
restart : on-failure
17
17
command : ["npm", "test"]
18
18
19
- mongo :
19
+ test- mongo :
20
20
image : mongo
21
21
restart : always
22
22
networks :
23
23
- peerprep-network
24
24
env_file :
25
25
- ./backend/.env
26
26
27
- redis :
27
+ test- redis :
28
28
image : redis:8.0-M01
29
- container_name : redis
29
+ container_name : test- redis
30
30
networks :
31
31
- peerprep-network
32
32
healthcheck :
Original file line number Diff line number Diff line change 1
- import { Routes , Route } from "react-router-dom" ;
1
+ import { Routes , Route , Navigate } from "react-router-dom" ;
2
2
3
3
import NewQuestion from "./pages/NewQuestion" ;
4
4
import QuestionDetail from "./pages/QuestionDetail" ;
@@ -64,10 +64,15 @@ function App() {
64
64
</ Route >
65
65
< Route path = "*" element = { < PageNotFound /> } />
66
66
</ Route >
67
- < Route path = "/auth" >
67
+ < Route path = "auth" >
68
+ < Route index element = { < Navigate to = "/auth/login" /> } />
68
69
< Route path = "signup" element = { < SignUp /> } />
69
70
< Route path = "login" element = { < LogIn /> } />
70
- < Route path = "verifyEmail/:userId" element = { < EmailVerification /> } />
71
+ < Route
72
+ path = "verifyEmail/:userId?"
73
+ element = { < EmailVerification /> }
74
+ />
75
+ < Route path = "*" element = { < Navigate to = "/auth/login" /> } />
71
76
</ Route >
72
77
</ Routes >
73
78
</ MatchProvider >
Original file line number Diff line number Diff line change @@ -67,8 +67,6 @@ const AuthProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
67
67
. then ( ( ) => userClient . post ( "users/send-verification-email" , { email } ) )
68
68
. then ( ( res ) => {
69
69
navigate ( `/auth/verifyEmail/${ res . data . data . id } ` ) ;
70
- // navigate("/login");
71
- // toast.success(res.data.message);
72
70
} )
73
71
. catch ( ( err ) => {
74
72
setUser ( null ) ;
@@ -89,6 +87,9 @@ const AuthProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
89
87
navigate ( "/home" ) ;
90
88
} )
91
89
. catch ( ( err ) => {
90
+ if ( err . response ?. data . message === "User not verified." ) {
91
+ navigate ( `/auth/verifyEmail` ) ;
92
+ }
92
93
setUser ( null ) ;
93
94
toast . error ( err . response ?. data . message || err . message ) ;
94
95
} ) ;
You can’t perform that action at this time.
0 commit comments