Skip to content

Commit 4357b49

Browse files
committed
Fix docker compose test
1 parent fce340e commit 4357b49

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

backend/user-service/config/redis.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import dotenv from "dotenv";
33

44
dotenv.config();
55

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";
710

811
const client = createClient({ url: REDIS_URI });
912

backend/user-service/model/repository.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export async function createUser(
3131
email,
3232
password,
3333
isAdmin,
34+
isVerified,
3435
});
3536
return user.save();
3637
}

backend/user-service/scripts/seed.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export async function seedAdminAccount() {
3838
adminUsername,
3939
adminEmail,
4040
hashedPassword,
41+
true,
4142
true
4243
);
4344
console.log("Admin account created successfully.");

backend/user-service/tests/authRoutes.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import supertest from "supertest";
44
import app from "../app";
55
import UserModel from "../model/user-model";
66

7+
jest.setTimeout(10000);
8+
79
const request = supertest(app);
810

911
const AUTH_BASE_URL = "/api/auth";
@@ -25,6 +27,7 @@ const insertAdminUser = async () => {
2527
email,
2628
password: hashedPassword,
2729
isAdmin: true,
30+
isVerified: true,
2831
}).save();
2932

3033
return { email, password };
@@ -37,6 +40,7 @@ const insertNonAdminUser = async () => {
3740
lastName,
3841
email,
3942
password: hashedPassword,
43+
isVerified: true,
4044
}).save();
4145

4246
return { email, password };

docker-compose-test.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
name: peerprep-test
2+
13
services:
24
test-user-service:
35
image: peerprep/user-service
46
build: ./backend/user-service
57
env_file: ./backend/user-service/.env
68
environment:
7-
- MONGO_URI_TEST=mongodb://mongo:mongo@mongo:27017/
9+
- MONGO_URI_TEST=mongodb://mongo:mongo@test-mongo:27017/
810
depends_on:
9-
- mongo
10-
- redis
11+
- test-mongo
12+
- test-redis
1113
networks:
1214
- peerprep-network
1315
volumes:
@@ -16,17 +18,17 @@ services:
1618
restart: on-failure
1719
command: ["npm", "test"]
1820

19-
mongo:
21+
test-mongo:
2022
image: mongo
2123
restart: always
2224
networks:
2325
- peerprep-network
2426
env_file:
2527
- ./backend/.env
2628

27-
redis:
29+
test-redis:
2830
image: redis:8.0-M01
29-
container_name: redis
31+
container_name: test-redis
3032
networks:
3133
- peerprep-network
3234
healthcheck:

0 commit comments

Comments
 (0)