From 0f7001b6093f16df4ddca41accbfd6743383a419 Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Fri, 11 Nov 2022 13:58:45 +0100 Subject: [PATCH] fix lint --- test/api/unit/libs/payments/apple.test.js | 16 +++++++--------- website/server/libs/payments/apple.js | 10 +++++----- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/test/api/unit/libs/payments/apple.test.js b/test/api/unit/libs/payments/apple.test.js index f595c0d941..f2eb0af521 100644 --- a/test/api/unit/libs/payments/apple.test.js +++ b/test/api/unit/libs/payments/apple.test.js @@ -9,7 +9,7 @@ import * as gems from '../../../../../website/server/libs/payments/gems'; const { i18n } = common; -describe.only('Apple Payments', () => { +describe('Apple Payments', () => { const subKey = 'basic_3mo'; describe('verifyPurchase', () => { @@ -459,7 +459,7 @@ describe.only('Apple Payments', () => { 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() + await user.save(); iap.getPurchaseData.restore(); iapGetPurchaseDataStub = sinon.stub(iap, 'getPurchaseData') @@ -467,7 +467,7 @@ describe.only('Apple Payments', () => { expirationDate: moment.utc().add({ day: 3 }).toDate(), purchaseDate: moment.utc().toDate(), productId: sku, - transactionId: token + "new", + transactionId: `${token}new`, originalTransactionId: token, }]); @@ -487,7 +487,6 @@ describe.only('Apple Payments', () => { }); }); - 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; @@ -499,7 +498,7 @@ describe.only('Apple Payments', () => { const secondUser = new User(); secondUser.purchased.plan = user.purchased.plan; - await secondUser.save() + await secondUser.save(); iap.getPurchaseData.restore(); iapGetPurchaseDataStub = sinon.stub(iap, 'getPurchaseData') @@ -507,7 +506,7 @@ describe.only('Apple Payments', () => { expirationDate: moment.utc().add({ day: 3 }).toDate(), purchaseDate: moment.utc().toDate(), productId: sku, - transactionId: token + "new", + transactionId: `${token}new`, originalTransactionId: token, }]); @@ -602,7 +601,6 @@ describe.only('Apple Payments', () => { }); }); - it('errors when a multiple users exist using the subscription', async () => { user = new User(); await user.save(); @@ -621,7 +619,7 @@ describe.only('Apple Payments', () => { const secondUser = new User(); secondUser.purchased.plan = user.purchased.plan; secondUser.purchased.plan.dateTerminate = new Date(); - secondUser.save() + secondUser.save(); iap.getPurchaseData.restore(); iapGetPurchaseDataStub = sinon.stub(iap, 'getPurchaseData') @@ -629,7 +627,7 @@ describe.only('Apple Payments', () => { expirationDate: moment.utc().add({ day: 1 }).toDate(), purchaseDate: moment.utc().toDate(), productId: sku, - transactionId: token + "new", + transactionId: `${token}new`, originalTransactionId: token, }]); diff --git a/website/server/libs/payments/apple.js b/website/server/libs/payments/apple.js index 23a4d227be..bdd86907ff 100644 --- a/website/server/libs/payments/apple.js +++ b/website/server/libs/payments/apple.js @@ -133,8 +133,7 @@ api.subscribe = async function subscribe (user, receipt, headers, nextPaymentPro if (purchase.originalTransactionId === purchase.transactionId) { throw new NotAuthorized(this.constants.RESPONSE_ALREADY_USED); } - for (const index in existingUsers) { - const existingUser = existingUsers[index]; + for (const existingUser of existingUsers) { if (existingUser._id !== user._id && !existingUser.purchased.plan.dateTerminated) { throw new NotAuthorized(this.constants.RESPONSE_ALREADY_USED); } @@ -262,7 +261,7 @@ api.cancelSubscribe = async function cancelSubscribe (user, headers) { const purchases = iap.getPurchaseData(appleRes); if (purchases.length === 0) throw new NotAuthorized(this.constants.RESPONSE_INVALID_RECEIPT); let newestDate; - let newestPurchase + let newestPurchase; for (const purchaseData of purchases) { const datePurchased = new Date(Number(purchaseData.purchaseDate)); @@ -272,7 +271,9 @@ api.cancelSubscribe = async function cancelSubscribe (user, headers) { } } - if (!iap.isCanceled(newestPurchase) && !iap.isExpired(newestPurchase)) throw new NotAuthorized(this.constants.RESPONSE_STILL_VALID); + if (!iap.isCanceled(newestPurchase) && !iap.isExpired(newestPurchase)) { + throw new NotAuthorized(this.constants.RESPONSE_STILL_VALID); + } await payments.cancelSubscription({ user, @@ -289,7 +290,6 @@ api.cancelSubscribe = async function cancelSubscribe (user, headers) { throw err; } } - }; export default api;