mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +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 `new Error()` usage in MEGA service
This commit is contained in:
parent
3b7042545a
commit
f343e73c92
@ -23,7 +23,9 @@ const labs = require('../../../shared/labs');
|
|||||||
const events = require('../../lib/common/events');
|
const events = require('../../lib/common/events');
|
||||||
|
|
||||||
const messages = {
|
const messages = {
|
||||||
invalidSegment: 'Invalid segment value. Use one of the valid:"status:free" or "status:-free" values.'
|
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'
|
||||||
};
|
};
|
||||||
|
|
||||||
const getFromAddress = () => {
|
const getFromAddress = () => {
|
||||||
@ -129,12 +131,20 @@ const addEmail = async (postModel, options) => {
|
|||||||
// `paid` and `free` were swapped out for NQL filters in 4.5.0, we shouldn't see them here now
|
// `paid` and `free` were swapped out for NQL filters in 4.5.0, we shouldn't see them here now
|
||||||
case 'paid':
|
case 'paid':
|
||||||
case 'free':
|
case 'free':
|
||||||
throw new Error(`Unexpected email_recipient_filter value "${emailRecipientFilter}", expected an NQL equivalent`);
|
throw new errors.GhostError({
|
||||||
|
message: tpl(messages.unexpectedEmailRecipientFilterError, {
|
||||||
|
emailRecipientFilter
|
||||||
|
})
|
||||||
|
});
|
||||||
case 'all':
|
case 'all':
|
||||||
filterOptions.filter = 'subscribed:true';
|
filterOptions.filter = 'subscribed:true';
|
||||||
break;
|
break;
|
||||||
case 'none':
|
case 'none':
|
||||||
throw new Error('Cannot sent email to "none" email_recipient_filter');
|
throw new errors.GhostError({
|
||||||
|
message: tpl(messages.noneEmailRecipientError, {
|
||||||
|
emailRecipientFilter
|
||||||
|
})
|
||||||
|
});
|
||||||
default:
|
default:
|
||||||
filterOptions.filter = `subscribed:true+${emailRecipientFilter}`;
|
filterOptions.filter = `subscribed:true+${emailRecipientFilter}`;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,40 @@
|
|||||||
const should = require('should');
|
const should = require('should');
|
||||||
|
const sinon = require('sinon');
|
||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
const {partitionMembersBySegment} = require('../../../../core/server/services/mega/mega');
|
|
||||||
|
const {addEmail, partitionMembersBySegment} = require('../../../../core/server/services/mega/mega');
|
||||||
|
|
||||||
describe('MEGA', function () {
|
describe('MEGA', function () {
|
||||||
|
describe('addEmail', function () {
|
||||||
|
it('addEmail throws when "free" or "paid" strings are used as a email_recipient_filter', async function () {
|
||||||
|
const postModel = {
|
||||||
|
get: sinon.stub().returns('free')
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await addEmail(postModel);
|
||||||
|
should.fail('addEmail did not throw');
|
||||||
|
} catch (err) {
|
||||||
|
should.equal(err instanceof errors.GhostError, true);
|
||||||
|
err.message.should.equal('Unexpected email_recipient_filter value "free", expected an NQL equivalent');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('addEmail throws when "none" is used as a email_recipient_filter', async function () {
|
||||||
|
const postModel = {
|
||||||
|
get: sinon.stub().returns('none')
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await addEmail(postModel);
|
||||||
|
should.fail('addEmail did not throw');
|
||||||
|
} catch (err) {
|
||||||
|
should.equal(err instanceof errors.GhostError, true);
|
||||||
|
err.message.should.equal('Cannot sent email to "none" email_recipient_filter');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('partitionMembersBySegment', function () {
|
describe('partitionMembersBySegment', function () {
|
||||||
it('partition with no segments', function () {
|
it('partition with no segments', function () {
|
||||||
const members = [{
|
const members = [{
|
||||||
|
Loading…
Reference in New Issue
Block a user