Skip to content

Commit

Permalink
buyer shuold make checkout to ordering products
Browse files Browse the repository at this point in the history
  • Loading branch information
niyobern authored and ambroisegithub committed May 25, 2024
1 parent bc092b8 commit 73005dc
Show file tree
Hide file tree
Showing 26 changed files with 1,229 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/PULL_REQUEST_TEMPLATE.MD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#### What does this PR do?

#### Description of Task to be completed?
#### Description of Tasks completed?

#### How should this be manually tested?

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"coveragePathIgnorePatterns": [
"/node_modules/",
"/src/emails/",
"/src/middlewares/"
"/src/middlewares/",
"/src/emails/"
],
"testPathIgnorePatterns": [
"/node_modules/",
Expand Down
67 changes: 65 additions & 2 deletions src/__test__/cartController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getBuyerToken,
getVendorToken,
} from './testSetup';

beforeAll(beforeAllHook);
afterAll(afterAllHook);

Expand All @@ -15,13 +16,14 @@ describe('Cart controller tests', () => {
let productId: number;
let itemId: number;
let categoryId: number;
let orderId: number;

beforeAll(async () => {
buyerToken = await getBuyerToken();
vendorToken = await getVendorToken();
});

it('should return cart items and total amount for user', async () => {
it('should return cart items and total amount for the user', async () => {
// create a category
const categoryData = {
name: 'Category4',
Expand Down Expand Up @@ -159,7 +161,8 @@ describe('Cart controller tests', () => {
expect(response.statusCode).toEqual(409);
expect(response.body.msg).toEqual('Invalid Quantity');
});
it('should return 409 if quantity exceeds available quantity while ugating a cart', async () => {

it('should return 409 if quantity exceeds available quantity while updating a cart', async () => {
const exceedQuantity = 50000;
const response = await request(app)
.patch(`/api/v1/cart/${itemId}`)
Expand Down Expand Up @@ -190,6 +193,7 @@ describe('Cart controller tests', () => {
expect(response.body.msg).toEqual('Cart Item deleted successfully');
expect(response.body.count).toBeGreaterThan(0);
});

it('should remove all items from the cart successfully', async () => {
const response = await request(app)
.delete('/api/v1/cart')
Expand All @@ -199,4 +203,63 @@ describe('Cart controller tests', () => {
expect(response.body.msg).toEqual('Cart Items deleted successfully');
expect(response.body.count).toBeGreaterThanOrEqual(0);
});

// New tests for checkout, cancel checkout, and get all orders

it('should place an order successfully', async () => {
const cartResponse = await request(app)
.post('/api/v1/cart')
.set('Authorization', `Bearer ${buyerToken}`)
.send({
productId: productId,
quantity: 2,
});

expect(cartResponse.statusCode).toEqual(201);
expect(cartResponse.body.msg).toEqual('Item added to cart successfully');
expect(cartResponse.body.cartItem).toBeDefined();

const checkoutResponse = await request(app)
.post('/api/v1/order/checkout')
.set('Authorization', `Bearer ${buyerToken}`)
.send({
deliveryInfo: '123 Delivery St.',
paymentInfo: 'VISA 1234',
couponCode: 'DISCOUNT10',
});

expect(checkoutResponse.statusCode).toEqual(201);
expect(checkoutResponse.body.msg).toEqual('Order placed successfully');
expect(checkoutResponse.body.order).toBeDefined();
expect(checkoutResponse.body.trackingNumber).toBeDefined();
orderId = checkoutResponse.body.order.id;
});

it('should cancel an order successfully', async () => {
const response = await request(app)
.delete(`/api/v1/order/checkout/${orderId}`)
.set('Authorization', `Bearer ${buyerToken}`);

expect(response.statusCode).toEqual(200);
expect(response.body.msg).toEqual('Order canceled successfully');
});

it('should return 404 if order is not found when canceling', async () => {
const nonExistentOrderId = 9999;
const response = await request(app)
.delete(`/api/v1/order/checkout/${nonExistentOrderId}`)
.set('Authorization', `Bearer ${buyerToken}`);

expect(response.statusCode).toEqual(404);
expect(response.body.msg).toEqual('Order not found');
});

it('should return all orders', async () => {
const response = await request(app)
.get('/api/v1/order/checkout')
.set('Authorization', `Bearer ${buyerToken}`);

expect(response.statusCode).toEqual(200);
expect(response.body.orders).toBeDefined();
});
});
Loading

0 comments on commit 73005dc

Please sign in to comment.