@@ -257,192 +257,194 @@ describe('PaymasterWorker', () => {
257257 MockDate . reset ( ) ;
258258 } ) ;
259259
260- test ( 'Should remind admins for blocked workspace if it has subscription and after payday passed 1 day' , async ( ) => {
261- /**
262- * Arrange
263- */
264- const currentDate = new Date ( '2005-12-23' ) ;
265- const plan = createPlanMock ( {
266- monthlyCharge : 100 ,
267- isDefault : true ,
268- } ) ;
269- const workspace = createWorkspaceMock ( {
270- plan,
271- subscriptionId : 'some-subscription-id' ,
272- lastChargeDate : new Date ( '2005-11-22' ) ,
273- isBlocked : true ,
274- billingPeriodEventsCount : 10 ,
275- } ) ;
276-
277- await fillDatabaseWithMockedData ( {
278- workspace,
279- plan,
280- } ) ;
281-
282- MockDate . set ( currentDate ) ;
283-
284- /**
285- * Act
286- */
287- const worker = new PaymasterWorker ( ) ;
288- const blockWorkspaceSpy = jest . spyOn ( worker , 'addTask' ) ;
289-
290- await worker . start ( ) ;
291- await worker . handle ( WORKSPACE_SUBSCRIPTION_CHECK ) ;
292- await worker . finish ( ) ;
293-
294- /**
295- * Assert
296- */
297- expect ( blockWorkspaceSpy ) . toHaveBeenCalledWith ( 'sender/email' , {
298- type : 'blocked-workspace-reminder' ,
299- payload : {
300- workspaceId : workspace . _id . toString ( ) ,
301- daysAfterPayday : 1 ,
302- } ,
303- } ) ;
304- MockDate . reset ( ) ;
305- } ) ;
306-
307- test ( 'Should remind admins for blocked workspace if it has subscription and after payday passed 5 days' , async ( ) => {
308- /**
309- * Arrange
310- */
311- const currentDate = new Date ( '2005-12-27' ) ;
312- const plan = createPlanMock ( {
313- monthlyCharge : 100 ,
314- isDefault : true ,
315- } ) ;
316- const workspace = createWorkspaceMock ( {
317- plan,
318- subscriptionId : 'some-subscription-id' ,
319- lastChargeDate : new Date ( '2005-11-22' ) ,
320- isBlocked : true ,
321- billingPeriodEventsCount : 10 ,
322- } ) ;
323-
324- await fillDatabaseWithMockedData ( {
325- workspace,
326- plan,
327- } ) ;
328-
329- MockDate . set ( currentDate ) ;
330-
331- /**
332- * Act
333- */
334- const worker = new PaymasterWorker ( ) ;
335- const blockWorkspaceSpy = jest . spyOn ( worker , 'addTask' ) ;
336-
337- await worker . start ( ) ;
338- await worker . handle ( WORKSPACE_SUBSCRIPTION_CHECK ) ;
339- await worker . finish ( ) ;
340-
341- /**
342- * Assert
343- */
344- expect ( blockWorkspaceSpy ) . toHaveBeenCalledWith ( 'sender/email' , {
345- type : 'blocked-workspace-reminder' ,
346- payload : {
347- workspaceId : workspace . _id . toString ( ) ,
348- daysAfterPayday : 5 ,
349- } ,
350- } ) ;
351- MockDate . reset ( ) ;
352- } ) ;
353-
354- test ( 'Should remind admins for blocked workspace if it has subscription and after payday passed 30 days' , async ( ) => {
355- /**
356- * Arrange
357- */
358- const currentDate = new Date ( '2006-01-21' ) ;
359- const plan = createPlanMock ( {
360- monthlyCharge : 100 ,
361- isDefault : true ,
362- } ) ;
363- const workspace = createWorkspaceMock ( {
364- plan,
365- subscriptionId : 'some-subscription-id' ,
366- lastChargeDate : new Date ( '2005-11-22' ) ,
367- isBlocked : true ,
368- billingPeriodEventsCount : 10 ,
369- } ) ;
370-
371- await fillDatabaseWithMockedData ( {
372- workspace,
373- plan,
374- } ) ;
375-
376- MockDate . set ( currentDate ) ;
377-
378- /**
379- * Act
380- */
381- const worker = new PaymasterWorker ( ) ;
382- const blockWorkspaceSpy = jest . spyOn ( worker , 'addTask' ) ;
383-
384- await worker . start ( ) ;
385- await worker . handle ( WORKSPACE_SUBSCRIPTION_CHECK ) ;
386- await worker . finish ( ) ;
387-
388- /**
389- * Assert
390- */
391- expect ( blockWorkspaceSpy ) . toHaveBeenCalledWith ( 'sender/email' , {
392- type : 'blocked-workspace-reminder' ,
393- payload : {
394- workspaceId : workspace . _id . toString ( ) ,
395- daysAfterPayday : 30 ,
396- } ,
397- } ) ;
398- MockDate . reset ( ) ;
399- } ) ;
400-
401- test ( 'Should not remind admins for blocked workspace on days not in reminder schedule (day 4)' , async ( ) => {
402- /**
403- * Arrange
404- */
405- const currentDate = new Date ( '2005-12-26' ) ;
406- const plan = createPlanMock ( {
407- monthlyCharge : 100 ,
408- isDefault : true ,
409- } ) ;
410- const workspace = createWorkspaceMock ( {
411- plan,
412- subscriptionId : 'some-subscription-id' ,
413- lastChargeDate : new Date ( '2005-11-22' ) ,
414- isBlocked : true ,
415- billingPeriodEventsCount : 10 ,
416- } ) ;
417-
418- await fillDatabaseWithMockedData ( {
419- workspace,
420- plan,
421- } ) ;
422-
423- MockDate . set ( currentDate ) ;
424-
425- /**
426- * Act
427- */
428- const worker = new PaymasterWorker ( ) ;
429- const blockWorkspaceSpy = jest . spyOn ( worker , 'addTask' ) ;
430-
431- await worker . start ( ) ;
432- await worker . handle ( WORKSPACE_SUBSCRIPTION_CHECK ) ;
433- await worker . finish ( ) ;
434-
435- /**
436- * Assert
437- */
438- expect ( blockWorkspaceSpy ) . not . toHaveBeenCalledWith ( 'sender/email' , {
439- type : 'blocked-workspace-reminder' ,
440- payload : {
441- workspaceId : workspace . _id . toString ( ) ,
442- daysAfterPayday : 4 ,
443- } ,
260+ describe ( 'Blocked workspace reminder tests' , ( ) => {
261+ test ( 'Should remind admins for blocked workspace if it has subscription and after payday passed 1 day' , async ( ) => {
262+ /**
263+ * Arrange
264+ */
265+ const currentDate = new Date ( '2005-12-23' ) ;
266+ const plan = createPlanMock ( {
267+ monthlyCharge : 100 ,
268+ isDefault : true ,
269+ } ) ;
270+ const workspace = createWorkspaceMock ( {
271+ plan,
272+ subscriptionId : 'some-subscription-id' ,
273+ lastChargeDate : new Date ( '2005-11-22' ) ,
274+ isBlocked : true ,
275+ billingPeriodEventsCount : 10 ,
276+ } ) ;
277+
278+ await fillDatabaseWithMockedData ( {
279+ workspace,
280+ plan,
281+ } ) ;
282+
283+ MockDate . set ( currentDate ) ;
284+
285+ /**
286+ * Act
287+ */
288+ const worker = new PaymasterWorker ( ) ;
289+ const blockWorkspaceSpy = jest . spyOn ( worker , 'addTask' ) ;
290+
291+ await worker . start ( ) ;
292+ await worker . handle ( WORKSPACE_SUBSCRIPTION_CHECK ) ;
293+ await worker . finish ( ) ;
294+
295+ /**
296+ * Assert
297+ */
298+ expect ( blockWorkspaceSpy ) . toHaveBeenCalledWith ( 'sender/email' , {
299+ type : 'blocked-workspace-reminder' ,
300+ payload : {
301+ workspaceId : workspace . _id . toString ( ) ,
302+ daysAfterPayday : 1 ,
303+ } ,
304+ } ) ;
305+ MockDate . reset ( ) ;
306+ } ) ;
307+
308+ test ( 'Should remind admins for blocked workspace if it has subscription and after payday passed 5 days' , async ( ) => {
309+ /**
310+ * Arrange
311+ */
312+ const currentDate = new Date ( '2005-12-27' ) ;
313+ const plan = createPlanMock ( {
314+ monthlyCharge : 100 ,
315+ isDefault : true ,
316+ } ) ;
317+ const workspace = createWorkspaceMock ( {
318+ plan,
319+ subscriptionId : 'some-subscription-id' ,
320+ lastChargeDate : new Date ( '2005-11-22' ) ,
321+ isBlocked : true ,
322+ billingPeriodEventsCount : 10 ,
323+ } ) ;
324+
325+ await fillDatabaseWithMockedData ( {
326+ workspace,
327+ plan,
328+ } ) ;
329+
330+ MockDate . set ( currentDate ) ;
331+
332+ /**
333+ * Act
334+ */
335+ const worker = new PaymasterWorker ( ) ;
336+ const blockWorkspaceSpy = jest . spyOn ( worker , 'addTask' ) ;
337+
338+ await worker . start ( ) ;
339+ await worker . handle ( WORKSPACE_SUBSCRIPTION_CHECK ) ;
340+ await worker . finish ( ) ;
341+
342+ /**
343+ * Assert
344+ */
345+ expect ( blockWorkspaceSpy ) . toHaveBeenCalledWith ( 'sender/email' , {
346+ type : 'blocked-workspace-reminder' ,
347+ payload : {
348+ workspaceId : workspace . _id . toString ( ) ,
349+ daysAfterPayday : 5 ,
350+ } ,
351+ } ) ;
352+ MockDate . reset ( ) ;
353+ } ) ;
354+
355+ test ( 'Should remind admins for blocked workspace if it has subscription and after payday passed 30 days' , async ( ) => {
356+ /**
357+ * Arrange
358+ */
359+ const currentDate = new Date ( '2006-01-21' ) ;
360+ const plan = createPlanMock ( {
361+ monthlyCharge : 100 ,
362+ isDefault : true ,
363+ } ) ;
364+ const workspace = createWorkspaceMock ( {
365+ plan,
366+ subscriptionId : 'some-subscription-id' ,
367+ lastChargeDate : new Date ( '2005-11-22' ) ,
368+ isBlocked : true ,
369+ billingPeriodEventsCount : 10 ,
370+ } ) ;
371+
372+ await fillDatabaseWithMockedData ( {
373+ workspace,
374+ plan,
375+ } ) ;
376+
377+ MockDate . set ( currentDate ) ;
378+
379+ /**
380+ * Act
381+ */
382+ const worker = new PaymasterWorker ( ) ;
383+ const blockWorkspaceSpy = jest . spyOn ( worker , 'addTask' ) ;
384+
385+ await worker . start ( ) ;
386+ await worker . handle ( WORKSPACE_SUBSCRIPTION_CHECK ) ;
387+ await worker . finish ( ) ;
388+
389+ /**
390+ * Assert
391+ */
392+ expect ( blockWorkspaceSpy ) . toHaveBeenCalledWith ( 'sender/email' , {
393+ type : 'blocked-workspace-reminder' ,
394+ payload : {
395+ workspaceId : workspace . _id . toString ( ) ,
396+ daysAfterPayday : 30 ,
397+ } ,
398+ } ) ;
399+ MockDate . reset ( ) ;
400+ } ) ;
401+
402+ test ( 'Should not remind admins for blocked workspace on days not in reminder schedule (day 4)' , async ( ) => {
403+ /**
404+ * Arrange
405+ */
406+ const currentDate = new Date ( '2005-12-26' ) ;
407+ const plan = createPlanMock ( {
408+ monthlyCharge : 100 ,
409+ isDefault : true ,
410+ } ) ;
411+ const workspace = createWorkspaceMock ( {
412+ plan,
413+ subscriptionId : 'some-subscription-id' ,
414+ lastChargeDate : new Date ( '2005-11-22' ) ,
415+ isBlocked : true ,
416+ billingPeriodEventsCount : 10 ,
417+ } ) ;
418+
419+ await fillDatabaseWithMockedData ( {
420+ workspace,
421+ plan,
422+ } ) ;
423+
424+ MockDate . set ( currentDate ) ;
425+
426+ /**
427+ * Act
428+ */
429+ const worker = new PaymasterWorker ( ) ;
430+ const blockWorkspaceSpy = jest . spyOn ( worker , 'addTask' ) ;
431+
432+ await worker . start ( ) ;
433+ await worker . handle ( WORKSPACE_SUBSCRIPTION_CHECK ) ;
434+ await worker . finish ( ) ;
435+
436+ /**
437+ * Assert
438+ */
439+ expect ( blockWorkspaceSpy ) . not . toHaveBeenCalledWith ( 'sender/email' , {
440+ type : 'blocked-workspace-reminder' ,
441+ payload : {
442+ workspaceId : workspace . _id . toString ( ) ,
443+ daysAfterPayday : 4 ,
444+ } ,
445+ } ) ;
446+ MockDate . reset ( ) ;
444447 } ) ;
445- MockDate . reset ( ) ;
446448 } ) ;
447449
448450 test ( 'Should update lastChargeDate and billingPeriodEventsCount if workspace has free tariff plan and it\'s time to pay' , async ( ) => {
0 commit comments