transferGems: use receiver language translation for PM strings #7722 (#8173)

* transferGems: use receiver language translation for PM strings #7722

* chore(test): DRY up transfer gems test

* chore(test): Allow check for language in translation assertion

* chore(test): Add test that member locales are used in transfer gems msg

* sendMessage: optionally take also the message in sender's language

when present, it is stored in the sender's inbox instead of the version
in the target language.

* transferGems: prepare pm in both languages #7722

* sendMessage: take an object for the second parameter instead

* payments: made two more gift strings translatable

* buyGems: send both translations for gifted gems

* buyGems: send push notifications in target user's locale

* createSubscription: send both translations for gifted subs

* createSubscription: send push notifications in target user's locale

* transferGems: send push notifications in target user's locale

* tests: adjust payment tests for translation changes

* added function doc for sendMessage

* tests: added bilingual test for buyGems
This commit is contained in:
Jaka Kranjc
2016-12-16 01:36:54 +01:00
committed by Keith Holliday
parent 3f6a13d209
commit f1a3bd5001
7 changed files with 165 additions and 47 deletions

View File

@@ -5,6 +5,7 @@ import notifications from '../../../../../website/server/libs/pushNotifications'
import { model as User } from '../../../../../website/server/models/user';
import { model as Group } from '../../../../../website/server/models/group';
import moment from 'moment';
import { translate as t } from '../../../../helpers/api-v3-integration.helper';
import {
generateGroup,
} from '../../../../helpers/api-unit.helper.js';
@@ -181,9 +182,10 @@ describe('payments/index', () => {
it('sends a private message about the gift', async () => {
await api.createSubscription(data);
let msg = '\`Hello recipient, sender has sent you 3 months of subscription!\`';
expect(user.sendMessage).to.be.calledOnce;
expect(user.sendMessage).to.be.calledWith(recipient, '\`Hello recipient, sender has sent you 3 months of subscription!\`');
expect(user.sendMessage).to.be.calledWith(recipient, { receiverMsg: msg, senderMsg: msg });
});
it('sends an email about the gift', async () => {
@@ -697,14 +699,37 @@ describe('payments/index', () => {
it('sends a message from purchaser to recipient', async () => {
await api.buyGems(data);
let msg = '\`Hello recipient, sender has sent you 4 gems!\`';
expect(user.sendMessage).to.be.calledWith(recipient, '\`Hello recipient, sender has sent you 4 gems!\`');
expect(user.sendMessage).to.be.calledWith(recipient, { receiverMsg: msg, senderMsg: msg });
});
it('sends a push notification if user did not gift to self', async () => {
await api.buyGems(data);
expect(notifications.sendNotification).to.be.calledOnce;
});
it('sends gem donation message in each participant\'s language', async () => {
await recipient.update({
'preferences.language': 'es',
});
await user.update({
'preferences.language': 'cs',
});
await api.buyGems(data);
let [recipientsMessageContent, sendersMessageContent] = ['es', 'cs'].map((lang) => {
let messageContent = t('giftedGemsFull', {
username: recipient.profile.name,
sender: user.profile.name,
gemAmount: data.gift.gems.amount,
}, lang);
return `\`${messageContent}\``;
});
expect(user.sendMessage).to.be.calledWith(recipient, { receiverMsg: recipientsMessageContent, senderMsg: sendersMessageContent });
});
});
});
});