11/* eslint-disable import/no-named-as-default-member */
2+ import addDays from 'date-fns/addDays' ;
23import i18n from 'i18next' ;
34
45import {
6+ fakeEvent ,
57 fakePaymentCancellation ,
68 fakePaymentRefund ,
9+ fakePriceGroup ,
710 fakeRegistration ,
11+ fakeRegistrationPriceGroup ,
812 fakeSignup ,
913 fakeSignupGroup ,
1014 fakeUser ,
@@ -29,6 +33,7 @@ describe('getSignupActionWarning function', () => {
2933 ( action ) => {
3034 const commonProps = {
3135 authenticated : false ,
36+ registration : fakeRegistration ( ) ,
3237 t : i18n . t . bind ( i18n ) ,
3338 userCanDoAction : false ,
3439 } ;
@@ -72,6 +77,7 @@ describe('getSignupActionWarning function', () => {
7277 expect (
7378 getSignupActionWarning ( {
7479 authenticated : true ,
80+ registration : fakeRegistration ( ) ,
7581 t : i18n . t . bind ( i18n ) ,
7682 userCanDoAction : false ,
7783 action,
@@ -84,6 +90,7 @@ describe('getSignupActionWarning function', () => {
8490 expect (
8591 getSignupActionWarning ( {
8692 authenticated : true ,
93+ registration : fakeRegistration ( ) ,
8794 signup : fakeSignup ( {
8895 paymentCancellation : fakePaymentCancellation ( ) ,
8996 } ) ,
@@ -98,6 +105,7 @@ describe('getSignupActionWarning function', () => {
98105 expect (
99106 getSignupActionWarning ( {
100107 authenticated : true ,
108+ registration : fakeRegistration ( ) ,
101109 signup : fakeSignup ( ) ,
102110 signupGroup : fakeSignupGroup ( {
103111 paymentCancellation : fakePaymentCancellation ( ) ,
@@ -113,6 +121,7 @@ describe('getSignupActionWarning function', () => {
113121 expect (
114122 getSignupActionWarning ( {
115123 authenticated : true ,
124+ registration : fakeRegistration ( ) ,
116125 signup : fakeSignup ( {
117126 paymentRefund : fakePaymentRefund ( ) ,
118127 } ) ,
@@ -127,6 +136,7 @@ describe('getSignupActionWarning function', () => {
127136 expect (
128137 getSignupActionWarning ( {
129138 authenticated : true ,
139+ registration : fakeRegistration ( ) ,
130140 signup : fakeSignup ( ) ,
131141 signupGroup : fakeSignupGroup ( {
132142 paymentRefund : fakePaymentRefund ( ) ,
@@ -137,6 +147,112 @@ describe('getSignupActionWarning function', () => {
137147 } )
138148 ) . toBe ( 'Osallistujan maksua hyvitetään eikä osallistujaa voi poistaa.' ) ;
139149 } ) ;
150+
151+ it ( 'should return correct warning when trying to delete paid signup past refund deadline' , ( ) => {
152+ const eventInFiveDays = addDays ( new Date ( ) , 5 ) ;
153+
154+ expect (
155+ getSignupActionWarning ( {
156+ authenticated : true ,
157+ registration : fakeRegistration ( {
158+ event : fakeEvent ( { startTime : eventInFiveDays . toISOString ( ) } ) ,
159+ registrationPriceGroups : [
160+ fakeRegistrationPriceGroup ( { price : '10.00' } ) ,
161+ ] ,
162+ } ) ,
163+ signup : fakeSignup ( {
164+ priceGroup : fakePriceGroup ( ) ,
165+ } ) ,
166+ t : i18n . t . bind ( i18n ) ,
167+ userCanDoAction : true ,
168+ action : SIGNUP_ACTIONS . DELETE ,
169+ } )
170+ ) . toBe ( 'Hyvityksen määräaika on umpeutunut eikä osallistujaa voi poistaa.' ) ;
171+ } ) ;
172+
173+ it ( 'should return correct warning when trying to delete signup group with paid signups past refund deadline' , ( ) => {
174+ const eventInFiveDays = addDays ( new Date ( ) , 5 ) ;
175+
176+ expect (
177+ getSignupActionWarning ( {
178+ authenticated : true ,
179+ registration : fakeRegistration ( {
180+ event : fakeEvent ( { startTime : eventInFiveDays . toISOString ( ) } ) ,
181+ registrationPriceGroups : [
182+ fakeRegistrationPriceGroup ( { price : '10.00' } ) ,
183+ ] ,
184+ } ) ,
185+ signupGroup : fakeSignupGroup ( {
186+ signups : [ fakeSignup ( { priceGroup : fakePriceGroup ( ) } ) ] ,
187+ } ) ,
188+ t : i18n . t . bind ( i18n ) ,
189+ userCanDoAction : true ,
190+ action : SIGNUP_ACTIONS . DELETE ,
191+ } )
192+ ) . toBe ( 'Hyvityksen määräaika on umpeutunut eikä osallistujaa voi poistaa.' ) ;
193+ } ) ;
194+
195+ it ( 'should not return refund deadline warning when trying to delete paid signup within refund deadline' , ( ) => {
196+ const eventInTenDays = addDays ( new Date ( ) , 10 ) ;
197+
198+ expect (
199+ getSignupActionWarning ( {
200+ authenticated : true ,
201+ registration : fakeRegistration ( {
202+ event : fakeEvent ( { startTime : eventInTenDays . toISOString ( ) } ) ,
203+ registrationPriceGroups : [
204+ fakeRegistrationPriceGroup ( { price : '10.00' } ) ,
205+ ] ,
206+ } ) ,
207+ signup : fakeSignup ( {
208+ priceGroup : fakePriceGroup ( ) ,
209+ } ) ,
210+ t : i18n . t . bind ( i18n ) ,
211+ userCanDoAction : true ,
212+ action : SIGNUP_ACTIONS . DELETE ,
213+ } )
214+ ) . toBe ( '' ) ;
215+ } ) ;
216+
217+ it ( 'should not return refund deadline warning when trying to delete free signup past deadline' , ( ) => {
218+ const eventInFiveDays = addDays ( new Date ( ) , 5 ) ;
219+
220+ expect (
221+ getSignupActionWarning ( {
222+ authenticated : true ,
223+ registration : fakeRegistration ( {
224+ event : fakeEvent ( { startTime : eventInFiveDays . toISOString ( ) } ) ,
225+ registrationPriceGroups : [
226+ fakeRegistrationPriceGroup ( { price : '0.00' } ) ,
227+ ] ,
228+ } ) ,
229+ signup : fakeSignup ( ) ,
230+ t : i18n . t . bind ( i18n ) ,
231+ userCanDoAction : true ,
232+ action : SIGNUP_ACTIONS . DELETE ,
233+ } )
234+ ) . toBe ( '' ) ;
235+ } ) ;
236+
237+ it ( 'should not return refund deadline warning when registration has no pricing' , ( ) => {
238+ const eventInFiveDays = addDays ( new Date ( ) , 5 ) ;
239+
240+ expect (
241+ getSignupActionWarning ( {
242+ authenticated : true ,
243+ registration : fakeRegistration ( {
244+ event : fakeEvent ( { startTime : eventInFiveDays . toISOString ( ) } ) ,
245+ registrationPriceGroups : [ ] ,
246+ } ) ,
247+ signup : fakeSignup ( {
248+ priceGroup : fakePriceGroup ( ) ,
249+ } ) ,
250+ t : i18n . t . bind ( i18n ) ,
251+ userCanDoAction : true ,
252+ action : SIGNUP_ACTIONS . DELETE ,
253+ } )
254+ ) . toBe ( '' ) ;
255+ } ) ;
140256} ) ;
141257
142258describe ( 'checkCanUserDoSignupAction function' , ( ) => {
0 commit comments