-
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.
- 주문 테스트 데이터 (server/src/fixture/orders.fixture.ts) 를 정리했습니다. - 실제 주문 데이터와 모의 주문 데이터를 구분하기 위해 별도의 배열로 분리했습니다. - 실제 주문 데이터는 orders 배열에, 모의 주문 데이터는 mockOrders 배열에 저장합니다. - 주문 목록 조회 서비스 (server/src/orders/application/orders-list.service.test.ts) 의 테스트 케이스를 작성했습니다. - findAll 함수를 모킹하여 테스트 데이터를 반환하도록 설정했습니다. - 테스트 케이스를 통해 서비스가 주문 목록을 정확하게 조회하는지 확인합니다.
- Loading branch information
Showing
2 changed files
with
101 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Delivery from 'src/delivery/domain/delivery'; | ||
import Order from 'src/orders/domain/order'; | ||
|
||
export const orders = [ | ||
{ | ||
id: 1, | ||
bookTitle: '어린왕자', | ||
totalQuantity: 3, | ||
totalPrice: 6000, | ||
userId: 0, | ||
delivery: { | ||
id: 0, | ||
address: '강원도 춘천시 동내면 대룡산길 227-314 24408 한국', | ||
contact: '010-1234-5667', | ||
receiver: '홍길동', | ||
}, | ||
deliveryId: 0, | ||
createdAt: '2024-03-14T15:59:31.520Z', | ||
}, | ||
{ | ||
id: 2, | ||
bookTitle: '어린왕자', | ||
totalQuantity: 3, | ||
totalPrice: 6000, | ||
userId: 0, | ||
delivery: { | ||
id: 0, | ||
address: '강원도 춘천시 동내면 대룡산길 227-314 24408 한국', | ||
contact: '010-1234-5667', | ||
receiver: '홍길동', | ||
}, | ||
deliveryId: 0, | ||
createdAt: '2024-03-14T15:59:31.520Z', | ||
}, | ||
]; | ||
|
||
export const mockOrders = [ | ||
new Order({ | ||
id: 1, | ||
bookTitle: 'Book 1', | ||
totalQuantity: 2, | ||
totalPrice: 20, | ||
delivery: new Delivery({ | ||
address: '123 Street', | ||
receiver: 'John Doe', | ||
contact: '1234567890', | ||
}), | ||
}), | ||
new Order({ | ||
id: 2, | ||
bookTitle: 'Book 2', | ||
totalQuantity: 1, | ||
totalPrice: 15, | ||
delivery: new Delivery({ | ||
address: '456 Avenue', | ||
receiver: 'Jane Smith', | ||
contact: '9876543210', | ||
}), | ||
}), | ||
]; |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { mockOrders } from 'src/fixture/orders.fixture'; | ||
|
||
import { findAll } from '../domain/order.repository'; | ||
import { getAllOrders } from './orders-list.service'; | ||
|
||
jest.mock('../domain/order.repository.ts'); | ||
|
||
describe('orderList Service', () => { | ||
beforeEach(() => { | ||
(findAll as jest.Mock).mockResolvedValue(mockOrders); | ||
}); | ||
|
||
describe('getAllOrders', () => { | ||
context('주문 목록을 조회하면', () => { | ||
it('주문 목록 리스트를 반환한다.', async () => { | ||
const orders = await getAllOrders(); | ||
|
||
expect(orders).toEqual([ | ||
{ | ||
address: '123 Street', | ||
bookTitle: 'Book 1', | ||
contact: '1234567890', | ||
orderId: 1, | ||
receiver: 'John Doe', | ||
totalPrice: 20, | ||
totalQuantity: 2, | ||
}, | ||
{ | ||
address: '456 Avenue', | ||
bookTitle: 'Book 2', | ||
contact: '9876543210', | ||
orderId: 2, | ||
receiver: 'Jane Smith', | ||
totalPrice: 15, | ||
totalQuantity: 1, | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); | ||
}); |