Merge branch 'develop' into exbook2_electric_boogaloo

This commit is contained in:
Phillip Thelen
2021-12-16 15:08:39 +01:00
committed by GitHub
9780 changed files with 25848 additions and 23233 deletions
+57
View File
@@ -0,0 +1,57 @@
/* eslint-disable global-require */
import nconf from 'nconf';
import { generateUser } from '../../../helpers/api-unit.helper';
import * as emailLib from '../../../../website/server/libs/email';
import { bugReportLogic } from '../../../../website/server/libs/bug-report';
describe('bug-report', () => {
beforeEach(() => {
sandbox.stub(emailLib, 'sendTxn').returns(Promise.resolve());
const nconfGetStub = sandbox.stub(nconf, 'get');
nconfGetStub.withArgs('ADMIN_EMAIL').returns('true');
});
afterEach(() => {
sandbox.restore();
});
it('sends a mail using sendTxn', async () => {
const userId = '2b58daeb-bc50-4a83-b5d3-4ac52c7c0608';
const userMail = 'me@me.com';
const userMessage = 'The power is over 9000, please fix it';
const userAgent = 'The UserAgent with a bunch of weird browser engine levels';
const user = generateUser({
_id: userId,
});
const result = await bugReportLogic(
user, userMail, userMessage, userAgent,
);
expect(emailLib.sendTxn).to.be.called;
expect(result).to.deep.equal({
sendMailResult: undefined,
emailData: {
BROWSER_UA: userAgent,
REPORT_MSG: userMessage,
USER_CLASS: 'warrior',
USER_CONSECUTIVE_MONTHS: 0,
USER_COSTUME: 'false',
USER_CUSTOMER_ID: undefined,
USER_CUSTOM_DAY: 0,
USER_DAILIES_PAUSED: 'false',
USER_EMAIL: userMail,
USER_HOURGLASSES: 0,
USER_ID: userId,
USER_LEVEL: 1,
USER_OFFSET_MONTHS: 0,
USER_PAYMENT_PLATFORM: undefined,
USER_SUBSCRIPTION: undefined,
USER_TIMEZONE_OFFSET: 0,
USER_USERNAME: undefined,
},
});
});
});
+73 -18
View File
@@ -123,9 +123,18 @@ describe('emails', () => {
});
});
describe('sendTxnEmail', () => {
describe('sendTxn', () => {
let sendTxn = null;
beforeEach(() => {
sandbox.stub(got, 'post').returns(defer().promise);
const nconfGetStub = sandbox.stub(nconf, 'get');
nconfGetStub.withArgs('IS_PROD').returns(true);
nconfGetStub.withArgs('BASE_URL').returns('BASE_URL');
const attachEmail = requireAgain(pathToEmailLib);
sendTxn = attachEmail.sendTxn;
});
afterEach(() => {
@@ -133,16 +142,14 @@ describe('emails', () => {
});
it('can send a txn email to one recipient', () => {
sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(true);
const attachEmail = requireAgain(pathToEmailLib);
const sendTxnEmail = attachEmail.sendTxn;
const emailType = 'an email type';
const mailingInfo = {
name: 'my name',
email: 'my@email',
};
sendTxnEmail(mailingInfo, emailType);
sendTxn(mailingInfo, emailType);
expect(got.post).to.be.called;
expect(got.post).to.be.calledWith('undefined/job', sinon.match({
json: {
data: {
@@ -154,27 +161,77 @@ describe('emails', () => {
});
it('does not send email if address is missing', () => {
sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(true);
const attachEmail = requireAgain(pathToEmailLib);
const sendTxnEmail = attachEmail.sendTxn;
const emailType = 'an email type';
const mailingInfo = {
name: 'my name',
// email: 'my@email',
};
sendTxnEmail(mailingInfo, emailType);
sendTxn(mailingInfo, emailType);
expect(got.post).not.to.be.called;
});
it('throws error when mail target is only a string', () => {
const emailType = 'an email type';
const mailingInfo = 'my email';
expect(sendTxn(mailingInfo, emailType)).to.throw;
});
it('throws error when mail target has no _id or email', () => {
const emailType = 'an email type';
const mailingInfo = {
};
expect(sendTxn(mailingInfo, emailType)).to.throw;
});
it('throws error when variables not an array', () => {
const emailType = 'an email type';
const mailingInfo = {
name: 'my name',
email: 'my@email',
};
const variables = {};
expect(sendTxn(mailingInfo, emailType, variables)).to.throw;
});
it('throws error when variables array not contain name/content', () => {
const emailType = 'an email type';
const mailingInfo = {
name: 'my name',
email: 'my@email',
};
const variables = [
{
},
];
expect(sendTxn(mailingInfo, emailType, variables)).to.throw;
});
it('throws no error when variables array contain name but no content', () => {
const emailType = 'an email type';
const mailingInfo = {
name: 'my name',
email: 'my@email',
};
const variables = [
{
name: 'MY_VAR',
},
];
expect(sendTxn(mailingInfo, emailType, variables)).to.not.throw;
});
it('uses getUserInfo in case of user data', () => {
sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(true);
const attachEmail = requireAgain(pathToEmailLib);
const sendTxnEmail = attachEmail.sendTxn;
const emailType = 'an email type';
const mailingInfo = getUser();
sendTxnEmail(mailingInfo, emailType);
sendTxn(mailingInfo, emailType);
expect(got.post).to.be.called;
expect(got.post).to.be.calledWith('undefined/job', sinon.match({
json: {
data: {
@@ -186,17 +243,15 @@ describe('emails', () => {
});
it('sends email with some default variables', () => {
sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(true);
const attachEmail = requireAgain(pathToEmailLib);
const sendTxnEmail = attachEmail.sendTxn;
const emailType = 'an email type';
const mailingInfo = {
name: 'my name',
email: 'my@email',
};
const variables = [1, 2, 3];
const variables = [];
sendTxnEmail(mailingInfo, emailType, variables);
sendTxn(mailingInfo, emailType, variables);
expect(got.post).to.be.called;
expect(got.post).to.be.calledWith('undefined/job', sinon.match({
json: {
data: {
+3 -3
View File
@@ -268,14 +268,14 @@ describe('payments/index', () => {
context('Active Promotion', () => {
beforeEach(() => {
sinon.stub(worldState, 'getCurrentEvent').returns({
sinon.stub(worldState, 'getCurrentEventList').returns([{
...common.content.events.winter2021Promo,
event: 'winter2021',
});
}]);
});
afterEach(() => {
worldState.getCurrentEvent.restore();
worldState.getCurrentEventList.restore();
});
it('creates a gift subscription for purchaser and recipient if none exist', async () => {
@@ -74,7 +74,6 @@ describe('PUT /challenges/:challengeId', () => {
expect(res.memberCount).to.equal(2);
expect(res.tasksOrder).not.to.equal('new order');
expect(res.official).to.equal(false);
expect(res.shortName).not.to.equal('new short name');
expect(res.leader).to.eql({
_id: user._id,
+49
View File
@@ -0,0 +1,49 @@
import {
generateUser,
} from '../../helpers/api-integration/v4';
describe('POST /bug-report', () => {
let user;
beforeEach(async () => {
user = await generateUser();
});
it('returns an error when message is not added', async () => {
await expect(user.post('/bug-report', {
message: '',
}))
.to.eventually.be.rejected.and.to.eql({
code: 400,
error: 'BadRequest',
// seems it is not possible to get the real error message
message: 'Invalid request parameters.',
});
});
it('returns an error when email is not added', async () => {
await expect(user.post('/bug-report', {
message: 'message',
email: '',
}))
.to.eventually.be.rejected.and.to.eql({
code: 400,
error: 'BadRequest',
// seems it is not possible to get the real error message
message: 'Invalid request parameters.',
});
});
it('returns an error when email is not valid', async () => {
await expect(user.post('/bug-report', {
message: 'message',
email: 'notamail',
}))
.to.eventually.be.rejected.and.to.eql({
code: 400,
error: 'BadRequest',
// seems it is not possible to get the real error message
message: 'Invalid request parameters.',
});
});
});