diff --git a/ghost/limit-service/lib/limit.js b/ghost/limit-service/lib/limit.js index 6edab24f1f..5be33cf4fb 100644 --- a/ghost/limit-service/lib/limit.js +++ b/ghost/limit-service/lib/limit.js @@ -42,19 +42,22 @@ class MaxLimit extends Limit { generateError(count) { let errorObj = super.generateError(); - let max = this.max; errorObj.message = this.fallbackMessage; if (this.error) { try { - errorObj.message = _.template(this.error)({max, count}); + errorObj.message = _.template(this.error)( + { + max: Intl.NumberFormat().format(this.max), + count: Intl.NumberFormat().format(count) + }); } catch (e) { errorObj.message = this.fallbackMessage; } } - errorObj.errorDetails.limit = max; + errorObj.errorDetails.limit = this.max; errorObj.errorDetails.total = count; return new errors.HostLimitError(errorObj); diff --git a/ghost/limit-service/test/limit-service.test.js b/ghost/limit-service/test/limit-service.test.js new file mode 100644 index 0000000000..19c1031dd4 --- /dev/null +++ b/ghost/limit-service/test/limit-service.test.js @@ -0,0 +1,28 @@ +// Switch these lines once there are useful utils +// const testUtils = require('./utils'); +require('./utils'); + +describe('Limit Service', function () { + describe('Lodash Template', function () { + it('Does not get clobbered by this lib', function () { + require('../lib/limit'); + let _ = require('lodash'); + + _.templateSettings.interpolate.should.eql(/<%=([\s\S]+?)%>/g); + }); + }); + + describe('Error Messages', function () { + it('Formats numbers correctly', function () { + const {MaxLimit} = require('../lib/limit'); + + let limit = new MaxLimit({name: 'test', config: {max: 35000000, currentCountQuery: () => {}, error: 'Your plan supports up to {{max}} staff users. Please upgrade to add more.'}}); + + let error = limit.generateError(35000001); + + error.message.should.eql('Your plan supports up to 35,000,000 staff users. Please upgrade to add more.'); + error.errorDetails.limit.should.eql(35000000); + error.errorDetails.total.should.eql(35000001); + }); + }); +}); diff --git a/ghost/limit-service/test/template.test.js b/ghost/limit-service/test/template.test.js deleted file mode 100644 index 9af1622970..0000000000 --- a/ghost/limit-service/test/template.test.js +++ /dev/null @@ -1,12 +0,0 @@ -// Switch these lines once there are useful utils -// const testUtils = require('./utils'); -require('./utils'); - -describe('Lodash Template', function () { - it('Does not get clobbered by this lib', function () { - require('../lib/limit'); - let _ = require('lodash'); - - _.templateSettings.interpolate.should.eql(/<%=([\s\S]+?)%>/g); - }); -});