-
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.
feat: implement update method in repository order
- Loading branch information
1 parent
5264a21
commit 30833c7
Showing
4 changed files
with
278 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,76 @@ | ||
import { Customer } from './customer' | ||
import { Order } from './order' | ||
import { OrderItem } from './order-item' | ||
|
||
describe('Order unit tests', () => { | ||
it('should throw error when id is empty', () => { | ||
expect(() => { | ||
const order = new Order('', '123', []) | ||
const order = new Order('', 'c1', []) | ||
}).toThrowError('id is required') | ||
}) | ||
|
||
it('should throw error when customerId is empty', () => { | ||
expect(() => { | ||
const order = new Order('123', '', []) | ||
const order = new Order('o1', '', []) | ||
}).toThrowError('customerId is required') | ||
}) | ||
|
||
it('should throw error when customerId is empty', () => { | ||
expect(() => { | ||
const order = new Order('123', '123', []) | ||
}).toThrowError('item qtd mus be greater than 0') | ||
const order = new Order('o1', 'c1', []) | ||
}).toThrowError('item qtd must be greater than 0') | ||
}) | ||
|
||
it('should calculate total', () => { | ||
const item1 = new OrderItem('123', 'product1', 100, '1', 2) | ||
const item2 = new OrderItem('123', 'product2', 200, '2', 2) | ||
const order = new Order('123', '123', [item1, item2]) | ||
const item1 = new OrderItem('i1', 'product1', 100, '1', 2) | ||
const item2 = new OrderItem('i2', 'product2', 200, '2', 2) | ||
const order = new Order('o1', 'c1', [item1, item2]) | ||
expect(order.total()).toBe(600) | ||
}) | ||
|
||
it('should check if the item qtd is less or equal 0', () => { | ||
expect(() => { | ||
const item = new OrderItem('123', 'product1', 100, '1', 0) | ||
const order = new Order('123', '123', [item]) | ||
const item = new OrderItem('i1', 'product1', 100, '1', 0) | ||
const order = new Order('o1', 'c1', [item]) | ||
}).toThrowError('item quantity must be greater than 0') | ||
}) | ||
|
||
it('should change customer', () => { | ||
const item1 = new OrderItem('123', 'product1', 100, '1', 2) | ||
const order = new Order('o1', 'c1', [item1]) | ||
expect(order.customerId).toBe('c1') | ||
|
||
order.changeCustomer('c2') | ||
expect(order.customerId).toBe('c2') | ||
}) | ||
|
||
it('should add new item', () => { | ||
const item1 = new OrderItem('123', 'product1', 100, '1', 2) | ||
const order = new Order('o1', 'c1', [item1]) | ||
expect(order.items.length).toBe(1) | ||
|
||
const item2 = new OrderItem('i2', 'product2', 200, '2', 2) | ||
order.addItem(item2) | ||
expect(order.items.length).toBe(2) | ||
}) | ||
|
||
it('should remove item', () => { | ||
const item1 = new OrderItem('123', 'product1', 100, '1', 2) | ||
const item2 = new OrderItem('i2', 'product2', 200, '2', 2) | ||
const order = new Order('o1', 'c1', [item1, item2]) | ||
expect(order.items.length).toBe(2) | ||
|
||
order.removeItem(item1.id) | ||
expect(order.items.length).toBe(1) | ||
}) | ||
|
||
it('should throw error if remove all items', () => { | ||
const item1 = new OrderItem('123', 'product1', 100, '1', 2) | ||
const order = new Order('o1', 'c1', [item1]) | ||
expect(order.items.length).toBe(1) | ||
|
||
expect(() => { | ||
order.removeItem(item1.id) | ||
}).toThrowError('item qtd must be greater than 0') | ||
}) | ||
}) |
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
Oops, something went wrong.