add some logging

This commit is contained in:
Matteo Pagliazzi
2016-07-04 16:46:41 +02:00
parent d4cff995e8
commit 8be5ba76dd
2 changed files with 6 additions and 47 deletions

View File

@@ -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},
});
});
});
});

View File

@@ -12,6 +12,8 @@ import logger from '../../../libs/api-v3/logger';
let api = {}; let api = {};
// TODO missing tests
/** /**
* @apiIgnore Payments are considered part of the private API * @apiIgnore Payments are considered part of the private API
* @api {post} /iap/android/verify Android Verify IAP * @api {post} /iap/android/verify Android Verify IAP
@@ -81,7 +83,6 @@ api.iapiOSVerify = {
let iapBody = req.body; let iapBody = req.body;
let appleRes; let appleRes;
let token;
try { try {
await iap.setup(); await iap.setup();
@@ -96,8 +97,10 @@ api.iapiOSVerify = {
let correctReceipt = true; let correctReceipt = true;
// Purchasing one item at a time (processing of await(s) below is sequential not parallel) // Purchasing one item at a time (processing of await(s) below is sequential not parallel)
for (let purchaseData of purchaseDataList) { for (let index in purchaseDataList) {
token = purchaseData.transactionId; 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 let existingReceipt = await IapPurchaseReceipt.findOne({ // eslint-disable-line babel/no-await-in-loop
_id: token, _id: token,