Skip to content

Commit

Permalink
Merge branch 'ft-coverage' of https://github.com/atlp-rwanda/knights-…
Browse files Browse the repository at this point in the history
…ecomm-be into ft-coverage
  • Loading branch information
elijahladdie committed Jun 5, 2024
2 parents 5ee96fd + 804f595 commit 9ce478a
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/__test__/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,4 @@ describe('User Controller', () => {
await request(app).put('/update-profile').send({});
expect(userProfileUpdateServices).toHaveBeenCalled();
});
});
});
6 changes: 3 additions & 3 deletions src/__test__/cart.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import request from 'supertest';
import jwt from 'jsonwebtoken';
import { app, server } from '../index';
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand Down
1 change: 1 addition & 0 deletions src/__test__/coupon.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import request from 'supertest';
import jwt from 'jsonwebtoken';
import { app, server } from '../index';
Expand Down
5 changes: 3 additions & 2 deletions src/__test__/product.entities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -171,4 +172,4 @@ describe('Product Entity', () => {
expect(savedProduct?.vendor).toBeDefined();
expect(savedProduct?.categories).toBeDefined();
});
});
});
1 change: 1 addition & 0 deletions src/__test__/roleCheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getConnection } from 'typeorm';
import { cleanDatabase } from './test-assets/DatabaseCleanup';
import { server } from '..';


let reqMock: Partial<Request>;
let resMock: Partial<Response>;
let nextMock: NextFunction;
Expand Down
9 changes: 6 additions & 3 deletions src/__test__/user.entity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -270,5 +274,4 @@ describe('User Entity', () => {
expect(foundUser?.orders.length).toBe(1);
expect(foundUser?.transactions.length).toBe(1);
});
});

});
1 change: 1 addition & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
18 changes: 1 addition & 17 deletions src/services/adminOrderServices/updateOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/services/cartServices/readCart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ export const readCartService = async (req: Request, res: Response) => {
responseError(res, 400, (error as Error).message);
return;
}
};
};
1 change: 1 addition & 0 deletions src/services/couponServices/createCouponService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/orderServices/updateOrderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ async function processRefund (order: Order, entityManager: EntityManager) {

function isOrderFinalStatus (status: string): boolean {
return ['cancelled', 'delivered', 'returned', 'completed'].includes(status);
}
}
2 changes: 1 addition & 1 deletion src/services/productServices/createProduct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ export const createProductService = async (req: Request, res: Response) => {
} catch (error) {
res.status(400).json({ message: (error as Error).message });
}
};
};
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit 9ce478a

Please sign in to comment.