@@ -22,8 +22,7 @@ describe('IsMenstrualLeaveMonthlyQuotaExceeded', () => {
2222 when ( user . getId ( ) ) . thenReturn ( 'user-123' ) ;
2323 } ) ;
2424
25- it ( 'testQuotaNotExceededWhenNoExistingRequests' , async ( ) => {
26- // No existing menstrual leave requests
25+ it ( 'testQuotaNotExceededWithHalfDay' , async ( ) => {
2726 when (
2827 leaveRequestRepository . findMenstrualLeaveRequestsByUserAndMonth (
2928 'user-123' ,
@@ -32,24 +31,22 @@ describe('IsMenstrualLeaveMonthlyQuotaExceeded', () => {
3231 )
3332 ) . thenResolve ( [ ] ) ;
3433
35- // New request is 1 day (under quota of 2)
3634 when (
37- dateUtils . getLeaveDuration ( '2026-04-10' , true , '2026-04-10' , true )
38- ) . thenReturn ( 1 ) ;
35+ dateUtils . getLeaveDuration ( '2026-04-10' , false , '2026-04-10' , true )
36+ ) . thenReturn ( 0.5 ) ;
3937
4038 const result = await specification . isSatisfiedBy (
4139 instance ( user ) ,
4240 '2026-04-10' ,
43- true ,
41+ false ,
4442 '2026-04-10' ,
4543 true
4644 ) ;
4745
48- expect ( result ) . toBe ( false ) ; // Not exceeded
46+ expect ( result ) . toBe ( false ) ;
4947 } ) ;
5048
5149 it ( 'testQuotaNotExceededAt2Days' , async ( ) => {
52- // 1 existing day of menstrual leave
5350 const existingLeave = mock ( LeaveRequest ) ;
5451 when ( existingLeave . getStartDate ( ) ) . thenReturn ( '2026-04-05' ) ;
5552 when ( existingLeave . isStartsAllDay ( ) ) . thenReturn ( true ) ;
@@ -64,12 +61,10 @@ describe('IsMenstrualLeaveMonthlyQuotaExceeded', () => {
6461 )
6562 ) . thenResolve ( [ instance ( existingLeave ) ] ) ;
6663
67- // Existing request is 1 day
6864 when (
6965 dateUtils . getLeaveDuration ( '2026-04-05' , true , '2026-04-05' , true )
7066 ) . thenReturn ( 1 ) ;
7167
72- // New request is 1 day (total = 2, exactly at quota)
7368 when (
7469 dateUtils . getLeaveDuration ( '2026-04-10' , true , '2026-04-10' , true )
7570 ) . thenReturn ( 1 ) ;
@@ -82,11 +77,10 @@ describe('IsMenstrualLeaveMonthlyQuotaExceeded', () => {
8277 true
8378 ) ;
8479
85- expect ( result ) . toBe ( false ) ; // Not exceeded (2 = quota)
80+ expect ( result ) . toBe ( false ) ;
8681 } ) ;
8782
88- it ( 'testQuotaExceededWhenAddingMoreThan2Days' , async ( ) => {
89- // 1 existing day of menstrual leave
83+ it ( 'testQuotaExceededWith3Days' , async ( ) => {
9084 const existingLeave = mock ( LeaveRequest ) ;
9185 when ( existingLeave . getStartDate ( ) ) . thenReturn ( '2026-04-05' ) ;
9286 when ( existingLeave . isStartsAllDay ( ) ) . thenReturn ( true ) ;
@@ -101,12 +95,10 @@ describe('IsMenstrualLeaveMonthlyQuotaExceeded', () => {
10195 )
10296 ) . thenResolve ( [ instance ( existingLeave ) ] ) ;
10397
104- // Existing request is 1 day
10598 when (
10699 dateUtils . getLeaveDuration ( '2026-04-05' , true , '2026-04-05' , true )
107100 ) . thenReturn ( 1 ) ;
108101
109- // New request is 2 days (total = 3, exceeds quota of 2)
110102 when (
111103 dateUtils . getLeaveDuration ( '2026-04-10' , true , '2026-04-11' , true )
112104 ) . thenReturn ( 2 ) ;
@@ -119,11 +111,10 @@ describe('IsMenstrualLeaveMonthlyQuotaExceeded', () => {
119111 true
120112 ) ;
121113
122- expect ( result ) . toBe ( true ) ; // Exceeded
114+ expect ( result ) . toBe ( true ) ;
123115 } ) ;
124116
125117 it ( 'testQuotaExceededWhenAlready2Days' , async ( ) => {
126- // 2 existing days of menstrual leave
127118 const existingLeave = mock ( LeaveRequest ) ;
128119 when ( existingLeave . getStartDate ( ) ) . thenReturn ( '2026-04-05' ) ;
129120 when ( existingLeave . isStartsAllDay ( ) ) . thenReturn ( true ) ;
@@ -138,12 +129,10 @@ describe('IsMenstrualLeaveMonthlyQuotaExceeded', () => {
138129 )
139130 ) . thenResolve ( [ instance ( existingLeave ) ] ) ;
140131
141- // Existing request is 2 days
142132 when (
143133 dateUtils . getLeaveDuration ( '2026-04-05' , true , '2026-04-06' , true )
144134 ) . thenReturn ( 2 ) ;
145135
146- // New request is 1 day (total = 3, exceeds quota of 2)
147136 when (
148137 dateUtils . getLeaveDuration ( '2026-04-10' , true , '2026-04-10' , true )
149138 ) . thenReturn ( 1 ) ;
@@ -156,12 +145,10 @@ describe('IsMenstrualLeaveMonthlyQuotaExceeded', () => {
156145 true
157146 ) ;
158147
159- expect ( result ) . toBe ( true ) ; // Exceeded
148+ expect ( result ) . toBe ( true ) ;
160149 } ) ;
161150
162- it ( 'testQuotaChecksMultipleMonths' , async ( ) => {
163- // Request spans April and May
164- // Mock April having 1 existing day
151+ it ( 'testMultipleMonthsApril' , async ( ) => {
165152 when (
166153 leaveRequestRepository . findMenstrualLeaveRequestsByUserAndMonth (
167154 'user-123' ,
@@ -171,16 +158,51 @@ describe('IsMenstrualLeaveMonthlyQuotaExceeded', () => {
171158 ) . thenResolve ( [ ] ) ;
172159
173160 when (
174- dateUtils . getLeaveDuration ( '2026-04-01' , true , '2026-04-01' , true )
161+ dateUtils . getLeaveDuration ( '2026-04-10' , true , '2026-04-10' , true )
162+ ) . thenReturn ( 1 ) ;
163+
164+ when (
165+ leaveRequestRepository . findMenstrualLeaveRequestsByUserAndMonth (
166+ 'user-123' ,
167+ 2026 ,
168+ 5
169+ )
170+ ) . thenResolve ( [ ] ) ;
171+
172+ when (
173+ dateUtils . getLeaveDuration ( '2026-05-01' , true , '2026-05-01' , true )
175174 ) . thenReturn ( 0 ) ;
176175
177- // Mock May having 2 existing days (at quota)
176+ const result = await specification . isSatisfiedBy (
177+ instance ( user ) ,
178+ '2026-04-10' ,
179+ true ,
180+ '2026-05-01' ,
181+ true
182+ ) ;
183+
184+ expect ( result ) . toBe ( false ) ;
185+ } ) ;
186+
187+ it ( 'testMultipleMonthsExceeded' , async ( ) => {
178188 const mayLeave = mock ( LeaveRequest ) ;
179189 when ( mayLeave . getStartDate ( ) ) . thenReturn ( '2026-05-05' ) ;
180190 when ( mayLeave . isStartsAllDay ( ) ) . thenReturn ( true ) ;
181191 when ( mayLeave . getEndDate ( ) ) . thenReturn ( '2026-05-06' ) ;
182192 when ( mayLeave . isEndsAllDay ( ) ) . thenReturn ( true ) ;
183193
194+ when (
195+ leaveRequestRepository . findMenstrualLeaveRequestsByUserAndMonth (
196+ 'user-123' ,
197+ 2026 ,
198+ 4
199+ )
200+ ) . thenResolve ( [ ] ) ;
201+
202+ when (
203+ dateUtils . getLeaveDuration ( '2026-04-10' , true , '2026-04-10' , true )
204+ ) . thenReturn ( 0 ) ;
205+
184206 when (
185207 leaveRequestRepository . findMenstrualLeaveRequestsByUserAndMonth (
186208 'user-123' ,
@@ -193,7 +215,6 @@ describe('IsMenstrualLeaveMonthlyQuotaExceeded', () => {
193215 dateUtils . getLeaveDuration ( '2026-05-05' , true , '2026-05-06' , true )
194216 ) . thenReturn ( 2 ) ;
195217
196- // New request is 1 day in May (total May = 3, exceeds quota)
197218 when (
198219 dateUtils . getLeaveDuration ( '2026-05-10' , true , '2026-05-10' , true )
199220 ) . thenReturn ( 1 ) ;
@@ -206,6 +227,6 @@ describe('IsMenstrualLeaveMonthlyQuotaExceeded', () => {
206227 true
207228 ) ;
208229
209- expect ( result ) . toBe ( true ) ; // Exceeded for May
230+ expect ( result ) . toBe ( true ) ;
210231 } ) ;
211232} ) ;
0 commit comments