Skip to content

Commit

Permalink
Conflift resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Ndevu12 committed Jun 6, 2024
2 parents 0fee7ef + d8eed35 commit c3163e7
Show file tree
Hide file tree
Showing 35 changed files with 477 additions and 214 deletions.
10 changes: 0 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,3 @@ coverage/
dist
/src/logs
.DS_Store

src/controllers/notificationControllers.ts
src/entities/Notification.ts
src/entities/NotificationItem.ts
src/routes/NoficationRoutes.ts
src/services/notificationServices/deleteNotification.ts
src/services/notificationServices/getNotifications.ts
src/services/notificationServices/updateNotification.ts
src/utils/getNotifications.ts
src/utils/sendNotification.ts
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@
"express-session": "^1.18.0",
"express-winston": "^4.2.0",
"highlight.js": "^11.9.0",
"joi": "^17.13.1",
"jsend": "^1.1.0",
"jsonwebtoken": "^9.0.2",
"mailgen": "^2.0.28",
"morgan": "^1.10.0",
"multer": "^1.4.5-lts.1",
"node-nlp": "^4.27.0",
"node-nlp": "^3.10.2",
"nodemailer": "^6.9.13",
"nodemon": "^3.1.0",
"passport": "^0.7.0",
Expand Down Expand Up @@ -96,6 +95,7 @@
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"jest-mock-extended": "^3.0.6",
"joi": "^17.13.1",
"prettier": "^3.2.5",
"supertest": "^7.0.0",
"ts-jest": "^29.1.2",
Expand Down
4 changes: 2 additions & 2 deletions src/__test__/cart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +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(404);
expect(response.status).toBe(200);
});

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(404);
expect(response.status).toBe(400);
});

it('should return 404 if the buyer has no orders', async () => {
Expand Down
107 changes: 91 additions & 16 deletions src/__test__/getProduct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const sampleBuyer1: UserInterface = {
phoneNumber: '000380996348',
photoUrl: 'https://example.com/photo.jpg',
role: 'BUYER',

};

const sampleCat = {
Expand All @@ -67,15 +68,20 @@ const sampleProduct1 = {
vendor: sampleVendor1,
categories: [sampleCat],
};
let cardID : string;
const bodyTosend = {
productId: product1Id,
quantity: 2,
};

let cardID: string;
beforeAll(async () => {
const connection = await dbConnection();

const categoryRepository = connection?.getRepository(Category);
await categoryRepository?.save({ ...sampleCat });

const userRepository = connection?.getRepository(User);
await userRepository?.save({ ...sampleVendor1});
await userRepository?.save({ ...sampleVendor1 });
await userRepository?.save({ ...sampleBuyer1 });

const productRepository = connection?.getRepository(Product);
Expand Down Expand Up @@ -104,7 +110,7 @@ describe('Creating new product', () => {

expect(response.status).toBe(201);
expect(response.body.data.product).toBeDefined;
}, 60000);
}, 20000);
});
describe('Get single product', () => {
it('should get a single product', async () => {
Expand Down Expand Up @@ -136,23 +142,92 @@ describe('Get single product', () => {
expect(response.body.message).toBe('Product not found');
}, 10000);
});
describe('Cart Order and payment functionalities', () => {
it('should create a cart for a product', async () => {
const productId = product1Id;
const quantity = 8;

const token = getAccessToken(BuyerID, sampleBuyer1.email);
describe('POST /confirm-payment', () => {

it('should add product to cart as authenticated buyer', async () => {
const response = await request(app)
.post('/cart')
.set('Authorization', `Bearer ${token}`)
.send({ productId, quantity });
.post(`/cart`)
.send(bodyTosend)
.set('Authorization', `Bearer ${getAccessToken(BuyerID, sampleBuyer1.email)}`);

expect(response.status).toBe(201);
expect(response.body.data.message).toBe('cart updated successfully');
expect(response.body.data.cart).toBeDefined;


expect(response.status).toBe(201);
expect(response.body.data.cart).toBeDefined();
cardID = JSON.stringify(response.body.data.cart.id)
});

it('should create an order successfully', async () => {
const address = {
country: 'Test Country',
city: 'Test City',
street: 'Test Street',
};


const response = await request(app)
.post('/product/orders')
.set('Authorization', `Bearer ${getAccessToken(BuyerID, sampleBuyer1.email)}`)
.send({ address });

console.log(response.body.message)
expect(response.status).toBe(201);
expect(response.body.message).toBe('Order created successfully');
expect(response.body.data).toBeDefined();

});
it('should confirm payment successfully', async () => {
const token = 'your_valid_access_token_here';


const response = await request(app)
.post(`/product/payment/${cardID}`)
.set('Authorization', `Bearer ${getAccessToken(BuyerID, sampleBuyer1.email)}`)
.send({ payment_method: "pm_card_visa" });

expect(response.status).toBe(200);
expect(response.body.message).toBe('Payment successful!');
});

it('should handle cart not found', async () => {

const response = await request(app)
.post(`/product/payment/wkowkokfowkf`)
.set('Authorization', `Bearer ${getAccessToken(BuyerID, sampleBuyer1.email)}`)
.send({ payment_method: "pm_card_visa" });

expect(response.status).toBe(200);

});
}
)
)
describe('GET / product search', () => {

it('should return a 400 error if no name is provided', async () => {
const response = await request(app)
.get(`/product/search/`)
.query({ name: '' });

expect(response.status).toBe(400);
expect(response.body.error).toBe('Please provide a search term');
}, 10000);

it('should return products if name is provided', async () => {
const response = await request(app)
.get('/product/search')
.query({ name: 'test product3' });

expect(response.status).toBe(200);
expect(response.body.data).toBeDefined();
expect(response.body.pagination).toBeDefined();
});

it('should return a 404 error if no products are found', async () => {
const response = await request(app)
.get('/product/search')
.query({ name: 'nonexistentproduct' });

expect(response.status).toBe(404);
expect(response.body.error).toBe('No products found');
});
})
3 changes: 1 addition & 2 deletions src/__test__/roleCheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { dbConnection } from '../startups/dbConnection';
import { v4 as uuid } from 'uuid';
import { getConnection } from 'typeorm';
import { cleanDatabase } from './test-assets/DatabaseCleanup';
import { server } from '..';


let reqMock: Partial<Request>;
let resMock: Partial<Response>;
Expand Down Expand Up @@ -37,7 +37,6 @@ beforeAll(async () => {

afterAll(async () => {
await cleanDatabase();
server.close();
});

describe('hasRole MiddleWare Test', () => {
Expand Down
Loading

0 comments on commit c3163e7

Please sign in to comment.