mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-10-29 04:04:47 +01:00
* upgrade stripe module * switch stripe api to latest version * fix api version in tests * start upgrading client and server * client: switch to redirect * implement checkout session creation for gems, start implementing webhooks * stripe: start refactoring one time payments * working gems and gift payments * start adding support for subscriptions * stripe: migrate subscriptions and fix cancelling sub * allow upgrading group plans * remove console.log statements * group plans: upgrade from static page / create new one * fix #11885, correct group plan modal title * silence more stripe webhooks * fix group plans redirects * implement editing payment method * start cleaning up code * fix(stripe): update in-code docs, fix eslint issues * subscriptions tests * remove and skip old tests * skip integration tests * fix client build * stripe webhooks: throw error if request fails * subscriptions: correctly pass groupId * remove console.log * stripe: add unit tests for one time payments * wip: stripe checkout tests * stripe createCheckoutSession unit tests * stripe createCheckoutSession unit tests * stripe createCheckoutSession unit tests (editing card) * fix existing webhooks tests * add new webhooks tests * add more webhooks tests * fix lint * stripe integration tests * better error handling when retrieving customer from stripe * client: remove unused strings and improve error handling * payments: limit gift message length (server) * payments: limit gift message length (client) * fix redirects when payment is cancelled * add back "subUpdateCard" string * fix redirects when editing a sub card, use proper names for products, check subs when gifting
67 lines
1.8 KiB
JavaScript
67 lines
1.8 KiB
JavaScript
import common from '../../../../../website/common';
|
|
import {
|
|
getGemsBlock,
|
|
validateGiftMessage,
|
|
} from '../../../../../website/server/libs/payments/gems';
|
|
import { model as User } from '../../../../../website/server/models/user';
|
|
|
|
const { i18n } = common;
|
|
|
|
describe('payments/gems', () => {
|
|
describe('#getGemsBlock', () => {
|
|
it('throws an error if the gem block key is invalid', () => {
|
|
expect(() => getGemsBlock('invalid')).to.throw;
|
|
});
|
|
|
|
it('returns the gem block for the given key', () => {
|
|
expect(getGemsBlock('21gems')).to.equal(common.content.gems['21gems']);
|
|
});
|
|
});
|
|
|
|
describe('#validateGiftMessage', () => {
|
|
let user;
|
|
let gift;
|
|
|
|
beforeEach(() => {
|
|
user = new User();
|
|
|
|
gift = {
|
|
message: (` // exactly 201 chars
|
|
A gift message that is over the 200 chars limit.
|
|
A gift message that is over the 200 chars limit.
|
|
A gift message that is over the 200 chars limit.
|
|
A gift message that is over the 200 chars limit. 1
|
|
`).trim().substring(0, 201),
|
|
};
|
|
|
|
expect(gift.message.length).to.equal(201);
|
|
});
|
|
|
|
it('throws if the gift message is too long', () => {
|
|
let expectedErr;
|
|
|
|
try {
|
|
validateGiftMessage(gift, user);
|
|
} catch (err) {
|
|
expectedErr = err;
|
|
}
|
|
|
|
expect(expectedErr).to.exist;
|
|
expect(expectedErr).to.eql({
|
|
httpCode: 400,
|
|
name: 'BadRequest',
|
|
message: i18n.t('giftMessageTooLong', { maxGiftMessageLength: 200 }),
|
|
});
|
|
});
|
|
|
|
it('does not throw if the gift message is not too long', () => {
|
|
gift.message = gift.message.substring(0, 200);
|
|
expect(() => validateGiftMessage(gift, user)).to.not.throw;
|
|
});
|
|
|
|
it('does not throw if it is not a gift', () => {
|
|
expect(() => validateGiftMessage(null, user)).to.not.throw;
|
|
});
|
|
});
|
|
});
|