2017-12-14 15:59:45 +00:00
|
|
|
/* eslint-disable camelcase */
|
|
|
|
|
import nconf from 'nconf';
|
|
|
|
|
|
2018-06-18 12:40:25 +00:00
|
|
|
import paypalPayments from '../../../../../../website/server/libs/payments/paypal';
|
|
|
|
|
import { model as User } from '../../../../../../website/server/models/user';
|
|
|
|
|
import common from '../../../../../../website/common';
|
2024-03-11 14:59:57 +00:00
|
|
|
import { apiError } from '../../../../../../website/server/libs/apiError';
|
2020-12-14 14:59:17 +00:00
|
|
|
import * as gems from '../../../../../../website/server/libs/payments/gems';
|
2017-12-14 15:59:45 +00:00
|
|
|
|
|
|
|
|
const BASE_URL = nconf.get('BASE_URL');
|
2019-10-08 18:45:38 +00:00
|
|
|
const { i18n } = common;
|
2017-12-14 15:59:45 +00:00
|
|
|
|
Fall Festival Gem Promo (#138)
* 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
2020-09-21 14:22:13 +00:00
|
|
|
describe('paypal - checkout', () => {
|
2017-12-14 15:59:45 +00:00
|
|
|
const subKey = 'basic_3mo';
|
Fall Festival Gem Promo (#138)
* 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
2020-09-21 14:22:13 +00:00
|
|
|
const gemsBlockKey = '21gems';
|
2017-12-14 15:59:45 +00:00
|
|
|
let paypalPaymentCreateStub;
|
|
|
|
|
let approvalHerf;
|
|
|
|
|
|
|
|
|
|
function getPaypalCreateOptions (description, amount) {
|
|
|
|
|
return {
|
2018-12-06 16:13:49 +00:00
|
|
|
experience_profile_id: 'xp_profile_id',
|
2017-12-14 15:59:45 +00:00
|
|
|
intent: 'sale',
|
|
|
|
|
payer: { payment_method: 'Paypal' },
|
|
|
|
|
redirect_urls: {
|
|
|
|
|
return_url: `${BASE_URL}/paypal/checkout/success`,
|
|
|
|
|
cancel_url: `${BASE_URL}`,
|
|
|
|
|
},
|
|
|
|
|
transactions: [{
|
|
|
|
|
item_list: {
|
|
|
|
|
items: [{
|
|
|
|
|
name: description,
|
|
|
|
|
price: amount,
|
|
|
|
|
currency: 'USD',
|
|
|
|
|
quantity: 1,
|
|
|
|
|
}],
|
|
|
|
|
},
|
|
|
|
|
amount: {
|
|
|
|
|
currency: 'USD',
|
|
|
|
|
total: amount,
|
|
|
|
|
},
|
|
|
|
|
description,
|
|
|
|
|
}],
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
approvalHerf = 'approval_href';
|
|
|
|
|
paypalPaymentCreateStub = sinon.stub(paypalPayments, 'paypalPaymentCreate')
|
2018-10-26 16:15:28 +00:00
|
|
|
.resolves({
|
2017-12-14 15:59:45 +00:00
|
|
|
links: [{ rel: 'approval_url', href: approvalHerf }],
|
|
|
|
|
});
|
2020-12-14 14:59:17 +00:00
|
|
|
sandbox.stub(gems, 'validateGiftMessage');
|
2017-12-14 15:59:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
paypalPayments.paypalPaymentCreate.restore();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('creates a link for gem purchases', async () => {
|
Fall Festival Gem Promo (#138)
* 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
2020-09-21 14:22:13 +00:00
|
|
|
const link = await paypalPayments.checkout({ user: new User(), gemsBlock: gemsBlockKey });
|
2017-12-14 15:59:45 +00:00
|
|
|
|
2020-12-14 14:59:17 +00:00
|
|
|
expect(gems.validateGiftMessage).to.not.be.called;
|
2017-12-14 15:59:45 +00:00
|
|
|
expect(paypalPaymentCreateStub).to.be.calledOnce;
|
Fall Festival Gem Promo (#138)
* 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
2020-09-21 14:22:13 +00:00
|
|
|
expect(paypalPaymentCreateStub).to.be.calledWith(getPaypalCreateOptions('Habitica Gems', 4.99));
|
2017-12-14 15:59:45 +00:00
|
|
|
expect(link).to.eql(approvalHerf);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should error if gem amount is too low', async () => {
|
2019-10-08 18:45:38 +00:00
|
|
|
const receivingUser = new User();
|
2017-12-14 15:59:45 +00:00
|
|
|
receivingUser.save();
|
2019-10-08 18:45:38 +00:00
|
|
|
const gift = {
|
2017-12-14 15:59:45 +00:00
|
|
|
type: 'gems',
|
|
|
|
|
gems: {
|
|
|
|
|
amount: 0,
|
|
|
|
|
uuid: receivingUser._id,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-08 18:45:38 +00:00
|
|
|
await expect(paypalPayments.checkout({ gift }))
|
2018-02-17 17:11:24 +00:00
|
|
|
.to.eventually.be.rejected.and.to.eql({
|
|
|
|
|
httpCode: 400,
|
|
|
|
|
message: 'Amount must be at least 1.',
|
|
|
|
|
name: 'BadRequest',
|
|
|
|
|
});
|
2017-12-14 15:59:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should error if the user cannot get gems', async () => {
|
2019-10-08 18:45:38 +00:00
|
|
|
const user = new User();
|
2018-10-26 16:15:28 +00:00
|
|
|
sinon.stub(user, 'canGetGems').resolves(false);
|
2017-12-14 15:59:45 +00:00
|
|
|
|
Fall Festival Gem Promo (#138)
* 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
2020-09-21 14:22:13 +00:00
|
|
|
await expect(paypalPayments.checkout({ user, gemsBlock: gemsBlockKey }))
|
|
|
|
|
.to.eventually.be.rejected.and.to.eql({
|
|
|
|
|
httpCode: 401,
|
|
|
|
|
message: i18n.t('groupPolicyCannotGetGems'),
|
|
|
|
|
name: 'NotAuthorized',
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should error if the gems block is not valid', async () => {
|
|
|
|
|
const user = new User();
|
|
|
|
|
|
|
|
|
|
await expect(paypalPayments.checkout({ user, gemsBlock: 'invalid' }))
|
|
|
|
|
.to.eventually.be.rejected.and.to.eql({
|
|
|
|
|
httpCode: 400,
|
|
|
|
|
message: apiError('invalidGemsBlock'),
|
|
|
|
|
name: 'BadRequest',
|
|
|
|
|
});
|
2017-12-14 15:59:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('creates a link for gifting gems', async () => {
|
2020-12-14 14:59:17 +00:00
|
|
|
const user = new User();
|
2019-10-08 18:45:38 +00:00
|
|
|
const receivingUser = new User();
|
2017-12-14 15:59:45 +00:00
|
|
|
await receivingUser.save();
|
2019-10-08 18:45:38 +00:00
|
|
|
const gift = {
|
2017-12-14 15:59:45 +00:00
|
|
|
type: 'gems',
|
|
|
|
|
uuid: receivingUser._id,
|
|
|
|
|
gems: {
|
|
|
|
|
amount: 16,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-14 14:59:17 +00:00
|
|
|
const link = await paypalPayments.checkout({ user, gift });
|
2017-12-14 15:59:45 +00:00
|
|
|
|
2020-12-14 14:59:17 +00:00
|
|
|
expect(gems.validateGiftMessage).to.be.calledOnce;
|
|
|
|
|
expect(gems.validateGiftMessage).to.be.calledWith(gift, user);
|
2017-12-14 15:59:45 +00:00
|
|
|
expect(paypalPaymentCreateStub).to.be.calledOnce;
|
|
|
|
|
expect(paypalPaymentCreateStub).to.be.calledWith(getPaypalCreateOptions('Habitica Gems (Gift)', '4.00'));
|
|
|
|
|
expect(link).to.eql(approvalHerf);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('creates a link for gifting a subscription', async () => {
|
2020-12-14 14:59:17 +00:00
|
|
|
const user = new User();
|
2019-10-08 18:45:38 +00:00
|
|
|
const receivingUser = new User();
|
2017-12-14 15:59:45 +00:00
|
|
|
receivingUser.save();
|
2019-10-08 18:45:38 +00:00
|
|
|
const gift = {
|
2017-12-14 15:59:45 +00:00
|
|
|
type: 'subscription',
|
|
|
|
|
subscription: {
|
|
|
|
|
key: subKey,
|
|
|
|
|
uuid: receivingUser._id,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-14 14:59:17 +00:00
|
|
|
const link = await paypalPayments.checkout({ user, gift });
|
|
|
|
|
|
|
|
|
|
expect(gems.validateGiftMessage).to.be.calledOnce;
|
|
|
|
|
expect(gems.validateGiftMessage).to.be.calledWith(gift, user);
|
2017-12-14 15:59:45 +00:00
|
|
|
|
|
|
|
|
expect(paypalPaymentCreateStub).to.be.calledOnce;
|
|
|
|
|
expect(paypalPaymentCreateStub).to.be.calledWith(getPaypalCreateOptions('mo. Habitica Subscription (Gift)', '15.00'));
|
|
|
|
|
expect(link).to.eql(approvalHerf);
|
|
|
|
|
});
|
|
|
|
|
});
|