From cd8a730ca1b3a694842ec03a016207b716361978 Mon Sep 17 00:00:00 2001 From: gisubizo Jovan Date: Thu, 23 May 2024 10:37:45 +0200 Subject: [PATCH] Fix-#Login: removed UserInfo field when user logs in --- __test__/cart.test.ts | 5 ++++- __test__/payment.test.ts | 8 ++++++-- __test__/product.test.ts | 5 ++++- __test__/user.test.ts | 3 ++- src/controllers/userControllers.ts | 1 - 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/__test__/cart.test.ts b/__test__/cart.test.ts index 418f085..e5b12f7 100644 --- a/__test__/cart.test.ts +++ b/__test__/cart.test.ts @@ -8,6 +8,8 @@ import User from "../src/sequelize/models/users"; import bcrypt from "bcrypt"; import { Role } from "../src/sequelize/models/roles"; import { dummy } from "./prod"; +import * as userServices from "../src/services/user.service" +import { number } from "joi"; const queryInterface = sequelize.getQueryInterface(); @@ -86,7 +88,8 @@ describe("testing cart", () => { // console.log("response 3--->", res3); sellerToken = res3.body.token; - sellerId = res3.body.userInfo?.id; + const seller = await userServices.getUserByEmail("seller123@example.com"); + const sellerId = seller?.id; await request(app) .patch(`/api/v1/users/${sellerId}/role`) diff --git a/__test__/payment.test.ts b/__test__/payment.test.ts index 4dc8e40..0070c7e 100644 --- a/__test__/payment.test.ts +++ b/__test__/payment.test.ts @@ -8,11 +8,12 @@ import User from "../src/sequelize/models/users"; import bcrypt from "bcryptjs"; import { Role } from "../src/sequelize/models/roles"; import { dummy } from "./prod"; +import * as userServive from "../src/services/user.service" let buyerToken: any; let adminToken: any; let sellerToken: any; -let sellerId: number; + describe("test stripe api payment", () => { beforeAll(async () => { @@ -79,8 +80,11 @@ describe("test stripe api payment", () => { email: "seller123@example.com", password: "password", }); + + const seller = await userServive.getUserByEmail("seller123@example.com"); sellerToken = sellerResponse.body.token; - sellerId = sellerResponse.body.userInfo?.id; + + let sellerId = seller?.id; await request(app) .patch(`/api/v1/users/${sellerId}/role`) diff --git a/__test__/product.test.ts b/__test__/product.test.ts index d4045a9..7f8e239 100644 --- a/__test__/product.test.ts +++ b/__test__/product.test.ts @@ -15,6 +15,7 @@ import { placeOrder } from "../src/services/payment.service"; import Cart from "../src/sequelize/models/Cart"; import CartItem from "../src/sequelize/models/CartItem"; import OrderItem from "../src/sequelize/models/orderItems"; +import * as userService from "../src/services/user.service" const userData: any = { name: "yvanna", @@ -137,7 +138,9 @@ describe("Testing product Routes", () => { }); expect(logDummySeller.status).toBe(200); token = logDummySeller.body.token; - const dummySellerId = logDummySeller.body.userInfo.id; + + const seller = await userService.getUserByEmail(dummySeller.email) + const dummySellerId = seller?.id; const response = await request(app) .patch(`/api/v1/users/${dummySellerId}/role`) diff --git a/__test__/user.test.ts b/__test__/user.test.ts index 0019e84..3c40b2f 100644 --- a/__test__/user.test.ts +++ b/__test__/user.test.ts @@ -217,7 +217,8 @@ describe("Testing user Routes", () => { password: dummySeller.password, }); expect(logDummySeller.status).toBe(200); - const dummySellerId = logDummySeller.body.userInfo.id; + const seller = await userServices.getUserByEmail(dummySeller.email); + const dummySellerId = seller?.id; const response = await request(app) .patch(`/api/v1/users/${dummySellerId}/role`) diff --git a/src/controllers/userControllers.ts b/src/controllers/userControllers.ts index 26219d5..2f7f179 100644 --- a/src/controllers/userControllers.ts +++ b/src/controllers/userControllers.ts @@ -83,7 +83,6 @@ export const userLogin = async (req: Request, res: Response) => { return res.status(200).json({ status: 200, message: "Logged in", - userInfo: userInfo, token: accessToken }); }