mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-10-30 20:52:29 +01:00
* refactor sending jobs to worker server * remove unused imports * add delete button to adminpanel * June 2025 content build (#15437) * chore: June 2025 content build * chore: typo fixing * chore: corrections to summer 2025 mage armor, spritesheet * fix(css): rebuild spritesmith-main --------- Co-authored-by: Kalista Payne <sabrecat@gmail.com> * fix(script): don't use extremely costly regex * fix(logging): don't spam empty error events * Translated using Weblate (Ukrainian) Currently translated at 100.0% (134 of 134 strings) Translated using Weblate (Hungarian) Currently translated at 100.0% (280 of 280 strings) Translated using Weblate (French) Currently translated at 100.0% (280 of 280 strings) Translated using Weblate (Spanish) Currently translated at 99.6% (279 of 280 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 97.4% (840 of 862 strings) Translated using Weblate (German) Currently translated at 99.8% (907 of 908 strings) Translated using Weblate (Dutch) Currently translated at 79.3% (219 of 276 strings) Translated using Weblate (Dutch) Currently translated at 28.1% (69 of 245 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 97.4% (840 of 862 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 97.5% (402 of 412 strings) Translated using Weblate (Dutch) Currently translated at 91.5% (377 of 412 strings) Translated using Weblate (Dutch) Currently translated at 85.2% (774 of 908 strings) Translated using Weblate (Ukrainian) Currently translated at 100.0% (91 of 91 strings) Translated using Weblate (Ukrainian) Currently translated at 100.0% (908 of 908 strings) Translated using Weblate (Slovak) Currently translated at 63.4% (106 of 167 strings) Translated using Weblate (Hungarian) Currently translated at 100.0% (908 of 908 strings) Translated using Weblate (Spanish) Currently translated at 100.0% (908 of 908 strings) Translated using Weblate (Slovak) Currently translated at 2.0% (5 of 245 strings) Translated using Weblate (French) Currently translated at 100.0% (908 of 908 strings) Translated using Weblate (Russian) Currently translated at 64.4% (158 of 245 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 97.0% (837 of 862 strings) Translated using Weblate (German) Currently translated at 97.9% (844 of 862 strings) Translated using Weblate (Ukrainian) Currently translated at 100.0% (91 of 91 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 97.3% (401 of 412 strings) Translated using Weblate (Portuguese) Currently translated at 95.3% (393 of 412 strings) Translated using Weblate (Slovak) Currently translated at 45.6% (413 of 905 strings) Translated using Weblate (Slovak) Currently translated at 50.8% (85 of 167 strings) Translated using Weblate (Russian) Currently translated at 99.1% (113 of 114 strings) Translated using Weblate (Russian) Currently translated at 64.0% (157 of 245 strings) Translated using Weblate (Russian) Currently translated at 64.0% (157 of 245 strings) Translated using Weblate (Russian) Currently translated at 62.0% (152 of 245 strings) Translated using Weblate (Russian) Currently translated at 62.0% (152 of 245 strings) Translated using Weblate (Russian) Currently translated at 60.8% (149 of 245 strings) Translated using Weblate (Russian) Currently translated at 60.8% (149 of 245 strings) Translated using Weblate (Russian) Currently translated at 60.4% (148 of 245 strings) Translated using Weblate (Russian) Currently translated at 60.4% (148 of 245 strings) Translated using Weblate (Russian) Currently translated at 60.0% (147 of 245 strings) Translated using Weblate (Russian) Currently translated at 60.0% (147 of 245 strings) Translated using Weblate (Russian) Currently translated at 57.9% (142 of 245 strings) Translated using Weblate (Russian) Currently translated at 57.9% (142 of 245 strings) Translated using Weblate (Russian) Currently translated at 56.7% (139 of 245 strings) Translated using Weblate (Russian) Currently translated at 56.7% (139 of 245 strings) Translated using Weblate (Russian) Currently translated at 56.3% (138 of 245 strings) Translated using Weblate (Russian) Currently translated at 56.3% (138 of 245 strings) Translated using Weblate (Russian) Currently translated at 53.8% (132 of 245 strings) Translated using Weblate (Russian) Currently translated at 53.8% (132 of 245 strings) Translated using Weblate (Russian) Currently translated at 53.4% (131 of 245 strings) Translated using Weblate (Russian) Currently translated at 53.4% (131 of 245 strings) Translated using Weblate (Russian) Currently translated at 48.9% (120 of 245 strings) Translated using Weblate (Russian) Currently translated at 48.9% (120 of 245 strings) Translated using Weblate (Russian) Currently translated at 48.5% (119 of 245 strings) Translated using Weblate (Russian) Currently translated at 48.5% (119 of 245 strings) Translated using Weblate (Russian) Currently translated at 46.9% (115 of 245 strings) Translated using Weblate (Russian) Currently translated at 46.9% (115 of 245 strings) Translated using Weblate (Russian) Currently translated at 46.9% (115 of 245 strings) Translated using Weblate (Russian) Currently translated at 46.9% (115 of 245 strings) Translated using Weblate (Russian) Currently translated at 46.9% (115 of 245 strings) Translated using Weblate (Russian) Currently translated at 46.9% (115 of 245 strings) Translated using Weblate (Russian) Currently translated at 46.9% (115 of 245 strings) Translated using Weblate (Russian) Currently translated at 46.9% (115 of 245 strings) Translated using Weblate (Russian) Currently translated at 46.9% (115 of 245 strings) Translated using Weblate (Russian) Currently translated at 46.9% (115 of 245 strings) Translated using Weblate (Russian) Currently translated at 46.9% (115 of 245 strings) Translated using Weblate (Russian) Currently translated at 46.9% (115 of 245 strings) Translated using Weblate (Russian) Currently translated at 46.9% (115 of 245 strings) Translated using Weblate (Russian) Currently translated at 45.3% (111 of 245 strings) Translated using Weblate (Russian) Currently translated at 45.3% (111 of 245 strings) Translated using Weblate (Russian) Currently translated at 45.3% (111 of 245 strings) Translated using Weblate (Russian) Currently translated at 45.3% (111 of 245 strings) Translated using Weblate (Russian) Currently translated at 44.4% (109 of 245 strings) Translated using Weblate (German) Currently translated at 99.9% (3324 of 3325 strings) Translated using Weblate (Russian) Currently translated at 44.4% (109 of 245 strings) Translated using Weblate (Russian) Currently translated at 44.4% (109 of 245 strings) Translated using Weblate (Ukrainian) Currently translated at 100.0% (91 of 91 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 100.0% (94 of 94 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 93.8% (107 of 114 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 100.0% (22 of 22 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 99.7% (429 of 430 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 95.1% (820 of 862 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 99.6% (902 of 905 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 100.0% (167 of 167 strings) Translated using Weblate (Portuguese) Currently translated at 100.0% (167 of 167 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 95.1% (820 of 862 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 95.1% (820 of 862 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 95.1% (820 of 862 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 93.8% (107 of 114 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 93.6% (3114 of 3325 strings) Translated using Weblate (Portuguese) Currently translated at 53.9% (1793 of 3325 strings) Translated using Weblate (Dutch) Currently translated at 78.1% (2600 of 3325 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 99.5% (242 of 243 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 95.1% (820 of 862 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 96.6% (398 of 412 strings) Translated using Weblate (Portuguese (Brazil)) Currently translated at 99.6% (902 of 905 strings) Translated using Weblate (Italian) Currently translated at 99.1% (113 of 114 strings) Translated using Weblate (Italian) Currently translated at 87.3% (2903 of 3325 strings) Translated using Weblate (Italian) Currently translated at 17.1% (42 of 245 strings) Translated using Weblate (Italian) Currently translated at 99.0% (408 of 412 strings) Translated using Weblate (Italian) Currently translated at 92.7% (102 of 110 strings) Translated using Weblate (Chinese (Simplified)) Currently translated at 99.0% (3292 of 3325 strings) Translated using Weblate (Chinese (Simplified)) Currently translated at 98.7% (3285 of 3325 strings) Translated using Weblate (Chinese (Simplified)) Currently translated at 98.7% (3285 of 3325 strings) Translated using Weblate (Slovak) Currently translated at 100.0% (134 of 134 strings) Translated using Weblate (Slovak) Currently translated at 100.0% (412 of 412 strings) Translated using Weblate (Ukrainian) Currently translated at 100.0% (91 of 91 strings) Translated using Weblate (Ukrainian) Currently translated at 100.0% (905 of 905 strings) Translated using Weblate (Chinese (Simplified)) Currently translated at 98.1% (3262 of 3325 strings) Co-authored-by: Andrea <goffopaguro@gmail.com> Co-authored-by: Artem StolyROV <stolyarov11303@gmail.com> Co-authored-by: Céu <marcel.ufscar@gmail.com> Co-authored-by: David Kaya <david@kaya.sk> Co-authored-by: Filip Betko <filipbetko@gmail.com> Co-authored-by: FingerTiao <787170918@qq.com> Co-authored-by: Irina Shcherbinina <cat3dcat007@gmail.com> Co-authored-by: Jaime Martí <jaumemarti77@icloud.com> Co-authored-by: Mencius <beautyalinap@gmail.com> Co-authored-by: Natalie Luhrs <eilatan@gmail.com> Co-authored-by: Nikita Maximov <ruvemaximus@gmail.com> Co-authored-by: Sophie LE MASLE <sophiesuff@gmail.com> Co-authored-by: Summer_GUI <heyang94@163.com> Co-authored-by: Tetiana <merekka13@gmail.com> Co-authored-by: Tom <tompsognathus@gmail.com> Co-authored-by: Toro Mor <thomas.bizer@gmx.de> Co-authored-by: V Aar <v.vanderaar@gmail.com> Co-authored-by: Viktor Révész <rviktor@ivankapal.com> Co-authored-by: Weblate <noreply@weblate.org> Co-authored-by: razil <boss.razmarin@gmail.com> Co-authored-by: Волкозмей <klippiky@gmail.com> Co-authored-by: Данила Мальцев <maltsev-danila@inbox.ru> Co-authored-by: Татьяна Куклева <klippiky@gmail.com> Translate-URL: https://translate.habitica.com/projects/habitica/achievements/pt/ Translate-URL: https://translate.habitica.com/projects/habitica/achievements/pt_BR/ Translate-URL: https://translate.habitica.com/projects/habitica/achievements/sk/ Translate-URL: https://translate.habitica.com/projects/habitica/backgrounds/de/ Translate-URL: https://translate.habitica.com/projects/habitica/backgrounds/es/ Translate-URL: https://translate.habitica.com/projects/habitica/backgrounds/fr/ Translate-URL: https://translate.habitica.com/projects/habitica/backgrounds/hu/ Translate-URL: https://translate.habitica.com/projects/habitica/backgrounds/nl/ Translate-URL: https://translate.habitica.com/projects/habitica/backgrounds/pt_BR/ Translate-URL: https://translate.habitica.com/projects/habitica/backgrounds/sk/ Translate-URL: https://translate.habitica.com/projects/habitica/backgrounds/uk/ Translate-URL: https://translate.habitica.com/projects/habitica/challenge/it/ Translate-URL: https://translate.habitica.com/projects/habitica/communityguidelines/uk/ Translate-URL: https://translate.habitica.com/projects/habitica/content/it/ Translate-URL: https://translate.habitica.com/projects/habitica/content/nl/ Translate-URL: https://translate.habitica.com/projects/habitica/content/pt/ Translate-URL: https://translate.habitica.com/projects/habitica/content/pt_BR/ Translate-URL: https://translate.habitica.com/projects/habitica/content/sk/ Translate-URL: https://translate.habitica.com/projects/habitica/faq/it/ Translate-URL: https://translate.habitica.com/projects/habitica/faq/nl/ Translate-URL: https://translate.habitica.com/projects/habitica/faq/ru/ Translate-URL: https://translate.habitica.com/projects/habitica/faq/sk/ Translate-URL: https://translate.habitica.com/projects/habitica/gear/de/ Translate-URL: https://translate.habitica.com/projects/habitica/gear/it/ Translate-URL: https://translate.habitica.com/projects/habitica/gear/nl/ Translate-URL: https://translate.habitica.com/projects/habitica/gear/pt/ Translate-URL: https://translate.habitica.com/projects/habitica/gear/pt_BR/ Translate-URL: https://translate.habitica.com/projects/habitica/gear/zh_Hans/ Translate-URL: https://translate.habitica.com/projects/habitica/generic/pt_BR/ Translate-URL: https://translate.habitica.com/projects/habitica/groups/pt_BR/ Translate-URL: https://translate.habitica.com/projects/habitica/limited/es/ Translate-URL: https://translate.habitica.com/projects/habitica/limited/fr/ Translate-URL: https://translate.habitica.com/projects/habitica/limited/hu/ Translate-URL: https://translate.habitica.com/projects/habitica/limited/nl/ Translate-URL: https://translate.habitica.com/projects/habitica/loginincentives/pt_BR/ Translate-URL: https://translate.habitica.com/projects/habitica/npc/sk/ Translate-URL: https://translate.habitica.com/projects/habitica/npc/uk/ Translate-URL: https://translate.habitica.com/projects/habitica/pets/it/ Translate-URL: https://translate.habitica.com/projects/habitica/pets/pt_BR/ Translate-URL: https://translate.habitica.com/projects/habitica/pets/ru/ Translate-URL: https://translate.habitica.com/projects/habitica/quests/pt_BR/ Translate-URL: https://translate.habitica.com/projects/habitica/questscontent/de/ Translate-URL: https://translate.habitica.com/projects/habitica/questscontent/pt_BR/ Translation: Habitica/Achievements Translation: Habitica/Backgrounds Translation: Habitica/Challenge Translation: Habitica/Communityguidelines Translation: Habitica/Content Translation: Habitica/Faq Translation: Habitica/Gear Translation: Habitica/Generic Translation: Habitica/Groups Translation: Habitica/Limited Translation: Habitica/Loginincentives Translation: Habitica/Npc Translation: Habitica/Pets Translation: Habitica/Quests Translation: Habitica/Questscontent * 5.36.4 * chore(deps): bump serialize-javascript in /website/client (#15395) Bumps [serialize-javascript](https://github.com/yahoo/serialize-javascript) from 6.0.1 to 6.0.2. - [Release notes](https://github.com/yahoo/serialize-javascript/releases) - [Commits](https://github.com/yahoo/serialize-javascript/compare/v6.0.1...v6.0.2) --- updated-dependencies: - dependency-name: serialize-javascript dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump axios from 1.7.4 to 1.8.2 (#15401) Bumps [axios](https://github.com/axios/axios) from 1.7.4 to 1.8.2. - [Release notes](https://github.com/axios/axios/releases) - [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md) - [Commits](https://github.com/axios/axios/compare/v1.7.4...v1.8.2) --- updated-dependencies: - dependency-name: axios dependency-type: direct:development ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump prismjs from 1.29.0 to 1.30.0 (#15403) Bumps [prismjs](https://github.com/PrismJS/prism) from 1.29.0 to 1.30.0. - [Release notes](https://github.com/PrismJS/prism/releases) - [Changelog](https://github.com/PrismJS/prism/blob/master/CHANGELOG.md) - [Commits](https://github.com/PrismJS/prism/compare/v1.29.0...v1.30.0) --- updated-dependencies: - dependency-name: prismjs dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump @babel/runtime-corejs2 in /website/client (#15406) Bumps [@babel/runtime-corejs2](https://github.com/babel/babel/tree/HEAD/packages/babel-runtime-corejs2) from 7.23.6 to 7.26.10. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.26.10/packages/babel-runtime-corejs2) --- updated-dependencies: - dependency-name: "@babel/runtime-corejs2" dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump @babel/helpers in /website/client (#15407) Bumps [@babel/helpers](https://github.com/babel/babel/tree/HEAD/packages/babel-helpers) from 7.23.6 to 7.26.10. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.26.10/packages/babel-helpers) --- updated-dependencies: - dependency-name: "@babel/helpers" dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump @babel/runtime from 7.23.9 to 7.26.10 (#15410) Bumps [@babel/runtime](https://github.com/babel/babel/tree/HEAD/packages/babel-runtime) from 7.23.9 to 7.26.10. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.26.10/packages/babel-runtime) --- updated-dependencies: - dependency-name: "@babel/runtime" dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump http-proxy-middleware in /website/client (#15427) Bumps [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware) from 2.0.6 to 2.0.9. - [Release notes](https://github.com/chimurai/http-proxy-middleware/releases) - [Changelog](https://github.com/chimurai/http-proxy-middleware/blob/v2.0.9/CHANGELOG.md) - [Commits](https://github.com/chimurai/http-proxy-middleware/compare/v2.0.6...v2.0.9) --- updated-dependencies: - dependency-name: http-proxy-middleware dependency-version: 2.0.9 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Optimize database access for some use cases (#15444) * optimize query when listing challenge tasks * Optimize query for checking if user is party leader * correct worker call * remove unused priority * fix tests * don’t use body with delete * add detailed information about sub payment for google and apple * Support paypal details for subscription in admin panel * stripe payment details * fix imports * fix tests * fix deleting account * begin building group admin panel * fix convertig sub to group plan * improve sub status display * fix lint * fix long line * fix sub state display * lint fix * fix * delete amplitude data by default * improve searching for email in admin panel * correctly call method * move delete button in admin panel * fix(lint): whitespace * fix(style): indent * fix(typo): humand --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Natalie <78037386+CuriousMagpie@users.noreply.github.com> Co-authored-by: Kalista Payne <sabrecat@gmail.com> Co-authored-by: Weblate <noreply@weblate.org> Co-authored-by: Andrea <goffopaguro@gmail.com> Co-authored-by: Artem StolyROV <stolyarov11303@gmail.com> Co-authored-by: Céu <marcel.ufscar@gmail.com> Co-authored-by: David Kaya <david@kaya.sk> Co-authored-by: Filip Betko <filipbetko@gmail.com> Co-authored-by: FingerTiao <787170918@qq.com> Co-authored-by: Irina Shcherbinina <cat3dcat007@gmail.com> Co-authored-by: Jaime Martí <jaumemarti77@icloud.com> Co-authored-by: Mencius <beautyalinap@gmail.com> Co-authored-by: Natalie Luhrs <eilatan@gmail.com> Co-authored-by: Nikita Maximov <ruvemaximus@gmail.com> Co-authored-by: Sophie LE MASLE <sophiesuff@gmail.com> Co-authored-by: Summer_GUI <heyang94@163.com> Co-authored-by: Tetiana <merekka13@gmail.com> Co-authored-by: Tom <tompsognathus@gmail.com> Co-authored-by: Toro Mor <thomas.bizer@gmx.de> Co-authored-by: V Aar <v.vanderaar@gmail.com> Co-authored-by: Viktor Révész <rviktor@ivankapal.com> Co-authored-by: razil <boss.razmarin@gmail.com> Co-authored-by: Волкозмей <klippiky@gmail.com> Co-authored-by: Данила Мальцев <maltsev-danila@inbox.ru> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Kalista Payne <kalista@habitica.com>
423 lines
14 KiB
JavaScript
423 lines
14 KiB
JavaScript
/* eslint-disable camelcase */
|
|
import moment from 'moment';
|
|
import payments from '../../../../../website/server/libs/payments/payments';
|
|
import googlePayments from '../../../../../website/server/libs/payments/google';
|
|
import iap from '../../../../../website/server/libs/inAppPurchases';
|
|
import { model as User } from '../../../../../website/server/models/user';
|
|
import common from '../../../../../website/common';
|
|
import * as gems from '../../../../../website/server/libs/payments/gems';
|
|
|
|
const { i18n } = common;
|
|
|
|
describe('Google Payments', () => {
|
|
const subKey = 'basic_3mo';
|
|
let iapSetupStub;
|
|
let iapValidateStub;
|
|
let iapIsValidatedStub;
|
|
let paymentBuySkuStub;
|
|
let validateGiftMessageStub;
|
|
|
|
beforeEach(() => {
|
|
iapSetupStub = sinon.stub(iap, 'setup')
|
|
.resolves();
|
|
iapIsValidatedStub = sinon.stub(iap, 'isValidated')
|
|
.returns(true);
|
|
sinon.stub(iap, 'isCanceled').returns(false);
|
|
sinon.stub(iap, 'isExpired').returns(false);
|
|
paymentBuySkuStub = sinon.stub(payments, 'buySkuItem').resolves({});
|
|
validateGiftMessageStub = sinon.stub(gems, 'validateGiftMessage');
|
|
});
|
|
|
|
afterEach(() => {
|
|
iap.setup.restore();
|
|
iap.validate.restore();
|
|
iap.isValidated.restore();
|
|
iap.isCanceled.restore();
|
|
iap.isExpired.restore();
|
|
payments.buySkuItem.restore();
|
|
gems.validateGiftMessage.restore();
|
|
});
|
|
|
|
describe('verifyPurchase', () => {
|
|
let sku; let user; let token; let receipt; let signature; let
|
|
headers;
|
|
|
|
beforeEach(() => {
|
|
sku = 'com.habitrpg.android.habitica.iap.21gems';
|
|
user = new User();
|
|
receipt = `{"token": "${token}", "productId": "${sku}"}`;
|
|
signature = '';
|
|
headers = {};
|
|
|
|
iapValidateStub = sinon.stub(iap, 'validate').resolves({ productId: sku });
|
|
});
|
|
|
|
it('should throw an error if receipt is invalid', async () => {
|
|
iap.isValidated.restore();
|
|
iapIsValidatedStub = sinon.stub(iap, 'isValidated')
|
|
.returns(false);
|
|
|
|
await expect(googlePayments.verifyPurchase({
|
|
user, receipt, signature, headers,
|
|
}))
|
|
.to.eventually.be.rejected.and.to.eql({
|
|
httpCode: 401,
|
|
name: 'NotAuthorized',
|
|
message: googlePayments.constants.RESPONSE_INVALID_RECEIPT,
|
|
});
|
|
});
|
|
|
|
it('should throw an error if productId is invalid', async () => {
|
|
receipt = `{"token": "${token}", "productId": "invalid"}`;
|
|
iapValidateStub.restore();
|
|
iapValidateStub = sinon.stub(iap, 'validate').resolves({});
|
|
|
|
paymentBuySkuStub.restore();
|
|
await expect(googlePayments.verifyPurchase({
|
|
user, receipt, signature, headers,
|
|
}))
|
|
.to.eventually.be.rejected.and.to.eql({
|
|
httpCode: 400,
|
|
name: 'BadRequest',
|
|
message: googlePayments.constants.RESPONSE_INVALID_ITEM,
|
|
});
|
|
paymentBuySkuStub = sinon.stub(payments, 'buySkuItem').resolves({});
|
|
});
|
|
|
|
it('should throw an error if user cannot purchase gems', async () => {
|
|
sinon.stub(user, 'canGetGems').resolves(false);
|
|
|
|
await expect(googlePayments.verifyPurchase({
|
|
user, receipt, signature, headers,
|
|
}))
|
|
.to.eventually.be.rejected.and.to.eql({
|
|
httpCode: 401,
|
|
name: 'NotAuthorized',
|
|
message: i18n.t('groupPolicyCannotGetGems'),
|
|
});
|
|
|
|
user.canGetGems.restore();
|
|
});
|
|
|
|
it('purchases gems', async () => {
|
|
sinon.stub(user, 'canGetGems').resolves(true);
|
|
await googlePayments.verifyPurchase({
|
|
user, receipt, signature, headers,
|
|
});
|
|
|
|
expect(validateGiftMessageStub).to.not.be.called;
|
|
|
|
expect(iapSetupStub).to.be.calledOnce;
|
|
expect(iapValidateStub).to.be.calledOnce;
|
|
expect(iapValidateStub).to.be.calledWith(iap.GOOGLE, {
|
|
data: receipt,
|
|
signature,
|
|
});
|
|
expect(iapIsValidatedStub).to.be.calledOnce;
|
|
expect(iapIsValidatedStub).to.be.calledWith(
|
|
{ productId: sku },
|
|
);
|
|
|
|
expect(paymentBuySkuStub).to.be.calledOnce;
|
|
expect(paymentBuySkuStub).to.be.calledWith({
|
|
user,
|
|
gift: undefined,
|
|
paymentMethod: googlePayments.constants.PAYMENT_METHOD_GOOGLE,
|
|
sku,
|
|
headers,
|
|
});
|
|
expect(user.canGetGems).to.be.calledOnce;
|
|
user.canGetGems.restore();
|
|
});
|
|
|
|
it('gifts gems', async () => {
|
|
const receivingUser = new User();
|
|
await receivingUser.save();
|
|
|
|
const gift = { uuid: receivingUser._id };
|
|
await googlePayments.verifyPurchase({
|
|
user, gift, receipt, signature, headers,
|
|
});
|
|
|
|
expect(validateGiftMessageStub).to.be.calledOnce;
|
|
expect(validateGiftMessageStub).to.be.calledWith(gift, user);
|
|
|
|
expect(iapSetupStub).to.be.calledOnce;
|
|
expect(iapValidateStub).to.be.calledOnce;
|
|
expect(iapValidateStub).to.be.calledWith(iap.GOOGLE, {
|
|
data: receipt,
|
|
signature,
|
|
});
|
|
expect(iapIsValidatedStub).to.be.calledOnce;
|
|
expect(iapIsValidatedStub).to.be.calledWith(
|
|
{ productId: sku },
|
|
);
|
|
|
|
expect(paymentBuySkuStub).to.be.calledOnce;
|
|
expect(paymentBuySkuStub).to.be.calledWith({
|
|
user,
|
|
gift: {
|
|
uuid: receivingUser._id,
|
|
member: sinon.match({ _id: receivingUser._id }),
|
|
},
|
|
paymentMethod: googlePayments.constants.PAYMENT_METHOD_GOOGLE,
|
|
sku,
|
|
headers,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('subscribe', () => {
|
|
let sub; let sku; let user; let token; let receipt; let signature; let headers; let
|
|
nextPaymentProcessing;
|
|
let paymentsCreateSubscritionStub;
|
|
|
|
beforeEach(() => {
|
|
sub = common.content.subscriptionBlocks[subKey];
|
|
sku = 'com.habitrpg.android.habitica.subscription.3month';
|
|
|
|
token = 'test-token';
|
|
headers = {};
|
|
receipt = `{"token": "${token}"}`;
|
|
signature = '';
|
|
nextPaymentProcessing = moment.utc().add({ days: 2 });
|
|
|
|
iapValidateStub = sinon.stub(iap, 'validate')
|
|
.resolves({});
|
|
paymentsCreateSubscritionStub = sinon.stub(payments, 'createSubscription').resolves({});
|
|
});
|
|
|
|
afterEach(() => {
|
|
payments.createSubscription.restore();
|
|
});
|
|
|
|
it('should throw an error if receipt is invalid', async () => {
|
|
iap.isValidated.restore();
|
|
iapIsValidatedStub = sinon.stub(iap, 'isValidated')
|
|
.returns(false);
|
|
|
|
await expect(googlePayments
|
|
.subscribe(sku, user, receipt, signature, headers, nextPaymentProcessing))
|
|
.to.eventually.be.rejected.and.to.eql({
|
|
httpCode: 401,
|
|
name: 'NotAuthorized',
|
|
message: googlePayments.constants.RESPONSE_INVALID_RECEIPT,
|
|
});
|
|
});
|
|
|
|
it('should throw an error if sku is invalid', async () => {
|
|
sku = 'invalid';
|
|
|
|
await expect(googlePayments
|
|
.subscribe(sku, user, receipt, signature, headers, nextPaymentProcessing))
|
|
.to.eventually.be.rejected.and.to.eql({
|
|
httpCode: 401,
|
|
name: 'NotAuthorized',
|
|
message: googlePayments.constants.RESPONSE_INVALID_ITEM,
|
|
});
|
|
});
|
|
|
|
it('creates a user subscription', async () => {
|
|
await googlePayments.subscribe(sku, user, receipt, signature, headers, nextPaymentProcessing);
|
|
|
|
expect(iapSetupStub).to.be.calledOnce;
|
|
expect(iapValidateStub).to.be.calledOnce;
|
|
expect(iapValidateStub).to.be.calledWith(iap.GOOGLE, {
|
|
data: receipt,
|
|
signature,
|
|
});
|
|
expect(iapIsValidatedStub).to.be.calledOnce;
|
|
expect(iapIsValidatedStub).to.be.calledWith({});
|
|
|
|
expect(paymentsCreateSubscritionStub).to.be.calledOnce;
|
|
expect(paymentsCreateSubscritionStub).to.be.calledWith({
|
|
user,
|
|
customerId: token,
|
|
paymentMethod: googlePayments.constants.PAYMENT_METHOD_GOOGLE,
|
|
sub,
|
|
headers,
|
|
additionalData: { data: receipt, signature },
|
|
nextPaymentProcessing,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('cancelSubscribe ', () => {
|
|
let user; let token; let receipt; let signature; let headers; let customerId; let
|
|
expirationDate;
|
|
let iapGetPurchaseDataStub; let
|
|
paymentCancelSubscriptionSpy;
|
|
|
|
beforeEach(async () => {
|
|
token = 'test-token';
|
|
headers = {};
|
|
receipt = `{"token": "${token}"}`;
|
|
signature = '';
|
|
customerId = 'test-customerId';
|
|
expirationDate = moment.utc();
|
|
iapValidateStub = sinon.stub(iap, 'validate')
|
|
.resolves({
|
|
expirationDate,
|
|
});
|
|
iapGetPurchaseDataStub = sinon.stub(iap, 'getPurchaseData')
|
|
.returns([{ expirationDate: expirationDate.toDate(), autoRenewing: false }]);
|
|
|
|
user = new User();
|
|
user.profile.name = 'sender';
|
|
user.purchased.plan.customerId = customerId;
|
|
user.purchased.plan.paymentMethod = googlePayments.constants.PAYMENT_METHOD_GOOGLE;
|
|
user.purchased.plan.planId = subKey;
|
|
user.purchased.plan.additionalData = { data: receipt, signature };
|
|
|
|
paymentCancelSubscriptionSpy = sinon.stub(payments, 'cancelSubscription').resolves({});
|
|
});
|
|
|
|
afterEach(() => {
|
|
iap.getPurchaseData.restore();
|
|
payments.cancelSubscription.restore();
|
|
});
|
|
|
|
it('should throw an error if we are missing a subscription', async () => {
|
|
user.purchased.plan.paymentMethod = undefined;
|
|
|
|
await expect(googlePayments.cancelSubscribe(user, headers))
|
|
.to.eventually.be.rejected.and.to.eql({
|
|
httpCode: 401,
|
|
name: 'NotAuthorized',
|
|
message: i18n.t('missingSubscription'),
|
|
});
|
|
});
|
|
|
|
it('should throw an error if receipt is invalid', async () => {
|
|
iap.isValidated.restore();
|
|
iapIsValidatedStub = sinon.stub(iap, 'isValidated')
|
|
.returns(false);
|
|
|
|
await expect(googlePayments.cancelSubscribe(user, headers))
|
|
.to.eventually.be.rejected.and.to.eql({
|
|
httpCode: 401,
|
|
name: 'NotAuthorized',
|
|
message: googlePayments.constants.RESPONSE_INVALID_RECEIPT,
|
|
});
|
|
});
|
|
|
|
it('should cancel a user subscription', async () => {
|
|
iap.isCanceled.restore();
|
|
iap.isCanceled = sinon.stub(iap, 'isCanceled').returns(true);
|
|
await googlePayments.cancelSubscribe(user, headers);
|
|
|
|
expect(iapSetupStub).to.be.calledOnce;
|
|
expect(iapValidateStub).to.be.calledOnce;
|
|
expect(iapValidateStub).to.be.calledWith(iap.GOOGLE, {
|
|
data: receipt,
|
|
signature,
|
|
});
|
|
expect(iapIsValidatedStub).to.be.calledOnce;
|
|
expect(iapIsValidatedStub).to.be.calledWith({
|
|
expirationDate,
|
|
});
|
|
expect(iapGetPurchaseDataStub).to.be.calledOnce;
|
|
|
|
expect(paymentCancelSubscriptionSpy).to.be.calledOnce;
|
|
expect(paymentCancelSubscriptionSpy).to.be.calledWith({
|
|
user,
|
|
paymentMethod: googlePayments.constants.PAYMENT_METHOD_GOOGLE,
|
|
nextBill: expirationDate.toDate(),
|
|
headers,
|
|
});
|
|
});
|
|
|
|
it('should cancel a user subscription with multiple inactive subscriptions', async () => {
|
|
iap.isCanceled.restore();
|
|
iap.isCanceled = sinon.stub(iap, 'isCanceled').returns(true);
|
|
const laterDate = moment.utc().add(7, 'days');
|
|
iap.getPurchaseData.restore();
|
|
iapGetPurchaseDataStub = sinon.stub(iap, 'getPurchaseData')
|
|
.returns([{
|
|
startTimeMillis: expirationDate.valueOf(),
|
|
expirationDate,
|
|
autoRenewing: false,
|
|
}, {
|
|
startTimeMillis: laterDate.valueOf(),
|
|
expirationDate: laterDate,
|
|
autoRenewing: false,
|
|
},
|
|
]);
|
|
await googlePayments.cancelSubscribe(user, headers);
|
|
|
|
expect(iapSetupStub).to.be.calledOnce;
|
|
expect(iapValidateStub).to.be.calledOnce;
|
|
expect(iapValidateStub).to.be.calledWith(iap.GOOGLE, {
|
|
data: receipt,
|
|
signature,
|
|
});
|
|
expect(iapIsValidatedStub).to.be.calledOnce;
|
|
expect(iapIsValidatedStub).to.be.calledWith({
|
|
expirationDate,
|
|
});
|
|
expect(iapGetPurchaseDataStub).to.be.calledOnce;
|
|
|
|
expect(paymentCancelSubscriptionSpy).to.be.calledOnce;
|
|
expect(paymentCancelSubscriptionSpy).to.be.calledWith({
|
|
user,
|
|
paymentMethod: googlePayments.constants.PAYMENT_METHOD_GOOGLE,
|
|
nextBill: laterDate.toDate(),
|
|
headers,
|
|
});
|
|
});
|
|
|
|
it('should not cancel a user subscription with autorenew', async () => {
|
|
iap.getPurchaseData.restore();
|
|
iapGetPurchaseDataStub = sinon.stub(iap, 'getPurchaseData')
|
|
.returns([{ autoRenewing: true }]);
|
|
await expect(googlePayments.cancelSubscribe(user, headers))
|
|
.to.eventually.be.rejected.and.to.eql({
|
|
httpCode: 401,
|
|
name: 'NotAuthorized',
|
|
message: googlePayments.constants.RESPONSE_STILL_VALID,
|
|
});
|
|
|
|
expect(iapSetupStub).to.be.calledOnce;
|
|
expect(iapValidateStub).to.be.calledOnce;
|
|
expect(iapValidateStub).to.be.calledWith(iap.GOOGLE, {
|
|
data: receipt,
|
|
signature,
|
|
});
|
|
expect(iapIsValidatedStub).to.be.calledOnce;
|
|
expect(iapIsValidatedStub).to.be.calledWith({
|
|
expirationDate,
|
|
});
|
|
expect(iapGetPurchaseDataStub).to.be.calledOnce;
|
|
|
|
expect(paymentCancelSubscriptionSpy).to.not.be.called;
|
|
});
|
|
|
|
it('should not cancel a user subscription with multiple subscriptions with one autorenew', async () => {
|
|
iap.getPurchaseData.restore();
|
|
iapGetPurchaseDataStub = sinon.stub(iap, 'getPurchaseData')
|
|
.returns([{ expirationDate, autoRenewing: false },
|
|
{ autoRenewing: true },
|
|
{ expirationDate, autoRenewing: false }]);
|
|
await expect(googlePayments.cancelSubscribe(user, headers))
|
|
.to.eventually.be.rejected.and.to.eql({
|
|
httpCode: 401,
|
|
name: 'NotAuthorized',
|
|
message: googlePayments.constants.RESPONSE_STILL_VALID,
|
|
});
|
|
expect(iapSetupStub).to.be.calledOnce;
|
|
expect(iapValidateStub).to.be.calledOnce;
|
|
expect(iapValidateStub).to.be.calledWith(iap.GOOGLE, {
|
|
data: receipt,
|
|
signature,
|
|
});
|
|
expect(iapIsValidatedStub).to.be.calledOnce;
|
|
expect(iapIsValidatedStub).to.be.calledWith({
|
|
expirationDate,
|
|
});
|
|
expect(iapGetPurchaseDataStub).to.be.calledOnce;
|
|
|
|
expect(paymentCancelSubscriptionSpy).to.not.be.called;
|
|
});
|
|
});
|
|
});
|