import { OrderItem } from './order-item.model'
import { Order } from './order.model'
describe('Order', () => {
	describe('updateAmounts method', () => {
		it('should correctly calculate total and base amount without tax', () => {
			const items: OrderItem[] = [
				new OrderItem({ unitPrice: 10, quantity: 5 }),
				new OrderItem({ unitPrice: 5, quantity: 2 }),
			]
			const order = new Order({ items, taxPercentage: 0 })
			Order.prototype['updateAmounts'].call(order)
			expect(order.totalAmount).toBe(60)
			expect(order.baseAmount).toBe(60)
		})
		it('should correctly calculate base amount with tax', () => {
			const items: OrderItem[] = [
				new OrderItem({ unitPrice: 10, quantity: 5 }),
				new OrderItem({ unitPrice: 5, quantity: 2 }),
			]
			const order = new Order({ items, taxPercentage: 10 })
			Order.prototype['updateAmounts'].call(order)
			expect(order.baseAmount).toBe(54)
		})
		it('should correctly calculate tax amount', () => {
			const items: OrderItem[] = [
				new OrderItem({ unitPrice: 10, quantity: 5 }),
				new OrderItem({ unitPrice: 5, quantity: 2 }),
			]
			const order = new Order({ items, taxPercentage: 10 })
			Order.prototype['updateAmounts'].call(order)
			expect(order.taxAmount).toBe(6)
		})
		it('should correctly calculate paid amount', () => {
			const items: OrderItem[] = [
				new OrderItem({ unitPrice: 10, quantity: 5, paidQuantity: 3 }),
				new OrderItem({ unitPrice: 5, quantity: 2, paidQuantity: 2 }),
			]
			const order = new Order({ items, taxPercentage: 10 })
			Order.prototype['updateAmounts'].call(order)
			expect(order.paidAmount).toBe(40)
		})
		it('should correctly calculate outstanding amount', () => {
			const items: OrderItem[] = [
				new OrderItem({ unitPrice: 10, quantity: 5, paidQuantity: 3 }),
				new OrderItem({ unitPrice: 5, quantity: 2, paidQuantity: 2 }),
			]
			const order = new Order({ items, taxPercentage: 10 })
			Order.prototype['updateAmounts'].call(order)
			expect(order.outstandingAmount).toBe(20)
		})
		it('should set all amounts to 0 when there are no items', () => {
			const order = new Order({ items: [], taxPercentage: 10 })
			Order.prototype['updateAmounts'].call(order)
			expect(order.totalAmount).toBe(0)
			expect(order.baseAmount).toBe(0)
			expect(order.taxAmount).toBe(0)
			expect(order.paidAmount).toBe(0)
			expect(order.outstandingAmount).toBe(0)
		})
	})
})
