Skip to content

Commit 57795b8

Browse files
committed
Add test and condition
1 parent 5c89c0c commit 57795b8

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/billing/cloudpayments.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,10 @@ export default class CloudPaymentsWebhooks {
272272

273273
try {
274274
await businessOperation.setStatus(BusinessOperationStatus.Confirmed);
275-
await workspace.changePlan(tariffPlan._id);
275+
276+
if (!data.isCardLinkOperation) {
277+
await workspace.changePlan(tariffPlan._id);
278+
}
276279

277280
const subscriptionId = body.SubscriptionId;
278281

test/integration/cases/billing/pay.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,26 @@ describe('Pay webhook', () => {
337337
expect(updatedWorkspace?.billingPeriodEventsCount).toBe(0);
338338
});
339339

340+
test('Should not reset events counter in workspace if it is a card linking operation', async () => {
341+
const apiResponse = await apiInstance.post('/billing/pay', {
342+
...validPayRequestData,
343+
Data: JSON.stringify({
344+
checksum: await checksumService.generateChecksum({
345+
...paymentSuccessPayload,
346+
isCardLinkOperation: true,
347+
nextPaymentDate: new Date(Date.now() + 24 * 60 * 60 * 1000).toString(), // next day
348+
}),
349+
}),
350+
});
351+
352+
const notUpdatedWorkspace = await workspacesCollection.findOne({
353+
_id: workspace._id,
354+
});
355+
356+
expect(apiResponse.data.code).toBe(PayCodes.SUCCESS);
357+
expect(notUpdatedWorkspace?.billingPeriodEventsCount).not.toBe(0);
358+
});
359+
340360
test('Should reset last charge date in workspace', async () => {
341361
const apiResponse = await apiInstance.post('/billing/pay', validPayRequestData);
342362

@@ -375,6 +395,26 @@ describe('Pay webhook', () => {
375395
expect(apiResponse.data.code).toBe(PayCodes.SUCCESS);
376396
});
377397

398+
test('Should not send task to limiter worker if it is a card linking operation', async () => {
399+
const apiResponse = await apiInstance.post('/billing/pay', {
400+
...validPayRequestData,
401+
Data: JSON.stringify({
402+
checksum: await checksumService.generateChecksum({
403+
...paymentSuccessPayload,
404+
isCardLinkOperation: true,
405+
nextPaymentDate: new Date(Date.now() + 24 * 60 * 60 * 1000).toString(), // next day
406+
}),
407+
}),
408+
});
409+
410+
const message = await global.rabbitChannel.get('cron-tasks/limiter', {
411+
noAck: true,
412+
});
413+
414+
expect(message).toBeFalsy();
415+
expect(apiResponse.data.code).toBe(PayCodes.SUCCESS);
416+
});
417+
378418
// test('Should associate an account with a workspace if the workspace did not have one', async () => {
379419
// /**
380420
// * Remove accountId from existed workspace
@@ -479,6 +519,8 @@ describe('Pay webhook', () => {
479519
expect(updatedUser?.bankCards?.shift()).toMatchObject(expectedCard);
480520
expect(apiResponse.data.code).toBe(PayCodes.SUCCESS);
481521
});
522+
523+
482524
});
483525

484526
describe('With invalid request', () => {

0 commit comments

Comments
 (0)