mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
fix test lint
This commit is contained in:
@@ -5,8 +5,10 @@ import { model as User } from '../../../../../../website/server/models/user';
|
||||
|
||||
describe('checkout success', () => {
|
||||
const subKey = 'basic_3mo';
|
||||
let user, gift, customerId, paymentId;
|
||||
let paypalPaymentExecuteStub, paymentBuyGemsStub, paymentsCreateSubscritionStub;
|
||||
let user; let gift; let customerId; let
|
||||
paymentId;
|
||||
let paypalPaymentExecuteStub; let paymentBuyGemsStub; let
|
||||
paymentsCreateSubscritionStub;
|
||||
|
||||
beforeEach(() => {
|
||||
user = new User();
|
||||
@@ -25,7 +27,9 @@ describe('checkout success', () => {
|
||||
});
|
||||
|
||||
it('purchases gems', async () => {
|
||||
await paypalPayments.checkoutSuccess({user, gift, paymentId, customerId});
|
||||
await paypalPayments.checkoutSuccess({
|
||||
user, gift, paymentId, customerId,
|
||||
});
|
||||
|
||||
expect(paypalPaymentExecuteStub).to.be.calledOnce;
|
||||
expect(paypalPaymentExecuteStub).to.be.calledWith(paymentId, { payer_id: customerId });
|
||||
@@ -38,7 +42,7 @@ describe('checkout success', () => {
|
||||
});
|
||||
|
||||
it('gifts gems', async () => {
|
||||
let receivingUser = new User();
|
||||
const receivingUser = new User();
|
||||
await receivingUser.save();
|
||||
gift = {
|
||||
type: 'gems',
|
||||
@@ -48,7 +52,9 @@ describe('checkout success', () => {
|
||||
},
|
||||
};
|
||||
|
||||
await paypalPayments.checkoutSuccess({user, gift, paymentId, customerId});
|
||||
await paypalPayments.checkoutSuccess({
|
||||
user, gift, paymentId, customerId,
|
||||
});
|
||||
|
||||
expect(paypalPaymentExecuteStub).to.be.calledOnce;
|
||||
expect(paypalPaymentExecuteStub).to.be.calledWith(paymentId, { payer_id: customerId });
|
||||
@@ -62,7 +68,7 @@ describe('checkout success', () => {
|
||||
});
|
||||
|
||||
it('gifts subscription', async () => {
|
||||
let receivingUser = new User();
|
||||
const receivingUser = new User();
|
||||
await receivingUser.save();
|
||||
gift = {
|
||||
type: 'subscription',
|
||||
@@ -72,7 +78,9 @@ describe('checkout success', () => {
|
||||
},
|
||||
};
|
||||
|
||||
await paypalPayments.checkoutSuccess({user, gift, paymentId, customerId});
|
||||
await paypalPayments.checkoutSuccess({
|
||||
user, gift, paymentId, customerId,
|
||||
});
|
||||
|
||||
expect(paypalPaymentExecuteStub).to.be.calledOnce;
|
||||
expect(paypalPaymentExecuteStub).to.be.calledWith(paymentId, { payer_id: customerId });
|
||||
|
||||
@@ -6,7 +6,7 @@ import { model as User } from '../../../../../../website/server/models/user';
|
||||
import common from '../../../../../../website/common';
|
||||
|
||||
const BASE_URL = nconf.get('BASE_URL');
|
||||
const i18n = common.i18n;
|
||||
const { i18n } = common;
|
||||
|
||||
describe('checkout', () => {
|
||||
const subKey = 'basic_3mo';
|
||||
@@ -53,7 +53,7 @@ describe('checkout', () => {
|
||||
});
|
||||
|
||||
it('creates a link for gem purchases', async () => {
|
||||
let link = await paypalPayments.checkout({user: new User()});
|
||||
const link = await paypalPayments.checkout({ user: new User() });
|
||||
|
||||
expect(paypalPaymentCreateStub).to.be.calledOnce;
|
||||
expect(paypalPaymentCreateStub).to.be.calledWith(getPaypalCreateOptions('Habitica Gems', 5.00));
|
||||
@@ -61,9 +61,9 @@ describe('checkout', () => {
|
||||
});
|
||||
|
||||
it('should error if gem amount is too low', async () => {
|
||||
let receivingUser = new User();
|
||||
const receivingUser = new User();
|
||||
receivingUser.save();
|
||||
let gift = {
|
||||
const gift = {
|
||||
type: 'gems',
|
||||
gems: {
|
||||
amount: 0,
|
||||
@@ -71,7 +71,7 @@ describe('checkout', () => {
|
||||
},
|
||||
};
|
||||
|
||||
await expect(paypalPayments.checkout({gift}))
|
||||
await expect(paypalPayments.checkout({ gift }))
|
||||
.to.eventually.be.rejected.and.to.eql({
|
||||
httpCode: 400,
|
||||
message: 'Amount must be at least 1.',
|
||||
@@ -80,10 +80,10 @@ describe('checkout', () => {
|
||||
});
|
||||
|
||||
it('should error if the user cannot get gems', async () => {
|
||||
let user = new User();
|
||||
const user = new User();
|
||||
sinon.stub(user, 'canGetGems').resolves(false);
|
||||
|
||||
await expect(paypalPayments.checkout({user})).to.eventually.be.rejected.and.to.eql({
|
||||
await expect(paypalPayments.checkout({ user })).to.eventually.be.rejected.and.to.eql({
|
||||
httpCode: 401,
|
||||
message: i18n.t('groupPolicyCannotGetGems'),
|
||||
name: 'NotAuthorized',
|
||||
@@ -91,9 +91,9 @@ describe('checkout', () => {
|
||||
});
|
||||
|
||||
it('creates a link for gifting gems', async () => {
|
||||
let receivingUser = new User();
|
||||
const receivingUser = new User();
|
||||
await receivingUser.save();
|
||||
let gift = {
|
||||
const gift = {
|
||||
type: 'gems',
|
||||
uuid: receivingUser._id,
|
||||
gems: {
|
||||
@@ -101,7 +101,7 @@ describe('checkout', () => {
|
||||
},
|
||||
};
|
||||
|
||||
let link = await paypalPayments.checkout({gift});
|
||||
const link = await paypalPayments.checkout({ gift });
|
||||
|
||||
expect(paypalPaymentCreateStub).to.be.calledOnce;
|
||||
expect(paypalPaymentCreateStub).to.be.calledWith(getPaypalCreateOptions('Habitica Gems (Gift)', '4.00'));
|
||||
@@ -109,9 +109,9 @@ describe('checkout', () => {
|
||||
});
|
||||
|
||||
it('creates a link for gifting a subscription', async () => {
|
||||
let receivingUser = new User();
|
||||
const receivingUser = new User();
|
||||
receivingUser.save();
|
||||
let gift = {
|
||||
const gift = {
|
||||
type: 'subscription',
|
||||
subscription: {
|
||||
key: subKey,
|
||||
@@ -119,7 +119,7 @@ describe('checkout', () => {
|
||||
},
|
||||
};
|
||||
|
||||
let link = await paypalPayments.checkout({gift});
|
||||
const link = await paypalPayments.checkout({ gift });
|
||||
|
||||
expect(paypalPaymentCreateStub).to.be.calledOnce;
|
||||
expect(paypalPaymentCreateStub).to.be.calledWith(getPaypalCreateOptions('mo. Habitica Subscription (Gift)', '15.00'));
|
||||
|
||||
@@ -3,13 +3,15 @@ import paypalPayments from '../../../../../../website/server/libs/payments/paypa
|
||||
import payments from '../../../../../../website/server/libs/payments/payments';
|
||||
import {
|
||||
generateGroup,
|
||||
} from '../../../../../helpers/api-unit.helper.js';
|
||||
} from '../../../../../helpers/api-unit.helper';
|
||||
import { model as User } from '../../../../../../website/server/models/user';
|
||||
|
||||
describe('ipn', () => {
|
||||
const subKey = 'basic_3mo';
|
||||
let user, group, txn_type, userPaymentId, groupPaymentId;
|
||||
let ipnVerifyAsyncStub, paymentCancelSubscriptionSpy;
|
||||
let user; let group; let txn_type; let userPaymentId; let
|
||||
groupPaymentId;
|
||||
let ipnVerifyAsyncStub; let
|
||||
paymentCancelSubscriptionSpy;
|
||||
|
||||
beforeEach(async () => {
|
||||
txn_type = 'recurring_payment_profile_cancel';
|
||||
@@ -38,16 +40,16 @@ describe('ipn', () => {
|
||||
paymentCancelSubscriptionSpy = sinon.stub(payments, 'cancelSubscription').resolves({});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
afterEach(() => {
|
||||
paypalPayments.ipnVerifyAsync.restore();
|
||||
payments.cancelSubscription.restore();
|
||||
});
|
||||
|
||||
it('should cancel a user subscription', async () => {
|
||||
await paypalPayments.ipn({txn_type, recurring_payment_id: userPaymentId});
|
||||
await paypalPayments.ipn({ txn_type, recurring_payment_id: userPaymentId });
|
||||
|
||||
expect(ipnVerifyAsyncStub).to.be.calledOnce;
|
||||
expect(ipnVerifyAsyncStub).to.be.calledWith({txn_type, recurring_payment_id: userPaymentId});
|
||||
expect(ipnVerifyAsyncStub).to.be.calledWith({ txn_type, recurring_payment_id: userPaymentId });
|
||||
|
||||
expect(paymentCancelSubscriptionSpy).to.be.calledOnce;
|
||||
expect(paymentCancelSubscriptionSpy.args[0][0].user._id).to.eql(user._id);
|
||||
@@ -55,10 +57,10 @@ describe('ipn', () => {
|
||||
});
|
||||
|
||||
it('should cancel a group subscription', async () => {
|
||||
await paypalPayments.ipn({txn_type, recurring_payment_id: groupPaymentId});
|
||||
await paypalPayments.ipn({ txn_type, recurring_payment_id: groupPaymentId });
|
||||
|
||||
expect(ipnVerifyAsyncStub).to.be.calledOnce;
|
||||
expect(ipnVerifyAsyncStub).to.be.calledWith({txn_type, recurring_payment_id: groupPaymentId});
|
||||
expect(ipnVerifyAsyncStub).to.be.calledWith({ txn_type, recurring_payment_id: groupPaymentId });
|
||||
|
||||
expect(paymentCancelSubscriptionSpy).to.be.calledOnce;
|
||||
expect(paymentCancelSubscriptionSpy).to.be.calledWith({ groupId: group._id, paymentMethod: 'Paypal' });
|
||||
|
||||
@@ -3,17 +3,19 @@ import paypalPayments from '../../../../../../website/server/libs/payments/paypa
|
||||
import payments from '../../../../../../website/server/libs/payments/payments';
|
||||
import {
|
||||
generateGroup,
|
||||
} from '../../../../../helpers/api-unit.helper.js';
|
||||
} from '../../../../../helpers/api-unit.helper';
|
||||
import { model as User } from '../../../../../../website/server/models/user';
|
||||
import common from '../../../../../../website/common';
|
||||
import { createNonLeaderGroupMember } from '../paymentHelpers';
|
||||
|
||||
const i18n = common.i18n;
|
||||
const { i18n } = common;
|
||||
|
||||
describe('subscribeCancel', () => {
|
||||
const subKey = 'basic_3mo';
|
||||
let user, group, groupId, customerId, groupCustomerId, nextBillingDate;
|
||||
let paymentCancelSubscriptionSpy, paypalBillingAgreementCancelStub, paypalBillingAgreementGetStub;
|
||||
let user; let group; let groupId; let customerId; let groupCustomerId; let
|
||||
nextBillingDate;
|
||||
let paymentCancelSubscriptionSpy; let paypalBillingAgreementCancelStub; let
|
||||
paypalBillingAgreementGetStub;
|
||||
|
||||
beforeEach(async () => {
|
||||
customerId = 'customer-id';
|
||||
@@ -49,7 +51,7 @@ describe('subscribeCancel', () => {
|
||||
paymentCancelSubscriptionSpy = sinon.stub(payments, 'cancelSubscription').resolves({});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
afterEach(() => {
|
||||
paypalPayments.paypalBillingAgreementGet.restore();
|
||||
paypalPayments.paypalBillingAgreementCancel.restore();
|
||||
payments.cancelSubscription.restore();
|
||||
@@ -58,7 +60,7 @@ describe('subscribeCancel', () => {
|
||||
it('should throw an error if we are missing a subscription', async () => {
|
||||
user.purchased.plan.customerId = undefined;
|
||||
|
||||
await expect(paypalPayments.subscribeCancel({user}))
|
||||
await expect(paypalPayments.subscribeCancel({ user }))
|
||||
.to.eventually.be.rejected.and.to.eql({
|
||||
httpCode: 401,
|
||||
name: 'NotAuthorized',
|
||||
@@ -67,7 +69,7 @@ describe('subscribeCancel', () => {
|
||||
});
|
||||
|
||||
it('should throw an error if group is not found', async () => {
|
||||
await expect(paypalPayments.subscribeCancel({user, groupId: 'fake-id'}))
|
||||
await expect(paypalPayments.subscribeCancel({ user, groupId: 'fake-id' }))
|
||||
.to.eventually.be.rejected.and.to.eql({
|
||||
httpCode: 404,
|
||||
name: 'NotFound',
|
||||
@@ -76,9 +78,9 @@ describe('subscribeCancel', () => {
|
||||
});
|
||||
|
||||
it('should throw an error if user is not group leader', async () => {
|
||||
let nonLeader = await createNonLeaderGroupMember(group);
|
||||
const nonLeader = await createNonLeaderGroupMember(group);
|
||||
|
||||
await expect(paypalPayments.subscribeCancel({user: nonLeader, groupId: group._id}))
|
||||
await expect(paypalPayments.subscribeCancel({ user: nonLeader, groupId: group._id }))
|
||||
.to.eventually.be.rejected.and.to.eql({
|
||||
httpCode: 401,
|
||||
name: 'NotAuthorized',
|
||||
@@ -87,7 +89,7 @@ describe('subscribeCancel', () => {
|
||||
});
|
||||
|
||||
it('should cancel a user subscription', async () => {
|
||||
await paypalPayments.subscribeCancel({user});
|
||||
await paypalPayments.subscribeCancel({ user });
|
||||
|
||||
expect(paypalBillingAgreementGetStub).to.be.calledOnce;
|
||||
expect(paypalBillingAgreementGetStub).to.be.calledWith(customerId);
|
||||
@@ -105,7 +107,7 @@ describe('subscribeCancel', () => {
|
||||
});
|
||||
|
||||
it('should cancel a group subscription', async () => {
|
||||
await paypalPayments.subscribeCancel({user, groupId: group._id});
|
||||
await paypalPayments.subscribeCancel({ user, groupId: group._id });
|
||||
|
||||
expect(paypalBillingAgreementGetStub).to.be.calledOnce;
|
||||
expect(paypalBillingAgreementGetStub).to.be.calledWith(groupCustomerId);
|
||||
|
||||
@@ -3,14 +3,16 @@ import paypalPayments from '../../../../../../website/server/libs/payments/paypa
|
||||
import payments from '../../../../../../website/server/libs/payments/payments';
|
||||
import {
|
||||
generateGroup,
|
||||
} from '../../../../../helpers/api-unit.helper.js';
|
||||
} from '../../../../../helpers/api-unit.helper';
|
||||
import { model as User } from '../../../../../../website/server/models/user';
|
||||
import common from '../../../../../../website/common';
|
||||
|
||||
describe('subscribeSuccess', () => {
|
||||
const subKey = 'basic_3mo';
|
||||
let user, group, block, groupId, token, headers, customerId;
|
||||
let paypalBillingAgreementExecuteStub, paymentsCreateSubscritionStub;
|
||||
let user; let group; let block; let groupId; let token; let headers; let
|
||||
customerId;
|
||||
let paypalBillingAgreementExecuteStub; let
|
||||
paymentsCreateSubscritionStub;
|
||||
|
||||
beforeEach(async () => {
|
||||
user = new User();
|
||||
@@ -40,7 +42,9 @@ describe('subscribeSuccess', () => {
|
||||
});
|
||||
|
||||
it('creates a user subscription', async () => {
|
||||
await paypalPayments.subscribeSuccess({user, block, groupId, token, headers});
|
||||
await paypalPayments.subscribeSuccess({
|
||||
user, block, groupId, token, headers,
|
||||
});
|
||||
|
||||
expect(paypalBillingAgreementExecuteStub).to.be.calledOnce;
|
||||
expect(paypalBillingAgreementExecuteStub).to.be.calledWith(token, {});
|
||||
@@ -59,7 +63,9 @@ describe('subscribeSuccess', () => {
|
||||
it('create a group subscription', async () => {
|
||||
groupId = group._id;
|
||||
|
||||
await paypalPayments.subscribeSuccess({user, block, groupId, token, headers});
|
||||
await paypalPayments.subscribeSuccess({
|
||||
user, block, groupId, token, headers,
|
||||
});
|
||||
|
||||
expect(paypalBillingAgreementExecuteStub).to.be.calledOnce;
|
||||
expect(paypalBillingAgreementExecuteStub).to.be.calledWith(token, {});
|
||||
|
||||
@@ -6,16 +6,17 @@ import paypalPayments from '../../../../../../website/server/libs/payments/paypa
|
||||
import { model as Coupon } from '../../../../../../website/server/models/coupon';
|
||||
import common from '../../../../../../website/common';
|
||||
|
||||
const i18n = common.i18n;
|
||||
const { i18n } = common;
|
||||
|
||||
describe('subscribe', () => {
|
||||
const subKey = 'basic_3mo';
|
||||
let coupon, sub, approvalHerf;
|
||||
let coupon; let sub; let
|
||||
approvalHerf;
|
||||
let paypalBillingAgreementCreateStub;
|
||||
|
||||
beforeEach(() => {
|
||||
approvalHerf = 'approvalHerf-test';
|
||||
sub = Object.assign({}, common.content.subscriptionBlocks[subKey]);
|
||||
sub = { ...common.content.subscriptionBlocks[subKey] };
|
||||
|
||||
paypalBillingAgreementCreateStub = sinon.stub(paypalPayments, 'paypalBillingAgreementCreate')
|
||||
.resolves({
|
||||
@@ -30,7 +31,7 @@ describe('subscribe', () => {
|
||||
it('should throw an error when coupon code is missing', async () => {
|
||||
sub.discount = 40;
|
||||
|
||||
await expect(paypalPayments.subscribe({sub, coupon}))
|
||||
await expect(paypalPayments.subscribe({ sub, coupon }))
|
||||
.to.eventually.be.rejected.and.to.eql({
|
||||
httpCode: 400,
|
||||
name: 'BadRequest',
|
||||
@@ -43,13 +44,13 @@ describe('subscribe', () => {
|
||||
sub.key = 'google_6mo';
|
||||
coupon = 'example-coupon';
|
||||
|
||||
let couponModel = new Coupon();
|
||||
const couponModel = new Coupon();
|
||||
couponModel.event = 'google_6mo';
|
||||
await couponModel.save();
|
||||
|
||||
sinon.stub(cc, 'validate').returns('invalid');
|
||||
|
||||
await expect(paypalPayments.subscribe({sub, coupon}))
|
||||
await expect(paypalPayments.subscribe({ sub, coupon }))
|
||||
.to.eventually.be.rejected.and.to.eql({
|
||||
httpCode: 401,
|
||||
name: 'NotAuthorized',
|
||||
@@ -63,17 +64,17 @@ describe('subscribe', () => {
|
||||
sub.key = 'google_6mo';
|
||||
coupon = 'example-coupon';
|
||||
|
||||
let couponModel = new Coupon();
|
||||
const couponModel = new Coupon();
|
||||
couponModel.event = 'google_6mo';
|
||||
let updatedCouponModel = await couponModel.save();
|
||||
const updatedCouponModel = await couponModel.save();
|
||||
|
||||
sinon.stub(cc, 'validate').returns(updatedCouponModel._id);
|
||||
|
||||
let link = await paypalPayments.subscribe({sub, coupon});
|
||||
const link = await paypalPayments.subscribe({ sub, coupon });
|
||||
|
||||
expect(link).to.eql(approvalHerf);
|
||||
expect(paypalBillingAgreementCreateStub).to.be.calledOnce;
|
||||
let billingPlanTitle = `Habitica Subscription ($${sub.price} every ${sub.months} months, recurring)`;
|
||||
const billingPlanTitle = `Habitica Subscription ($${sub.price} every ${sub.months} months, recurring)`;
|
||||
expect(paypalBillingAgreementCreateStub).to.be.calledWith({
|
||||
name: billingPlanTitle,
|
||||
description: billingPlanTitle,
|
||||
@@ -92,11 +93,11 @@ describe('subscribe', () => {
|
||||
it('creates a link for a subscription', async () => {
|
||||
delete sub.discount;
|
||||
|
||||
let link = await paypalPayments.subscribe({sub, coupon});
|
||||
const link = await paypalPayments.subscribe({ sub, coupon });
|
||||
|
||||
expect(link).to.eql(approvalHerf);
|
||||
expect(paypalBillingAgreementCreateStub).to.be.calledOnce;
|
||||
let billingPlanTitle = `Habitica Subscription ($${sub.price} every ${sub.months} months, recurring)`;
|
||||
const billingPlanTitle = `Habitica Subscription ($${sub.price} every ${sub.months} months, recurring)`;
|
||||
expect(paypalBillingAgreementCreateStub).to.be.calledWith({
|
||||
name: billingPlanTitle,
|
||||
description: billingPlanTitle,
|
||||
|
||||
Reference in New Issue
Block a user