-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:atlp-rwanda/knights-ecomm-be int…
…o ft-coverage
- Loading branch information
Showing
18 changed files
with
354 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -608,4 +608,4 @@ describe('Order management tests', () => { | |
expect(response.status).toBe(500); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,11 @@ import { User, UserInterface } from '../entities/User'; | |
import { v4 as uuid } from 'uuid'; | ||
import { Product } from '../entities/Product'; | ||
import { Category } from '../entities/Category'; | ||
import { Cart } from '../entities/Cart'; | ||
import { cleanDatabase } from './test-assets/DatabaseCleanup'; | ||
|
||
const vendor1Id = uuid(); | ||
const BuyerID = uuid(); | ||
const product1Id = uuid(); | ||
const Invalidproduct = '11278df2-d026-457a-9471-4749f038df68'; | ||
const catId = uuid(); | ||
|
@@ -37,6 +39,18 @@ const sampleVendor1: UserInterface = { | |
photoUrl: 'https://example.com/photo.jpg', | ||
role: 'VENDOR', | ||
}; | ||
const sampleBuyer1: UserInterface = { | ||
id: BuyerID, | ||
firstName: 'vendor1o', | ||
lastName: 'user', | ||
email: '[email protected]', | ||
password: 'password', | ||
userType: 'Vendor', | ||
gender: 'Male', | ||
phoneNumber: '000380996348', | ||
photoUrl: 'https://example.com/photo.jpg', | ||
role: 'BUYER', | ||
}; | ||
|
||
const sampleCat = { | ||
id: catId, | ||
|
@@ -53,23 +67,23 @@ const sampleProduct1 = { | |
vendor: sampleVendor1, | ||
categories: [sampleCat], | ||
}; | ||
|
||
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); | ||
await productRepository?.save({ ...sampleProduct1 }); | ||
}); | ||
|
||
afterAll(async () => { | ||
await cleanDatabase(); | ||
|
||
server.close(); | ||
}); | ||
|
||
|
@@ -122,3 +136,23 @@ 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); | ||
|
||
const response = await request(app) | ||
.post('/cart') | ||
.set('Authorization', `Bearer ${token}`) | ||
.send({ productId, quantity }); | ||
|
||
|
||
expect(response.status).toBe(201); | ||
expect(response.body.data.cart).toBeDefined(); | ||
cardID = JSON.stringify(response.body.data.cart.id) | ||
}); | ||
|
||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,45 +9,108 @@ import { Coupon } from '../entities/coupon'; | |
import { Transaction } from '../entities/transaction'; | ||
import { VendorOrderItem } from '../entities/VendorOrderItem'; | ||
import { VendorOrders } from '../entities/vendorOrders'; | ||
|
||
describe('Product Entity', () => { | ||
let productRepository: Repository<Product>; | ||
let userRepository: Repository<User>; | ||
let categoryRepository: Repository<Category>; | ||
let couponRepository: Repository<Coupon>; | ||
|
||
beforeAll(async () => { | ||
const connection = await createConnection({ | ||
type: 'postgres', | ||
host: 'localhost', | ||
port: 5432, | ||
username: 'postgres', | ||
password: 'ndevu', | ||
database: 'test', | ||
entities: [Product, User, Category, Transaction, VendorOrders, VendorOrderItem, Order, OrderItem, Coupon], | ||
synchronize: true, | ||
dropSchema: true, | ||
}); | ||
|
||
productRepository = connection.getRepository(Product); | ||
userRepository = connection.getRepository(User); | ||
categoryRepository = connection.getRepository(Category); | ||
couponRepository = connection.getRepository(Coupon); | ||
import { v4 as uuid } from 'uuid'; | ||
import { cleanDatabase } from './test-assets/DatabaseCleanup'; | ||
|
||
const vendor3Id = uuid(); | ||
const product1Id = uuid(); | ||
const product2Id = uuid(); | ||
const couponCode1 = 'DISCOUNT10'; | ||
const couponCode2 = 'DISCOUNT10'; | ||
|
||
const sampleVendor3 = new User(); | ||
sampleVendor3.id = vendor3Id; | ||
sampleVendor3.firstName = 'vendor3 ddss'; | ||
sampleVendor3.lastName = 'user'; | ||
sampleVendor3.email = '[email protected]'; | ||
sampleVendor3.password = 'password'; | ||
sampleVendor3.userType = 'Vendor'; | ||
sampleVendor3.gender = 'Male'; | ||
sampleVendor3.phoneNumber = '1638099634'; | ||
sampleVendor3.photoUrl = 'https://example.com/photo.jpg'; | ||
sampleVendor3.role = 'VENDOR'; | ||
|
||
const sampleProduct1 = new Product(); | ||
sampleProduct1.id = product2Id; | ||
sampleProduct1.name = 'Test Product'; | ||
sampleProduct1.description = 'Amazing product'; | ||
sampleProduct1.images = ['photo1.jpg', 'photo2.jpg', 'photo3.jpg']; | ||
sampleProduct1.newPrice = 200; | ||
sampleProduct1.quantity = 10; | ||
sampleProduct1.vendor = sampleVendor3 as User; | ||
|
||
const sampleProduct2 = new Product(); | ||
sampleProduct1.id = product1Id; | ||
sampleProduct1.name = 'Test Product'; | ||
sampleProduct1.description = 'Hello Amazing product'; | ||
sampleProduct1.images = ['photo1.jpg', 'photo2.jpg', 'photo3.jpg']; | ||
sampleProduct1.newPrice = 200; | ||
sampleProduct1.quantity = 10; | ||
sampleProduct1.vendor = sampleVendor3 as User; | ||
|
||
const sampleCoupon1 = new Coupon(); | ||
sampleCoupon1.code = couponCode1; | ||
sampleCoupon1.discountRate = 20; | ||
sampleCoupon1.expirationDate = new Date('2025-01-01'); | ||
sampleCoupon1.maxUsageLimit = 100; | ||
sampleCoupon1.discountType = 'percentage'; | ||
sampleCoupon1.product = sampleProduct1; | ||
sampleCoupon1.vendor = sampleVendor3 as User; | ||
|
||
const sampleCoupon2 = new Coupon(); | ||
sampleCoupon1.code = couponCode2; | ||
sampleCoupon1.discountRate = 20; | ||
sampleCoupon1.expirationDate = new Date('2025-01-01'); | ||
sampleCoupon1.maxUsageLimit = 100; | ||
sampleCoupon1.discountType = 'percentage'; | ||
sampleCoupon1.product = sampleProduct1; | ||
sampleCoupon1.vendor = sampleVendor3 as User; | ||
|
||
|
||
let productRepository: Repository<Product>; | ||
let userRepository: Repository<User>; | ||
let categoryRepository: Repository<Category>; | ||
let couponRepository: Repository<Coupon>; | ||
|
||
beforeAll(async () => { | ||
const connection = await createConnection({ | ||
type: 'postgres', | ||
host: 'localhost', | ||
port: 5432, | ||
username: 'postgres', | ||
password: 'ndevu', | ||
database: 'test', | ||
entities: [Product, User, Category, Transaction, VendorOrders, VendorOrderItem, Order, OrderItem, Coupon], | ||
synchronize: true, | ||
dropSchema: true, | ||
}); | ||
|
||
afterAll(async () => { | ||
await getConnection().close(); | ||
}); | ||
productRepository = connection.getRepository(Product); | ||
userRepository = connection.getRepository(User); | ||
categoryRepository = connection.getRepository(Category); | ||
couponRepository = connection.getRepository(Coupon); | ||
}); | ||
|
||
afterAll(async () => { | ||
await cleanDatabase(); | ||
await getConnection().close(); | ||
}); | ||
|
||
describe('Product Entity', async () => { | ||
it('should create a all enties related to product entity', async () => { | ||
await productRepository.save(sampleProduct2); | ||
}); | ||
|
||
it('should validate a valid product', async () => { | ||
const user = userRepository.create({ /* ...user data... */ }); | ||
const user = userRepository.create(sampleVendor3); | ||
await userRepository.save(user); | ||
|
||
const category = categoryRepository.create({ /* ...category data... */ }); | ||
const category = categoryRepository.create({ | ||
name: "ProductCategory", | ||
}); | ||
await categoryRepository.save(category); | ||
|
||
const coupon = couponRepository.create({ /* ...coupon data... */ }); | ||
const coupon = couponRepository.create(sampleCoupon1); | ||
await couponRepository.save(coupon); | ||
|
||
const product = productRepository.create({ | ||
|
@@ -79,14 +142,14 @@ describe('Product Entity', () => { | |
}); | ||
|
||
it('should enforce array constraints on images', async () => { | ||
const user = userRepository.create({ /* ...user data... */ }); | ||
const user = userRepository.create(sampleVendor3); | ||
await userRepository.save(user); | ||
|
||
const product = productRepository.create({ | ||
vendor: user, | ||
name: 'Sample Product', | ||
description: 'This is a sample product', | ||
images: [], | ||
images: [], | ||
newPrice: 100.0, | ||
quantity: 10, | ||
isAvailable: true, | ||
|
@@ -98,14 +161,18 @@ describe('Product Entity', () => { | |
}); | ||
|
||
it('should handle relationships correctly', async () => { | ||
const user = userRepository.create({ /* ...user data... */ }); | ||
const user = userRepository.create(sampleVendor3); | ||
await userRepository.save(user); | ||
|
||
const category1 = categoryRepository.create({ /* ...category data... */ }); | ||
const category2 = categoryRepository.create({ /* ...category data... */ }); | ||
const category1 = categoryRepository.create({ | ||
name: "ProductCategory1", | ||
}); | ||
const category2 = categoryRepository.create({ | ||
name: "ProductCategory2", | ||
}); | ||
await categoryRepository.save([category1, category2]); | ||
|
||
const coupon = couponRepository.create({ /* ...coupon data... */ }); | ||
const coupon = couponRepository.create(sampleCoupon2); | ||
await couponRepository.save(coupon); | ||
|
||
const product = productRepository.create({ | ||
|
Oops, something went wrong.