From e1bb4872c24795da1855dbfb505a22aa1a77bb85 Mon Sep 17 00:00:00 2001 From: jihwooon Date: Fri, 3 Nov 2023 03:01:29 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B0=B0=EC=86=A1=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=EB=A5=BC=20=EA=B0=80=EC=A7=84=20Delivery=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=EB=A5=BC=20=EC=83=9D=EC=84=B1=ED=95=98=EB=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 배송 정보를 가진 Delivery 객체를 구현했습니다 --- server/src/delivery/domain/delivery.entity.ts | 48 ++++++++++++++ server/src/delivery/domain/delivery.test.ts | 38 +++++++++++ server/src/fixture/deliveryFixture.ts | 63 +++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 server/src/delivery/domain/delivery.entity.ts create mode 100644 server/src/delivery/domain/delivery.test.ts create mode 100644 server/src/fixture/deliveryFixture.ts diff --git a/server/src/delivery/domain/delivery.entity.ts b/server/src/delivery/domain/delivery.entity.ts new file mode 100644 index 0000000..e961fd0 --- /dev/null +++ b/server/src/delivery/domain/delivery.entity.ts @@ -0,0 +1,48 @@ +import { Member } from '../../members/domain/member.entity' + +export class Delivery { + id: number + + deliveryName: string + + deliveryFee: number + + member: Member + + createTime: Date + + updateTime: Date + + createBy: string + + modifiedBy: string + + constructor({ + id = 0, + deliveryName = '', + deliveryFee = 0, + member = new Member({}), + createTime = new Date(), + updateTime = new Date(), + createBy = '', + modifiedBy = '', + }: { + id?: number + deliveryName?: string + deliveryFee?: number + member?: Member + createTime?: Date + updateTime?: Date + createBy?: string + modifiedBy?: string + }) { + this.id = id + this.deliveryName = deliveryName + this.deliveryFee = deliveryFee + this.member = member + this.createTime = createTime + this.updateTime = updateTime + this.createBy = createBy + this.modifiedBy = modifiedBy + } +} diff --git a/server/src/delivery/domain/delivery.test.ts b/server/src/delivery/domain/delivery.test.ts new file mode 100644 index 0000000..b938ead --- /dev/null +++ b/server/src/delivery/domain/delivery.test.ts @@ -0,0 +1,38 @@ +import { userMock } from '../../fixture/memberFixture' +import { Delivery } from './delivery.entity' +import { deliveryMock } from '../../fixture/deliveryFixture' + +describe('Delivery', () => { + let delivery: Delivery + + describe('객체가 주어지면', () => { + beforeEach(() => { + delivery = new Delivery(deliveryMock()) + }) + + it('값을 리턴해야 리턴해야 한다', () => { + expect(delivery.id).toEqual(1) + expect(delivery.deliveryName).toEqual('마포구 물류센터') + expect(delivery.deliveryFee).toEqual(3000) + expect(delivery.member).toEqual(userMock()) + expect(delivery.createTime).toEqual(new Date('2023-08-23T23:10:00.009Z')) + expect(delivery.updateTime).toEqual(new Date('2023-10-01T23:10:00.009Z')) + expect(delivery.createBy).toEqual('생성자') + expect(delivery.modifiedBy).toEqual('수정자') + }) + }) + + describe('객체가 빈 값이 주어지면', () => { + beforeEach(() => { + delivery = new Delivery({}) + }) + + it('default 값을 리턴해야 한다', () => { + expect(delivery.id).toEqual(0) + expect(delivery.deliveryName).toEqual('') + expect(delivery.deliveryFee).toEqual(0) + expect(delivery.createBy).toEqual('') + expect(delivery.modifiedBy).toEqual('') + }) + }) +}) diff --git a/server/src/fixture/deliveryFixture.ts b/server/src/fixture/deliveryFixture.ts new file mode 100644 index 0000000..26fc80b --- /dev/null +++ b/server/src/fixture/deliveryFixture.ts @@ -0,0 +1,63 @@ +import { userMock } from './memberFixture' +import { Delivery } from '../delivery/domain/delivery.entity' + +export const deliveryMock = (): Delivery => { + return { + id: 1, + deliveryName: '마포구 물류센터', + deliveryFee: 3000, + member: userMock(), + createTime: new Date('2023-08-23T23:10:00.009Z'), + updateTime: new Date('2023-10-01T23:10:00.009Z'), + createBy: '생성자', + modifiedBy: '수정자', + } +} + +export const deliveriesMock = (): Delivery[] => { + return [ + { + id: 1, + deliveryName: '마포구 물류센터', + deliveryFee: 3000, + member: userMock(), + createTime: new Date('2023-08-23T23:10:00.009Z'), + updateTime: new Date('2023-10-01T23:10:00.009Z'), + createBy: '생성자', + modifiedBy: '수정자', + }, + { + id: 2, + deliveryName: '동탄 물류센터 무료배송', + deliveryFee: 0, + member: userMock(), + createTime: new Date('2022-10-02T23:10:00.009Z'), + updateTime: new Date('2023-09-01T23:10:00.009Z'), + createBy: '생성자', + modifiedBy: '수정자', + }, + ] +} + +export const dbDeliveriesMock = [ + { + delivery_id: deliveriesMock()[0].id, + delivery_name: deliveriesMock()[0].deliveryName, + delivery_fee: deliveriesMock()[0].deliveryFee, + member_id: userMock().memberId, + create_time: deliveriesMock()[0].createTime, + update_time: deliveriesMock()[0].updateTime, + create_by: deliveriesMock()[0].createBy, + modified_by: deliveriesMock()[0].modifiedBy, + }, + { + delivery_id: deliveriesMock()[1].id, + delivery_name: deliveriesMock()[1].deliveryName, + delivery_fee: deliveriesMock()[1].deliveryFee, + member_id: userMock().memberId, + create_time: deliveriesMock()[1].createTime, + update_time: deliveriesMock()[1].updateTime, + create_by: deliveriesMock()[1].createBy, + modified_by: deliveriesMock()[1].modifiedBy, + }, +]