diff --git a/test/api/unit/libs/payments/apple.test.js b/test/api/unit/libs/payments/apple.test.js index f2eb0af521..2f01fef793 100644 --- a/test/api/unit/libs/payments/apple.test.js +++ b/test/api/unit/libs/payments/apple.test.js @@ -452,80 +452,6 @@ describe('Apple Payments', () => { }); }); - it('allows second user to subscribe if initial subscription is cancelled', async () => { - user.profile.name = 'sender'; - user.purchased.plan.paymentMethod = applePayments.constants.PAYMENT_METHOD_APPLE; - user.purchased.plan.customerId = token; - user.purchased.plan.planId = common.content.subscriptionBlocks.basic_3mo.key; - user.purchased.plan.additionalData = receipt; - user.purchased.plan.dateTerminated = moment.utc().subtract({ day: 1 }).toDate(); - await user.save(); - - iap.getPurchaseData.restore(); - iapGetPurchaseDataStub = sinon.stub(iap, 'getPurchaseData') - .returns([{ - expirationDate: moment.utc().add({ day: 3 }).toDate(), - purchaseDate: moment.utc().toDate(), - productId: sku, - transactionId: `${token}new`, - originalTransactionId: token, - }]); - - const secondUser = new User(); - await secondUser.save(); - await applePayments.subscribe(secondUser, receipt, headers, nextPaymentProcessing); - - expect(paymentsCreateSubscritionStub).to.be.calledOnce; - expect(paymentsCreateSubscritionStub).to.be.calledWith({ - user: secondUser, - customerId: token, - paymentMethod: applePayments.constants.PAYMENT_METHOD_APPLE, - sub, - headers, - additionalData: receipt, - nextPaymentProcessing, - }); - }); - - it('allows second user to subscribe if multiple initial subscription are cancelled', async () => { - user.profile.name = 'sender'; - user.purchased.plan.paymentMethod = applePayments.constants.PAYMENT_METHOD_APPLE; - user.purchased.plan.customerId = token; - user.purchased.plan.planId = common.content.subscriptionBlocks.basic_3mo.key; - user.purchased.plan.additionalData = receipt; - user.purchased.plan.dateTerminated = moment.utc().subtract({ day: 1 }).toDate(); - await user.save(); - - const secondUser = new User(); - secondUser.purchased.plan = user.purchased.plan; - await secondUser.save(); - - iap.getPurchaseData.restore(); - iapGetPurchaseDataStub = sinon.stub(iap, 'getPurchaseData') - .returns([{ - expirationDate: moment.utc().add({ day: 3 }).toDate(), - purchaseDate: moment.utc().toDate(), - productId: sku, - transactionId: `${token}new`, - originalTransactionId: token, - }]); - - const thirdUser = new User(); - await thirdUser.save(); - await applePayments.subscribe(thirdUser, receipt, headers, nextPaymentProcessing); - - expect(paymentsCreateSubscritionStub).to.be.calledOnce; - expect(paymentsCreateSubscritionStub).to.be.calledWith({ - user: thirdUser, - customerId: token, - paymentMethod: applePayments.constants.PAYMENT_METHOD_APPLE, - sub, - headers, - additionalData: receipt, - nextPaymentProcessing, - }); - }); - describe('does not apply multiple times', async () => { it('errors when a user is using the same subscription', async () => { payments.createSubscription.restore(); diff --git a/website/server/libs/payments/apple.js b/website/server/libs/payments/apple.js index 50bcee750b..6001f9ed91 100644 --- a/website/server/libs/payments/apple.js +++ b/website/server/libs/payments/apple.js @@ -130,8 +130,7 @@ api.subscribe = async function subscribe (user, receipt, headers, nextPaymentPro $or: [ { 'purchased.plan.customerId': purchase.originalTransactionId }, { 'purchased.plan.customerId': purchase.transactionId }, - ] - + ], }).exec(); if (existingUsers.length > 0) { if (purchase.originalTransactionId === purchase.transactionId) {