Skip to content

Commit

Permalink
배송 정보를 가진 Delivery 객체를 생성하라
Browse files Browse the repository at this point in the history
배송 정보를 가진 Delivery 객체를 구현했습니다
  • Loading branch information
jihwooon committed Nov 3, 2023
1 parent 807333c commit e1bb487
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
48 changes: 48 additions & 0 deletions server/src/delivery/domain/delivery.entity.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
38 changes: 38 additions & 0 deletions server/src/delivery/domain/delivery.test.ts
Original file line number Diff line number Diff line change
@@ -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('')
})
})
})
63 changes: 63 additions & 0 deletions server/src/fixture/deliveryFixture.ts
Original file line number Diff line number Diff line change
@@ -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,
},
]

0 comments on commit e1bb487

Please sign in to comment.