mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
refactor(api): Remove prod check in payments library. Fill out tests
Wasn't able to mock out pushNotifications correctly and left two tests unfinished. closes #7728 closes #7770
This commit is contained in:
@@ -5,12 +5,9 @@ import {
|
||||
sendTxn as txnEmail,
|
||||
} from './email';
|
||||
import moment from 'moment';
|
||||
import nconf from 'nconf';
|
||||
import sendPushNotification from './pushNotifications';
|
||||
import shared from '../../../../common' ;
|
||||
|
||||
const IS_PROD = nconf.get('IS_PROD');
|
||||
|
||||
let api = {};
|
||||
|
||||
function revealMysteryItems (user) {
|
||||
@@ -72,21 +69,21 @@ api.createSubscription = async function createSubscription (data) {
|
||||
|
||||
revealMysteryItems(recipient);
|
||||
|
||||
if (IS_PROD) {
|
||||
if (!data.gift) txnEmail(data.user, 'subscription-begins');
|
||||
|
||||
analytics.trackPurchase({
|
||||
uuid: data.user._id,
|
||||
itemPurchased: 'Subscription',
|
||||
sku: `${data.paymentMethod.toLowerCase()}-subscription`,
|
||||
purchaseType: 'subscribe',
|
||||
paymentMethod: data.paymentMethod,
|
||||
quantity: 1,
|
||||
gift: Boolean(data.gift),
|
||||
purchaseValue: block.price,
|
||||
});
|
||||
if (!data.gift) {
|
||||
txnEmail(data.user, 'subscription-begins');
|
||||
}
|
||||
|
||||
analytics.trackPurchase({
|
||||
uuid: data.user._id,
|
||||
itemPurchased: 'Subscription',
|
||||
sku: `${data.paymentMethod.toLowerCase()}-subscription`,
|
||||
purchaseType: 'subscribe',
|
||||
paymentMethod: data.paymentMethod,
|
||||
quantity: 1,
|
||||
gift: Boolean(data.gift),
|
||||
purchaseValue: block.price,
|
||||
});
|
||||
|
||||
data.user.purchased.txnCount++;
|
||||
|
||||
if (data.gift) {
|
||||
@@ -158,20 +155,18 @@ api.buyGems = async function buyGems (data) {
|
||||
(data.gift ? data.gift.member : data.user).balance += amt;
|
||||
data.user.purchased.txnCount++;
|
||||
|
||||
if (IS_PROD) {
|
||||
if (!data.gift) txnEmail(data.user, 'donation');
|
||||
if (!data.gift) txnEmail(data.user, 'donation');
|
||||
|
||||
analytics.trackPurchase({
|
||||
uuid: data.user._id,
|
||||
itemPurchased: 'Gems',
|
||||
sku: `${data.paymentMethod.toLowerCase()}-checkout`,
|
||||
purchaseType: 'checkout',
|
||||
paymentMethod: data.paymentMethod,
|
||||
quantity: 1,
|
||||
gift: Boolean(data.gift),
|
||||
purchaseValue: amt,
|
||||
});
|
||||
}
|
||||
analytics.trackPurchase({
|
||||
uuid: data.user._id,
|
||||
itemPurchased: 'Gems',
|
||||
sku: `${data.paymentMethod.toLowerCase()}-checkout`,
|
||||
purchaseType: 'checkout',
|
||||
paymentMethod: data.paymentMethod,
|
||||
quantity: 1,
|
||||
gift: Boolean(data.gift),
|
||||
purchaseValue: amt,
|
||||
});
|
||||
|
||||
if (data.gift) {
|
||||
let byUsername = getUserInfo(data.user, ['name']).name;
|
||||
|
||||
Reference in New Issue
Block a user