From 22f808f2105a82e38164de9c45ea19d1da703bbb Mon Sep 17 00:00:00 2001 From: angelalvaigle Date: Wed, 27 Nov 2024 18:21:13 +0100 Subject: [PATCH] unit-test fix (copy utils in dockerfile) --- users/authservice/Dockerfile | 1 + users/authservice/utils/passwordUtils.js | 12 ------------ users/authservice/utils/tokenUtils.js | 16 ---------------- users/userservice/Dockerfile | 1 + users/userservice/user-service.test.js | 2 +- users/userservice/utils/passwordUtils.js | 12 ------------ users/userservice/utils/tokenUtils.js | 16 ---------------- 7 files changed, 3 insertions(+), 57 deletions(-) delete mode 100644 users/authservice/utils/passwordUtils.js delete mode 100644 users/authservice/utils/tokenUtils.js delete mode 100644 users/userservice/utils/passwordUtils.js delete mode 100644 users/userservice/utils/tokenUtils.js diff --git a/users/authservice/Dockerfile b/users/authservice/Dockerfile index 70648d7..78f6ffe 100644 --- a/users/authservice/Dockerfile +++ b/users/authservice/Dockerfile @@ -12,6 +12,7 @@ RUN npm install # Copy the app source code to the working directory COPY . . +COPY utils /usr/src/authservice/utils # Expose the port the app runs on EXPOSE 8002 diff --git a/users/authservice/utils/passwordUtils.js b/users/authservice/utils/passwordUtils.js deleted file mode 100644 index 170c263..0000000 --- a/users/authservice/utils/passwordUtils.js +++ /dev/null @@ -1,12 +0,0 @@ -import bcrypt from 'bcrypt'; - -export const hashPassword = async (password) => { - const salt = await bcrypt.genSalt(10); - const hashedPassword = await bcrypt.hash(password, salt); - return hashedPassword; -}; - -export const comparePassword = async (password, hashedPassword) => { - const isMatch = await bcrypt.compare(password, hashedPassword); - return isMatch; -}; diff --git a/users/authservice/utils/tokenUtils.js b/users/authservice/utils/tokenUtils.js deleted file mode 100644 index f7d84dc..0000000 --- a/users/authservice/utils/tokenUtils.js +++ /dev/null @@ -1,16 +0,0 @@ -import jwt from 'jsonwebtoken'; - -export const createJWT = (payload) => { - const token = jwt.sign(payload, 'your-secret-key', { - // process.env.JWT_SECRET - expiresIn: '1d', // process.env.JWT_EXPIRES_IN, - }); - return token; -}; - -export const verifyJWT = (token) => { - console.log('verjwt'); - console.log(token); - const decoded = jwt.verify(token, 'your-secret-key'); // process.env.JWT_SECRET); - return decoded; -}; diff --git a/users/userservice/Dockerfile b/users/userservice/Dockerfile index f43e2df..c091be1 100644 --- a/users/userservice/Dockerfile +++ b/users/userservice/Dockerfile @@ -12,6 +12,7 @@ RUN npm install # Copy the app source code to the working directory COPY . . +COPY utils /usr/src/userservice/utils # Expose the port the app runs on EXPOSE 8001 diff --git a/users/userservice/user-service.test.js b/users/userservice/user-service.test.js index 39c9c13..007fb00 100644 --- a/users/userservice/user-service.test.js +++ b/users/userservice/user-service.test.js @@ -8,7 +8,7 @@ beforeAll(async () => { mongoServer = await MongoMemoryServer.create(); const mongoUri = mongoServer.getUri(); process.env.MONGODB_URI = mongoUri; - app = require('./user-service'); + app = (await import('./user-service.js')).default; // Import app dynamically to ensure MONGODB_URI is set }); afterAll(async () => { diff --git a/users/userservice/utils/passwordUtils.js b/users/userservice/utils/passwordUtils.js deleted file mode 100644 index 170c263..0000000 --- a/users/userservice/utils/passwordUtils.js +++ /dev/null @@ -1,12 +0,0 @@ -import bcrypt from 'bcrypt'; - -export const hashPassword = async (password) => { - const salt = await bcrypt.genSalt(10); - const hashedPassword = await bcrypt.hash(password, salt); - return hashedPassword; -}; - -export const comparePassword = async (password, hashedPassword) => { - const isMatch = await bcrypt.compare(password, hashedPassword); - return isMatch; -}; diff --git a/users/userservice/utils/tokenUtils.js b/users/userservice/utils/tokenUtils.js deleted file mode 100644 index f7d84dc..0000000 --- a/users/userservice/utils/tokenUtils.js +++ /dev/null @@ -1,16 +0,0 @@ -import jwt from 'jsonwebtoken'; - -export const createJWT = (payload) => { - const token = jwt.sign(payload, 'your-secret-key', { - // process.env.JWT_SECRET - expiresIn: '1d', // process.env.JWT_EXPIRES_IN, - }); - return token; -}; - -export const verifyJWT = (token) => { - console.log('verjwt'); - console.log(token); - const decoded = jwt.verify(token, 'your-secret-key'); // process.env.JWT_SECRET); - return decoded; -};