mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 03:44:29 +03:00
Removed use of deprecated new Error() syntax
refs2f1123d6ca
refs6f1a3e1774
- As per refed commits, we are removing deprecated use of `new Error()` in the codebase - This bit cleans up the rest of `new Error()` usage in MEGA service
This commit is contained in:
parent
b045112950
commit
5ea8e9b926
@ -25,7 +25,9 @@ const events = require('../../lib/common/events');
|
||||
const messages = {
|
||||
invalidSegment: 'Invalid segment value. Use one of the valid:"status:free" or "status:-free" values.',
|
||||
unexpectedEmailRecipientFilterError: 'Unexpected email_recipient_filter value "{emailRecipientFilter}", expected an NQL equivalent',
|
||||
noneEmailRecipientError: 'Cannot sent email to "none" email_recipient_filter'
|
||||
noneEmailRecipientFilterError: 'Cannot sent email to "none" email_recipient_filter',
|
||||
unexpectedRecipientFilterError: 'Unexpected recipient_filter value "{recipientFilter}", expected an NQL equivalent',
|
||||
noneRecipientFileterError: 'Cannot sent email to "none" recipient_filter'
|
||||
};
|
||||
|
||||
const getFromAddress = () => {
|
||||
@ -141,7 +143,7 @@ const addEmail = async (postModel, options) => {
|
||||
break;
|
||||
case 'none':
|
||||
throw new errors.GhostError({
|
||||
message: tpl(messages.noneEmailRecipientError, {
|
||||
message: tpl(messages.noneEmailRecipientFilterError, {
|
||||
emailRecipientFilter
|
||||
})
|
||||
});
|
||||
@ -352,12 +354,18 @@ async function getEmailMemberRows({emailModel, memberSegment, options}) {
|
||||
// `paid` and `free` were swapped out for NQL filters in 4.5.0, we shouldn't see them here now
|
||||
case 'paid':
|
||||
case 'free':
|
||||
throw new Error(`Unexpected recipient_filter value "${recipientFilter}", expected an NQL equivalent`);
|
||||
throw new errors.GhostError({
|
||||
message: tpl(messages.unexpectedRecipientFilterError, {
|
||||
recipientFilter
|
||||
})
|
||||
});
|
||||
case 'all':
|
||||
filterOptions.filter = 'subscribed:true';
|
||||
break;
|
||||
case 'none':
|
||||
throw new Error('Cannot sent email to "none" recipient_filter');
|
||||
throw new errors.GhostError({
|
||||
message: tpl(messages.noneRecipientFileterError)
|
||||
});
|
||||
default:
|
||||
filterOptions.filter = `subscribed:true+${recipientFilter}`;
|
||||
}
|
||||
@ -534,7 +542,8 @@ module.exports = {
|
||||
sendTestEmail,
|
||||
handleUnsubscribeRequest,
|
||||
// NOTE: below are only exposed for testing purposes
|
||||
_partitionMembersBySegment: partitionMembersBySegment
|
||||
_partitionMembersBySegment: partitionMembersBySegment,
|
||||
_getEmailMemberRows: getEmailMemberRows
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,7 @@ const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
const errors = require('@tryghost/errors');
|
||||
|
||||
const {addEmail, _partitionMembersBySegment} = require('../../../../core/server/services/mega/mega');
|
||||
const {addEmail, _partitionMembersBySegment, _getEmailMemberRows} = require('../../../../core/server/services/mega/mega');
|
||||
|
||||
describe('MEGA', function () {
|
||||
describe('addEmail', function () {
|
||||
@ -35,6 +35,36 @@ describe('MEGA', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getEmailMemberRows', function () {
|
||||
it('addEmail throws when "free" or "paid" strings are used as a recipient_filter', async function () {
|
||||
const emailModel = {
|
||||
get: sinon.stub().returns('paid')
|
||||
};
|
||||
|
||||
try {
|
||||
await _getEmailMemberRows({emailModel});
|
||||
should.fail('getEmailMemberRows did not throw');
|
||||
} catch (err) {
|
||||
should.equal(err instanceof errors.GhostError, true);
|
||||
err.message.should.equal('Unexpected recipient_filter value "paid", expected an NQL equivalent');
|
||||
}
|
||||
});
|
||||
|
||||
it('addEmail throws when "none" is used as a recipient_filter', async function () {
|
||||
const emailModel = {
|
||||
get: sinon.stub().returns('none')
|
||||
};
|
||||
|
||||
try {
|
||||
await _getEmailMemberRows({emailModel});
|
||||
should.fail('getEmailMemberRows did not throw');
|
||||
} catch (err) {
|
||||
should.equal(err instanceof errors.GhostError, true);
|
||||
err.message.should.equal('Cannot sent email to "none" recipient_filter');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('partitionMembersBySegment', function () {
|
||||
it('partition with no segments', function () {
|
||||
const members = [{
|
||||
|
Loading…
Reference in New Issue
Block a user