From 8be5ba76dd29f944e5788a2d5ac3e636353b77ae Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Mon, 4 Jul 2016 16:46:41 +0200 Subject: [PATCH] add some logging --- test/api/v3/unit/libs/inAppPurchases.test.js | 44 ------------------- .../controllers/top-level/payments/iap.js | 9 ++-- 2 files changed, 6 insertions(+), 47 deletions(-) delete mode 100644 test/api/v3/unit/libs/inAppPurchases.test.js diff --git a/test/api/v3/unit/libs/inAppPurchases.test.js b/test/api/v3/unit/libs/inAppPurchases.test.js deleted file mode 100644 index 00986aa3ac..0000000000 --- a/test/api/v3/unit/libs/inAppPurchases.test.js +++ /dev/null @@ -1,44 +0,0 @@ -import { model as User } from '../../../../../website/server/models/user'; -import iapLibrary from 'in-app-purchase'; -import iap from '../../../../../website/server/libs/api-v3/inAppPurchases'; - -describe('In App Purchases', () => { - let user; - let setupSpy; - let validateSpy; - - beforeEach(() => { - user = new User(); - setupSpy = sinon.spy(); - validateSpy = sinon.spy(); - - sandbox.stub(iapLibrary, 'setup').yields(); - sandbox.stub(iapLibrary, 'validate').yields(); - sandbox.stub(iapLibrary, 'isValidated').returns(); - }); - - afterEach(() => { - sandbox.restore(); - }); - - describe('Android', () => { - it('applies new valid receipt', async () => { - iapLibrary.setup.yields(undefined, setupSpy); - - await iap.iapAndroidVerify(user, { - receipt: {token: 1}, - }); - - expect(setupSpy).to.have.been.called; - expect(validateSpy).to.have.been.called; - }); - - it('example with stub yielding an error', async () => { - iapLibrary.setup.yields(new Error('an error')); - - await iap.iapAndroidVerify(user, { - receipt: {token: 1}, - }); - }); - }); -}); diff --git a/website/server/controllers/top-level/payments/iap.js b/website/server/controllers/top-level/payments/iap.js index 5f048083f3..dfaa829139 100644 --- a/website/server/controllers/top-level/payments/iap.js +++ b/website/server/controllers/top-level/payments/iap.js @@ -12,6 +12,8 @@ import logger from '../../../libs/api-v3/logger'; let api = {}; +// TODO missing tests + /** * @apiIgnore Payments are considered part of the private API * @api {post} /iap/android/verify Android Verify IAP @@ -81,7 +83,6 @@ api.iapiOSVerify = { let iapBody = req.body; let appleRes; - let token; try { await iap.setup(); @@ -96,8 +97,10 @@ api.iapiOSVerify = { let correctReceipt = true; // Purchasing one item at a time (processing of await(s) below is sequential not parallel) - for (let purchaseData of purchaseDataList) { - token = purchaseData.transactionId; + for (let index in purchaseDataList) { + let purchaseData = purchaseDataList[index]; + console.log('purchaseData', purchaseData, index); + let token = purchaseData.transactionId; let existingReceipt = await IapPurchaseReceipt.findOne({ // eslint-disable-line babel/no-await-in-loop _id: token,