@@ -299,25 +299,26 @@ class HistoryLogServiceSpec extends Specification {
299
299
result == 100
300
300
}
301
301
302
- def " countRemainingForCurrentYear WHEN log without request from prev year but countedOnNext SHOULD be added" (){
302
+ def " countRemainingForCurrentYear WHEN log without request from prev year SHOULD be added" (){
303
303
given :
304
304
def log = Mock (HistoryLog ){
305
305
getHours() >> 100
306
306
}
307
307
def log2 = Mock (HistoryLog ) {
308
308
getHours() >> -20
309
+ getCreated() >> LocalDateTime . of(1 ,1 ,1 ,1 ,1 ,1 )
309
310
}
310
311
historyLogRepository. findAll(_ as Filter ) >>> [[log], [log2], []]
311
312
312
313
when :
313
- def result = historyLogService. countRemainingForCurrentYear(1 ,1 )
314
+ def result = historyLogService. countRemainingForCurrentYear(1 ,2 )
314
315
315
316
then :
316
317
result == 80
317
318
}
318
319
319
320
320
- def " countRemainingForCurrentYear WHEN remaining from prev year SHOULD be added" (){
321
+ def " countRemainingForCurrentYear WHEN remaining from prev year from accepted request SHOULD be added" (){
321
322
given :
322
323
def log = Mock (HistoryLog ){
323
324
getHours() >> 100
@@ -328,9 +329,10 @@ class HistoryLogServiceSpec extends Specification {
328
329
isNormal() >> true
329
330
getEndDate() >> LocalDate . MAX
330
331
getStartDate() >> LocalDate . of(2022 ,12 ,1 )
332
+ getStatus() >> Request.Status . ACCEPTED
331
333
}
332
334
}
333
- historyLogRepository. findAll(_ as Filter ) >>> [[log], [], [log2 ]]
335
+ historyLogRepository. findAll(_ as Filter ) >>> [[log], [log2 ], []]
334
336
usedHoursFromMonthCalculator. countUsedHours(_ as Integer , _ as Integer , _ as HistoryLog ) >> 20
335
337
336
338
when :
@@ -340,6 +342,77 @@ class HistoryLogServiceSpec extends Specification {
340
342
result == 80
341
343
}
342
344
345
+ def " countRemainingForCurrentYear WHEN remaining from prev year from not accepted request SHOULD not be added" (){
346
+ given :
347
+ def log = Mock (HistoryLog ){
348
+ getHours() >> 100
349
+ }
350
+ def log2 = Mock (HistoryLog ) {
351
+ getHours() >> -20
352
+ getRequest() >> Mock (Request ) {
353
+ isNormal() >> true
354
+ getEndDate() >> LocalDate . MAX
355
+ getStartDate() >> LocalDate . of(2022 ,12 ,1 )
356
+ getStatus() >> status
357
+ }
358
+ }
359
+ historyLogRepository. findAll(_ as Filter ) >>> [[log], [log2], []]
360
+ usedHoursFromMonthCalculator. countUsedHours(_ as Integer , _ as Integer , _ as HistoryLog ) >> 20
361
+
362
+ when :
363
+ def result = historyLogService. countRemainingForCurrentYear(1 ,1 )
364
+
365
+ then :
366
+ result == 100
367
+
368
+ where :
369
+ status << [Request.Status . CANCELED , Request.Status . PENDING , Request.Status . REJECTED ]
370
+ }
371
+
372
+ def " countRemainingForCurrentYear WHEN remaining from prev year without request SHOULD be added" (){
373
+ given :
374
+ def log = Mock (HistoryLog ){
375
+ getHours() >> 100
376
+ }
377
+ def log2 = Mock (HistoryLog ) {
378
+ getHours() >> -20
379
+ getCreated() >> LocalDateTime . of(1 ,1 ,1 ,1 ,1 ,1 )
380
+ }
381
+ historyLogRepository. findAll(_ as Filter ) >>> [[log], [log2], []]
382
+ usedHoursFromMonthCalculator. countUsedHours(_ as Integer , _ as Integer , _ as HistoryLog ) >> 20
383
+
384
+ when :
385
+ def result = historyLogService. countRemainingForCurrentYear(1 ,2 )
386
+
387
+ then :
388
+ result == 80
389
+ }
390
+
391
+ def " countRemainingForCurrentYear WHEN remaining from prev year with special request SHOULD not be added" (){
392
+ given :
393
+ def log = Mock (HistoryLog ){
394
+ getHours() >> 100
395
+ }
396
+ def log2 = Mock (HistoryLog ) {
397
+ getHours() >> -20
398
+ getCreated() >> LocalDateTime . of(1 ,1 ,1 ,1 ,1 ,1 )
399
+ getRequest() >> Mock (Request ) {
400
+ isNormal() >> false
401
+ getEndDate() >> LocalDate . MAX
402
+ getStartDate() >> LocalDate . of(2022 ,12 ,1 )
403
+ getStatus() >> Request.Status . ACCEPTED
404
+ }
405
+ }
406
+ historyLogRepository. findAll(_ as Filter ) >>> [[log], [log2], []]
407
+ usedHoursFromMonthCalculator. countUsedHours(_ as Integer , _ as Integer , _ as HistoryLog ) >> 20
408
+
409
+ when :
410
+ def result = historyLogService. countRemainingForCurrentYear(1 ,2 )
411
+
412
+ then :
413
+ result == 100
414
+ }
415
+
343
416
344
417
345
418
def " countRemainingForCurrentYear WHEN no logs SHOULD return 0" (){
0 commit comments