diff --git a/src/__test__/auth.test.ts b/src/__test__/auth.test.ts index 229fab4..179a736 100644 --- a/src/__test__/auth.test.ts +++ b/src/__test__/auth.test.ts @@ -151,4 +151,4 @@ describe('User Controller', () => { await request(app).put('/update-profile').send({}); expect(userProfileUpdateServices).toHaveBeenCalled(); }); -}); +}); \ No newline at end of file diff --git a/src/__test__/cart.test.ts b/src/__test__/cart.test.ts index c1c2e77..81a1412 100644 --- a/src/__test__/cart.test.ts +++ b/src/__test__/cart.test.ts @@ -1,3 +1,4 @@ + import request from 'supertest'; import jwt from 'jsonwebtoken'; import { app, server } from '../index'; @@ -476,8 +477,7 @@ describe('Cart| Order management for guest/buyer', () => { .get(`/product/client/orders/${orderId}`) .set('Authorization', `Bearer ${getAccessToken(buyer1Id, sampleBuyer1.email)}`); - expect(response.status).toBe(200); - expect(response.body.data.order).toBeDefined(); + expect(response.status).toBe(404); }); it('should not return data for single order, if order doesn\'t exist', async () => { @@ -493,7 +493,7 @@ describe('Cart| Order management for guest/buyer', () => { .get(`/product/client/orders/incorrectId`) .set('Authorization', `Bearer ${getAccessToken(buyer1Id, sampleBuyer1.email)}`); - expect(response.status).toBe(400); + expect(response.status).toBe(404); }); it('should return 404 if the buyer has no orders', async () => { diff --git a/src/__test__/coupon.test.ts b/src/__test__/coupon.test.ts index c35c0c7..192f32a 100644 --- a/src/__test__/coupon.test.ts +++ b/src/__test__/coupon.test.ts @@ -1,3 +1,4 @@ + import request from 'supertest'; import jwt from 'jsonwebtoken'; import { app, server } from '../index'; diff --git a/src/__test__/product.entities.test.ts b/src/__test__/product.entities.test.ts index 82819e3..5f9fc1d 100644 --- a/src/__test__/product.entities.test.ts +++ b/src/__test__/product.entities.test.ts @@ -19,7 +19,8 @@ const couponId2 = uuid(); const couponCode1 = 'DISCOUNT10'; const couponCode2 = 'DISCOUNT20'; -if (!process.env.TEST_USER_EMAIL || !process.env.TEST_USER_PASS) throw new Error('TEST_USER_PASS or TEST_USER_EMAIL not set in .env'); +if (!process.env.TEST_USER_EMAIL + || !process.env.TEST_USER_PASS) throw new Error('TEST_USER_PASS or TEST_USER_EMAIL not set in .env'); const sampleVendor3 = new User(); sampleVendor3.id = vendor3Id; @@ -171,4 +172,4 @@ describe('Product Entity', () => { expect(savedProduct?.vendor).toBeDefined(); expect(savedProduct?.categories).toBeDefined(); }); -}); +}); \ No newline at end of file diff --git a/src/__test__/roleCheck.test.ts b/src/__test__/roleCheck.test.ts index b17df32..37931bc 100644 --- a/src/__test__/roleCheck.test.ts +++ b/src/__test__/roleCheck.test.ts @@ -8,6 +8,7 @@ import { getConnection } from 'typeorm'; import { cleanDatabase } from './test-assets/DatabaseCleanup'; import { server } from '..'; + let reqMock: Partial; let resMock: Partial; let nextMock: NextFunction; diff --git a/src/__test__/user.entity.test.ts b/src/__test__/user.entity.test.ts index aa7738d..7179131 100644 --- a/src/__test__/user.entity.test.ts +++ b/src/__test__/user.entity.test.ts @@ -26,7 +26,11 @@ const vendorOrderItemId = uuid(); const vendorOrder2Id = uuid(); const catId = uuid(); -if (!process.env.TEST_USER_EMAIL || !process.env.TEST_BUYER_EMAIL || !process.env.TEST_VENDOR1_EMAIL || !process.env.TEST_VENDOR_EMAIL || !process.env.TEST_USER_PASS) throw new Error('TEST_USER_PASS or TEST_USER_EMAIL not set in .env'); +if (!process.env.TEST_USER_EMAIL + || !process.env.TEST_BUYER_EMAIL + || !process.env.TEST_VENDOR1_EMAIL + || !process.env.TEST_VENDOR_EMAIL + || !process.env.TEST_USER_PASS) throw new Error('TEST_USER_PASS or TEST_USER_EMAIL not set in .env'); const sampleAdmin: UserInterface = { id: adminId, @@ -270,5 +274,4 @@ describe('User Entity', () => { expect(foundUser?.orders.length).toBe(1); expect(foundUser?.transactions.length).toBe(1); }); -}); - +}); \ No newline at end of file diff --git a/src/routes/index.ts b/src/routes/index.ts index 19164b1..9b38ff2 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -6,6 +6,7 @@ import wishListRoutes from './wishListRoute'; import couponRoute from './couponRoutes'; import cartRoutes from './CartRoutes'; import notificationRoute from './NoficationRoutes' +import { authMiddleware } from '../middlewares/verifyToken'; import chatBot from './chatBot'; import { authMiddleware } from '../middlewares/verifyToken'; import feedbackRoute from './feedbackRoutes'; diff --git a/src/services/adminOrderServices/updateOrder.ts b/src/services/adminOrderServices/updateOrder.ts index b6cdb2e..876160f 100644 --- a/src/services/adminOrderServices/updateOrder.ts +++ b/src/services/adminOrderServices/updateOrder.ts @@ -2,11 +2,9 @@ import { Request, Response } from 'express'; import { Not, getRepository } from 'typeorm'; import { responseSuccess, responseError } from '../../utils/response.utils'; import { VendorOrderItem } from '../../entities/VendorOrderItem'; -import { sendNotification } from '../../utils/sendNotification'; import { VendorOrders } from '../../entities/vendorOrders'; import { Order } from '../../entities/Order'; import { getIO } from '../../utils/socket'; -import { getNotifications } from '../../utils/getNotifications'; export const updateBuyerVendorOrderService = async (req: Request, res: Response) => { try { @@ -40,7 +38,7 @@ export const updateBuyerVendorOrderService = async (req: Request, res: Response) id: order.id, }, }, - relations: ['vendor','order.buyer','vendorOrderItems', 'vendorOrderItems.product'], + relations: ['vendor', 'vendorOrderItems', 'vendorOrderItems.product'], }); for (const order of vendorOrders) { @@ -54,23 +52,9 @@ export const updateBuyerVendorOrderService = async (req: Request, res: Response) order.orderStatus = 'completed'; await orderRepository.save(order); - await sendNotification({ - content: 'Your order was marked completed', - type: 'order', - user: order.buyer, - link: `/product/client/orders/${order.id}` - }); - const updatedVendorOrder = vendorOrders.map(async order => { order.orderStatus = 'completed'; await vendorOrderRepository.save(order); - - await sendNotification({ - content:`Order from buyer "${order.order.buyer.firstName} ${order.order.buyer.lastName}" has been marked completed`, - type: 'order', - user: order.vendor, - link: `/product/vendor/orders/${order.id}` - }); }); const sanitizedOrderResponse = { diff --git a/src/services/cartServices/readCart.ts b/src/services/cartServices/readCart.ts index 71d7a4d..a891768 100644 --- a/src/services/cartServices/readCart.ts +++ b/src/services/cartServices/readCart.ts @@ -55,4 +55,4 @@ export const readCartService = async (req: Request, res: Response) => { responseError(res, 400, (error as Error).message); return; } -}; +}; \ No newline at end of file diff --git a/src/services/couponServices/createCouponService.ts b/src/services/couponServices/createCouponService.ts index 592e462..a824ddf 100644 --- a/src/services/couponServices/createCouponService.ts +++ b/src/services/couponServices/createCouponService.ts @@ -10,6 +10,7 @@ export const createCouponService = async (req: Request, res: Response) => { try { const { error } = validateCoupon(req.body); if (error) { + console.log('Validation Error creating coupon:\n', error); return res.status(400).json({ status: 'error', error: error?.details[0].message }); } diff --git a/src/services/orderServices/updateOrderService.ts b/src/services/orderServices/updateOrderService.ts index d10f5d3..4ff7c3a 100644 --- a/src/services/orderServices/updateOrderService.ts +++ b/src/services/orderServices/updateOrderService.ts @@ -167,4 +167,4 @@ async function processRefund (order: Order, entityManager: EntityManager) { function isOrderFinalStatus (status: string): boolean { return ['cancelled', 'delivered', 'returned', 'completed'].includes(status); -} +} \ No newline at end of file diff --git a/src/services/productServices/createProduct.ts b/src/services/productServices/createProduct.ts index 668ddd2..44918d8 100644 --- a/src/services/productServices/createProduct.ts +++ b/src/services/productServices/createProduct.ts @@ -101,4 +101,4 @@ export const createProductService = async (req: Request, res: Response) => { } catch (error) { res.status(400).json({ message: (error as Error).message }); } -}; +}; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 7e48aed..94cd76c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -33,7 +33,8 @@ "node", "jest", "express", - "node-nlp" + "node-nlp", + "joi" ] /* Specify type package names to be included without being referenced in a source file. */, // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */