@things-factory/organization 9.1.19 → 9.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,271 @@
1
+ /**
2
+ * Employee Unit Tests
3
+ * 직원 엔티티 단위 테스트
4
+ */
5
+
6
+ import { TestDatabase } from '../../../../test/test-database'
7
+ import { withTestTransaction } from '../../../../test/test-context'
8
+ import {
9
+ domainFactory,
10
+ userFactory,
11
+ employeeFactory,
12
+ departmentFactory
13
+ } from '../../../../test/factories'
14
+ import { EmployeeType } from '../../../../test/entities/schemas'
15
+
16
+ describe('Employee Entity Tests', () => {
17
+ let testDb: TestDatabase
18
+
19
+ beforeAll(async () => {
20
+ testDb = TestDatabase.getInstance()
21
+ })
22
+
23
+ describe('Employee 생성', () => {
24
+ it('Employee가 올바르게 생성되어야 한다', async () => {
25
+ await withTestTransaction(async (context) => {
26
+ const { tx, domain } = context.state
27
+
28
+ // When
29
+ const employee = await employeeFactory.createWithDomain(
30
+ {
31
+ controlNo: 'EMP-001',
32
+ name: 'John Doe',
33
+ jobPosition: 'Engineer',
34
+ type: EmployeeType.FULLTIME
35
+ },
36
+ domain,
37
+ tx
38
+ )
39
+
40
+ // Then
41
+ expect(employee).toBeDefined()
42
+ expect(employee.id).toBeDefined()
43
+ expect(employee.controlNo).toBe('EMP-001')
44
+ expect(employee.name).toBe('John Doe')
45
+ expect(employee.jobPosition).toBe('Engineer')
46
+ expect(employee.type).toBe(EmployeeType.FULLTIME)
47
+ expect(employee.domain?.id).toBe(domain.id)
48
+ })
49
+ })
50
+
51
+ it('controlNo는 필수 필드여야 한다', async () => {
52
+ await withTestTransaction(async (context) => {
53
+ const { tx, domain } = context.state
54
+
55
+ // When
56
+ const employee = await employeeFactory.createWithDomain(
57
+ { controlNo: 'REQUIRED-001' },
58
+ domain,
59
+ tx
60
+ )
61
+
62
+ // Then
63
+ expect(employee.controlNo).toBe('REQUIRED-001')
64
+ })
65
+ })
66
+
67
+ it('다양한 EmployeeType이 지원되어야 한다', async () => {
68
+ await withTestTransaction(async (context) => {
69
+ const { tx, domain } = context.state
70
+
71
+ // When: FULLTIME
72
+ const fulltime = await employeeFactory.createWithDomain(
73
+ { type: EmployeeType.FULLTIME },
74
+ domain,
75
+ tx
76
+ )
77
+
78
+ // When: PARTTIME
79
+ const parttime = await employeeFactory.createWithDomain(
80
+ { type: EmployeeType.PARTTIME },
81
+ domain,
82
+ tx
83
+ )
84
+
85
+ // When: TEMPORARY
86
+ const temporary = await employeeFactory.createWithDomain(
87
+ { type: EmployeeType.TEMPORARY },
88
+ domain,
89
+ tx
90
+ )
91
+
92
+ // Then
93
+ expect(fulltime.type).toBe(EmployeeType.FULLTIME)
94
+ expect(parttime.type).toBe(EmployeeType.PARTTIME)
95
+ expect(temporary.type).toBe(EmployeeType.TEMPORARY)
96
+ })
97
+ })
98
+ })
99
+
100
+ describe('Employee-User 연결', () => {
101
+ it('Employee와 User가 연결될 수 있어야 한다', async () => {
102
+ await withTestTransaction(async (context) => {
103
+ const { tx, domain, user } = context.state
104
+
105
+ // When
106
+ const employee = await employeeFactory.createWithUser({}, user, domain, tx)
107
+
108
+ // Then
109
+ expect(employee.user?.id).toBe(user.id)
110
+ })
111
+ })
112
+
113
+ it('User 없이도 Employee 생성이 가능해야 한다', async () => {
114
+ await withTestTransaction(async (context) => {
115
+ const { tx, domain } = context.state
116
+
117
+ // When
118
+ const employee = await employeeFactory.createWithDomain({}, domain, tx)
119
+
120
+ // Then
121
+ expect(employee).toBeDefined()
122
+ expect(employee.user).toBeUndefined()
123
+ })
124
+ })
125
+ })
126
+
127
+ describe('Employee-Department 관계', () => {
128
+ it('Employee가 Department에 속할 수 있어야 한다', async () => {
129
+ await withTestTransaction(async (context) => {
130
+ const { tx, domain } = context.state
131
+
132
+ // Given
133
+ const department = await departmentFactory.createWithDomain(
134
+ { name: 'Engineering' },
135
+ domain,
136
+ tx
137
+ )
138
+
139
+ // When
140
+ const employee = await employeeFactory.createWithDepartment({}, department, tx)
141
+
142
+ // Then
143
+ expect(employee.department?.id).toBe(department.id)
144
+ })
145
+ })
146
+ })
147
+
148
+ describe('Supervisor 관계', () => {
149
+ it('Employee에게 Supervisor를 설정할 수 있어야 한다', async () => {
150
+ await withTestTransaction(async (context) => {
151
+ const { tx, domain } = context.state
152
+
153
+ // Given
154
+ const supervisor = await employeeFactory.createManager({}, domain, tx)
155
+
156
+ // When
157
+ const employee = await employeeFactory.createWithSupervisor({}, supervisor, tx)
158
+
159
+ // Then
160
+ expect(employee.supervisor?.id).toBe(supervisor.id)
161
+ })
162
+ })
163
+
164
+ it('조직 구조가 올바르게 생성되어야 한다', async () => {
165
+ await withTestTransaction(async (context) => {
166
+ const { tx, domain } = context.state
167
+
168
+ // When
169
+ const { manager, employees, department } = await employeeFactory.createOrganizationStructure(
170
+ domain,
171
+ tx
172
+ )
173
+
174
+ // Then
175
+ expect(manager).toBeDefined()
176
+ expect(manager.jobPosition).toBe('Manager')
177
+ expect(employees.length).toBe(3)
178
+ employees.forEach(emp => {
179
+ expect(emp.supervisor?.id).toBe(manager.id)
180
+ })
181
+ })
182
+ })
183
+ })
184
+
185
+ describe('Employee 속성', () => {
186
+ it('입사일/퇴사일이 설정될 수 있어야 한다', async () => {
187
+ await withTestTransaction(async (context) => {
188
+ const { tx, domain } = context.state
189
+
190
+ // Given
191
+ const hiredOn = new Date('2020-01-15')
192
+ const retiredOn = new Date('2024-12-31')
193
+
194
+ // When
195
+ const employee = await employeeFactory.createWithDomain(
196
+ { hiredOn, retiredOn },
197
+ domain,
198
+ tx
199
+ )
200
+
201
+ // Then
202
+ expect(employee.hiredOn).toEqual(hiredOn)
203
+ expect(employee.retiredOn).toEqual(retiredOn)
204
+ })
205
+ })
206
+
207
+ it('비상연락처 정보가 저장되어야 한다', async () => {
208
+ await withTestTransaction(async (context) => {
209
+ const { tx, domain } = context.state
210
+
211
+ // When
212
+ const employee = await employeeFactory.createWithDomain(
213
+ {
214
+ emergencyContact: 'Jane Doe',
215
+ emergencyContactPhone: '010-1234-5678'
216
+ },
217
+ domain,
218
+ tx
219
+ )
220
+
221
+ // Then
222
+ expect(employee.emergencyContact).toBe('Jane Doe')
223
+ expect(employee.emergencyContactPhone).toBe('010-1234-5678')
224
+ })
225
+ })
226
+
227
+ it('급여 계좌 정보가 저장되어야 한다', async () => {
228
+ await withTestTransaction(async (context) => {
229
+ const { tx, domain } = context.state
230
+
231
+ // When
232
+ const employee = await employeeFactory.createWithDomain(
233
+ {
234
+ bankName: 'KB Bank',
235
+ bankAccount: '123-456-789012'
236
+ },
237
+ domain,
238
+ tx
239
+ )
240
+
241
+ // Then
242
+ expect(employee.bankName).toBe('KB Bank')
243
+ expect(employee.bankAccount).toBe('123-456-789012')
244
+ })
245
+ })
246
+
247
+ it('active 상태가 관리되어야 한다', async () => {
248
+ await withTestTransaction(async (context) => {
249
+ const { tx, domain } = context.state
250
+
251
+ // When: active=true
252
+ const activeEmployee = await employeeFactory.createWithDomain(
253
+ { active: true },
254
+ domain,
255
+ tx
256
+ )
257
+
258
+ // When: active=false (퇴사자)
259
+ const inactiveEmployee = await employeeFactory.createWithDomain(
260
+ { active: false },
261
+ domain,
262
+ tx
263
+ )
264
+
265
+ // Then
266
+ expect(activeEmployee.active).toBe(true)
267
+ expect(inactiveEmployee.active).toBe(false)
268
+ })
269
+ })
270
+ })
271
+ })