mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 21:27:23 +01:00
fix(payments): address some test failures
This commit is contained in:
@@ -17,7 +17,7 @@ describe('Amazon Payments - Checkout', () => {
|
|||||||
let closeOrderReferenceSpy;
|
let closeOrderReferenceSpy;
|
||||||
|
|
||||||
let paymentBuyGemsStub;
|
let paymentBuyGemsStub;
|
||||||
let paymentCreateSubscritionStub;
|
let paymentCreateSubscriptionStub;
|
||||||
let amount = gemsBlock.price / 100;
|
let amount = gemsBlock.price / 100;
|
||||||
|
|
||||||
function expectOrderReferenceSpy () {
|
function expectOrderReferenceSpy () {
|
||||||
@@ -85,8 +85,8 @@ describe('Amazon Payments - Checkout', () => {
|
|||||||
paymentBuyGemsStub = sinon.stub(payments, 'buyGems');
|
paymentBuyGemsStub = sinon.stub(payments, 'buyGems');
|
||||||
paymentBuyGemsStub.resolves({});
|
paymentBuyGemsStub.resolves({});
|
||||||
|
|
||||||
paymentCreateSubscritionStub = sinon.stub(payments, 'createSubscription');
|
paymentCreateSubscriptionStub = sinon.stub(payments, 'createSubscription');
|
||||||
paymentCreateSubscritionStub.resolves({});
|
paymentCreateSubscriptionStub.resolves({});
|
||||||
|
|
||||||
sinon.stub(common, 'uuid').returns('uuid-generated');
|
sinon.stub(common, 'uuid').returns('uuid-generated');
|
||||||
sandbox.stub(gems, 'validateGiftMessage');
|
sandbox.stub(gems, 'validateGiftMessage');
|
||||||
@@ -109,6 +109,7 @@ describe('Amazon Payments - Checkout', () => {
|
|||||||
user,
|
user,
|
||||||
paymentMethod,
|
paymentMethod,
|
||||||
headers,
|
headers,
|
||||||
|
sku: undefined,
|
||||||
};
|
};
|
||||||
if (gift) {
|
if (gift) {
|
||||||
expectedArgs.gift = gift;
|
expectedArgs.gift = gift;
|
||||||
@@ -215,13 +216,14 @@ describe('Amazon Payments - Checkout', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
gift.member = receivingUser;
|
gift.member = receivingUser;
|
||||||
expect(paymentCreateSubscritionStub).to.be.calledOnce;
|
expect(paymentCreateSubscriptionStub).to.be.calledOnce;
|
||||||
expect(paymentCreateSubscritionStub).to.be.calledWith({
|
expect(paymentCreateSubscriptionStub).to.be.calledWith({
|
||||||
user,
|
user,
|
||||||
paymentMethod: amzLib.constants.PAYMENT_METHOD_GIFT,
|
paymentMethod: amzLib.constants.PAYMENT_METHOD_GIFT,
|
||||||
headers,
|
headers,
|
||||||
gift,
|
gift,
|
||||||
gemsBlock: undefined,
|
gemsBlock: undefined,
|
||||||
|
sku: undefined,
|
||||||
});
|
});
|
||||||
expectAmazonStubs();
|
expectAmazonStubs();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ describe('Apple Payments', () => {
|
|||||||
productId: 'com.habitrpg.ios.Habitica.21gems',
|
productId: 'com.habitrpg.ios.Habitica.21gems',
|
||||||
transactionId: token,
|
transactionId: token,
|
||||||
}]);
|
}]);
|
||||||
paymentBuyGemsStub = sinon.stub(payments, 'buyGems').resolves({});
|
paymentBuyGemsStub = sinon.stub(payments, 'buySkuItem').resolves({});
|
||||||
validateGiftMessageStub = sinon.stub(gems, 'validateGiftMessage');
|
validateGiftMessageStub = sinon.stub(gems, 'validateGiftMessage');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ describe('Apple Payments', () => {
|
|||||||
iap.validate.restore();
|
iap.validate.restore();
|
||||||
iap.isValidated.restore();
|
iap.isValidated.restore();
|
||||||
iap.getPurchaseData.restore();
|
iap.getPurchaseData.restore();
|
||||||
payments.buyGems.restore();
|
payments.buySkuItem.restore();
|
||||||
gems.validateGiftMessage.restore();
|
gems.validateGiftMessage.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -97,8 +97,8 @@ describe('Apple Payments', () => {
|
|||||||
|
|
||||||
await expect(applePayments.verifyPurchase({ user, receipt, headers }))
|
await expect(applePayments.verifyPurchase({ user, receipt, headers }))
|
||||||
.to.eventually.be.rejected.and.to.eql({
|
.to.eventually.be.rejected.and.to.eql({
|
||||||
httpCode: 401,
|
httpCode: 400,
|
||||||
name: 'NotAuthorized',
|
name: 'BadRequest',
|
||||||
message: applePayments.constants.RESPONSE_INVALID_ITEM,
|
message: applePayments.constants.RESPONSE_INVALID_ITEM,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ describe('Google Payments', () => {
|
|||||||
.resolves({});
|
.resolves({});
|
||||||
iapIsValidatedStub = sinon.stub(iap, 'isValidated')
|
iapIsValidatedStub = sinon.stub(iap, 'isValidated')
|
||||||
.returns(true);
|
.returns(true);
|
||||||
paymentBuyGemsStub = sinon.stub(payments, 'buyGems').resolves({});
|
paymentBuyGemsStub = sinon.stub(payments, 'buySkuItem').resolves({});
|
||||||
validateGiftMessageStub = sinon.stub(gems, 'validateGiftMessage');
|
validateGiftMessageStub = sinon.stub(gems, 'validateGiftMessage');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ describe('Google Payments', () => {
|
|||||||
iap.setup.restore();
|
iap.setup.restore();
|
||||||
iap.validate.restore();
|
iap.validate.restore();
|
||||||
iap.isValidated.restore();
|
iap.isValidated.restore();
|
||||||
payments.buyGems.restore();
|
payments.buySkuItem.restore();
|
||||||
gems.validateGiftMessage.restore();
|
gems.validateGiftMessage.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -65,8 +65,8 @@ describe('Google Payments', () => {
|
|||||||
user, receipt, signature, headers,
|
user, receipt, signature, headers,
|
||||||
}))
|
}))
|
||||||
.to.eventually.be.rejected.and.to.eql({
|
.to.eventually.be.rejected.and.to.eql({
|
||||||
httpCode: 401,
|
httpCode: 400,
|
||||||
name: 'NotAuthorized',
|
name: 'BadRequest',
|
||||||
message: googlePayments.constants.RESPONSE_INVALID_ITEM,
|
message: googlePayments.constants.RESPONSE_INVALID_ITEM,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import {
|
|||||||
} from '../errors';
|
} from '../errors';
|
||||||
import { model as IapPurchaseReceipt } from '../../models/iapPurchaseReceipt';
|
import { model as IapPurchaseReceipt } from '../../models/iapPurchaseReceipt';
|
||||||
import { model as User } from '../../models/user';
|
import { model as User } from '../../models/user';
|
||||||
import { buySkuItem } from './skuItem';
|
|
||||||
|
|
||||||
const api = {};
|
const api = {};
|
||||||
|
|
||||||
@@ -62,7 +61,7 @@ api.verifyPurchase = async function verifyPurchase (options) {
|
|||||||
userId: user._id,
|
userId: user._id,
|
||||||
});
|
});
|
||||||
|
|
||||||
await buySkuItem({ // eslint-disable-line no-await-in-loop
|
await payments.buySkuItem({ // eslint-disable-line no-await-in-loop
|
||||||
user,
|
user,
|
||||||
gift,
|
gift,
|
||||||
paymentMethod: api.constants.PAYMENT_METHOD_APPLE,
|
paymentMethod: api.constants.PAYMENT_METHOD_APPLE,
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import {
|
|||||||
import { model as IapPurchaseReceipt } from '../../models/iapPurchaseReceipt';
|
import { model as IapPurchaseReceipt } from '../../models/iapPurchaseReceipt';
|
||||||
import { model as User } from '../../models/user';
|
import { model as User } from '../../models/user';
|
||||||
import { validateGiftMessage } from './gems';
|
import { validateGiftMessage } from './gems';
|
||||||
import { buySkuItem } from './skuItem';
|
|
||||||
|
|
||||||
const api = {};
|
const api = {};
|
||||||
|
|
||||||
@@ -62,7 +61,7 @@ api.verifyPurchase = async function verifyPurchase (options) {
|
|||||||
userId: user._id,
|
userId: user._id,
|
||||||
});
|
});
|
||||||
|
|
||||||
await buySkuItem({ // eslint-disable-line no-await-in-loop
|
await payments.buySkuItem({ // eslint-disable-line no-await-in-loop
|
||||||
user,
|
user,
|
||||||
gift,
|
gift,
|
||||||
paymentMethod: api.constants.PAYMENT_METHOD_GOOGLE,
|
paymentMethod: api.constants.PAYMENT_METHOD_GOOGLE,
|
||||||
|
|||||||
Reference in New Issue
Block a user