From 2c3b0602f346e6be54cf5a4b13e240809b1509ae Mon Sep 17 00:00:00 2001 From: jihwooon Date: Fri, 15 Mar 2024 08:54:37 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A3=BC=EB=AC=B8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=B0=8F=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 주문 테스트 데이터 (server/src/fixture/orders.fixture.ts) 를 정리했습니다. - 실제 주문 데이터와 모의 주문 데이터를 구분하기 위해 별도의 배열로 분리했습니다. - 실제 주문 데이터는 orders 배열에, 모의 주문 데이터는 mockOrders 배열에 저장합니다. - 주문 목록 조회 서비스 (server/src/orders/application/orders-list.service.test.ts) 의 테스트 케이스를 작성했습니다. - findAll 함수를 모킹하여 테스트 데이터를 반환하도록 설정했습니다. - 테스트 케이스를 통해 서비스가 주문 목록을 정확하게 조회하는지 확인합니다. --- server/src/fixture/orders.fixture.ts | 60 +++++++++++++++++++ .../application/orders-list.service.test.ts | 41 +++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 server/src/fixture/orders.fixture.ts create mode 100644 server/src/orders/application/orders-list.service.test.ts diff --git a/server/src/fixture/orders.fixture.ts b/server/src/fixture/orders.fixture.ts new file mode 100644 index 0000000..b506f0c --- /dev/null +++ b/server/src/fixture/orders.fixture.ts @@ -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', + }), + }), +]; diff --git a/server/src/orders/application/orders-list.service.test.ts b/server/src/orders/application/orders-list.service.test.ts new file mode 100644 index 0000000..8e8b38a --- /dev/null +++ b/server/src/orders/application/orders-list.service.test.ts @@ -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, + }, + ]); + }); + }); + }); +});