mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-10-27 19:22:55 +01:00
* content: add gems blocks * gemsBlocks: include ios and android identifiers * wip: promo code * split common constants into multiple files * add second promo part * geCurrentEvent, refactor promo * fix lint * fix exports, use world state api * start adding world state tests * remove console.log * use gems block for purchases * remove comments * fix most unit tests * restore comment * fix lint * prevent apple/google gift tests from breaking other tests when stub is not reset * fix unit tests, clarify tests names * iap: use gift object when gifting gems * allow gift object with less data * fix iap tests, remove findById stubs * iap: require less data from the mobile apps * apply discounts * add missing worldState file * fix lint * add test event * start removing 20 gems option for web * start adding support for all gems packages on web * fix unit tests for apple, stripe and google * amazon: support all gems blocks * paypal: support all gems blocks * fix payments unit tests, add tests for getGemsBlock * web: add gems plans with discounts, update stripe * fix amazon and paypal clients, payments success modals * amazon pay: disabled state * update icons, start abstracting payments buttons * begin redesign * redesign gems modal * fix buttons * fix hover color for gems modal close icon * add key to world state current event * extend test event length * implement gems modals designs * early test fall2020 * fix header banner position * add missing files * use iso 8601 for dates, minor ui fixes * fix time zones * events: fix ISO8601 format * fix css indentation * start abstracting banners * refactor payments buttons * test spooky, fix group plans box * implement gems promo banners, refactor banners, fixes * fix lint * fix dates * remove unused i18n strings * fix stripe integration test * fix world state integration tests * the current active event * add missing unit tests * add storybook story for payments buttons component * fix typo * fix(stripe): correct label when gifting subscriptions
84 lines
2.4 KiB
JavaScript
84 lines
2.4 KiB
JavaScript
/* eslint-disable camelcase */
|
|
import paypalPayments from '../../../../../../website/server/libs/payments/paypal';
|
|
import payments from '../../../../../../website/server/libs/payments/payments';
|
|
import {
|
|
generateGroup,
|
|
} from '../../../../../helpers/api-unit.helper';
|
|
import { model as User } from '../../../../../../website/server/models/user';
|
|
import common from '../../../../../../website/common';
|
|
|
|
describe('paypal - subscribeSuccess', () => {
|
|
const subKey = 'basic_3mo';
|
|
let user; let group; let block; let groupId; let token; let headers; let
|
|
customerId;
|
|
let paypalBillingAgreementExecuteStub; let
|
|
paymentsCreateSubscritionStub;
|
|
|
|
beforeEach(async () => {
|
|
user = new User();
|
|
|
|
group = generateGroup({
|
|
name: 'test group',
|
|
type: 'guild',
|
|
privacy: 'public',
|
|
leader: user._id,
|
|
});
|
|
|
|
token = 'test-token';
|
|
headers = {};
|
|
block = common.content.subscriptionBlocks[subKey];
|
|
customerId = 'test-customerId';
|
|
|
|
paypalBillingAgreementExecuteStub = sinon.stub(paypalPayments, 'paypalBillingAgreementExecute')
|
|
.resolves({
|
|
id: customerId,
|
|
});
|
|
paymentsCreateSubscritionStub = sinon.stub(payments, 'createSubscription').resolves({});
|
|
});
|
|
|
|
afterEach(() => {
|
|
paypalPayments.paypalBillingAgreementExecute.restore();
|
|
payments.createSubscription.restore();
|
|
});
|
|
|
|
it('creates a user subscription', async () => {
|
|
await paypalPayments.subscribeSuccess({
|
|
user, block, groupId, token, headers,
|
|
});
|
|
|
|
expect(paypalBillingAgreementExecuteStub).to.be.calledOnce;
|
|
expect(paypalBillingAgreementExecuteStub).to.be.calledWith(token, {});
|
|
|
|
expect(paymentsCreateSubscritionStub).to.be.calledOnce;
|
|
expect(paymentsCreateSubscritionStub).to.be.calledWith({
|
|
user,
|
|
groupId,
|
|
customerId,
|
|
paymentMethod: 'Paypal',
|
|
sub: block,
|
|
headers,
|
|
});
|
|
});
|
|
|
|
it('create a group subscription', async () => {
|
|
groupId = group._id;
|
|
|
|
await paypalPayments.subscribeSuccess({
|
|
user, block, groupId, token, headers,
|
|
});
|
|
|
|
expect(paypalBillingAgreementExecuteStub).to.be.calledOnce;
|
|
expect(paypalBillingAgreementExecuteStub).to.be.calledWith(token, {});
|
|
|
|
expect(paymentsCreateSubscritionStub).to.be.calledOnce;
|
|
expect(paymentsCreateSubscritionStub).to.be.calledWith({
|
|
user,
|
|
groupId,
|
|
customerId,
|
|
paymentMethod: 'Paypal',
|
|
sub: block,
|
|
headers,
|
|
});
|
|
});
|
|
});
|