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 cf89be4
Show file tree
Hide file tree
Showing 33 changed files with 5,425 additions and 3,935 deletions.
8,571 changes: 4,902 additions & 3,669 deletions model.nlp

Large diffs are not rendered by default.

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 cf89be4

Please sign in to comment.