Skip to content

Commit 07249fa

Browse files
Copilottalyguryn
andcommitted
Add comprehensive test coverage for blocked workspace reminder days
Co-authored-by: talyguryn <15259299+talyguryn@users.noreply.github.com>
1 parent edf9cfb commit 07249fa

1 file changed

Lines changed: 141 additions & 0 deletions

File tree

workers/paymaster/tests/index.test.ts

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,53 @@ 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+
260307
test('Should remind admins for blocked workspace if it has subscription and after payday passed 5 days', async () => {
261308
/**
262309
* Arrange
@@ -304,6 +351,100 @@ describe('PaymasterWorker', () => {
304351
MockDate.reset();
305352
});
306353

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+
},
444+
});
445+
MockDate.reset();
446+
});
447+
307448
test('Should update lastChargeDate and billingPeriodEventsCount if workspace has free tariff plan and it\'s time to pay', async () => {
308449
/**
309450
* Arrange

0 commit comments

Comments
 (0)