0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00
ghost/core/test/unit/helpers/price_spec.js
Naz Gargol 07e1a2406b Added {{price}} helper for formatting stripe amounts (ie. "1935" to "19.35") (#11473)
no issue

- This helper allows to format currencies that use decimal normalization. For example 19.35 USD is served as 1935 from the API which always needs to be divided by 100 to get a dollar ammount.
2020-01-27 11:41:12 +00:00

46 lines
1.3 KiB
JavaScript

const should = require('should');
const helpers = require.main.require('core/frontend/helpers');
const handlebars = require.main.require('core/frontend/services/themes/engine').handlebars;
function compile(templateString) {
const template = handlebars.compile(templateString);
template.with = (locals = {}, globals) => {
return template(locals, globals);
};
return template;
}
describe('{{price}} helper', function () {
before(function () {
handlebars.registerHelper('price', helpers.price);
});
it('throws an error for no provided parameters', function () {
(function compileWith() {
compile('{{price}}')
.with({});
}).should.throw();
});
it('throws an error for undefined parameter', function () {
(function compileWith() {
compile('{{price @dont.exist}}')
.with({});
}).should.throw();
});
it('throws if argument is not a number', function () {
(function compileWith() {
compile('{{price "not_a_number"}}')
.with({});
}).should.throw();
});
it('will format decimal adjusted amount', function () {
compile('{{price 2000}}')
.with({})
.should.equal('20');
});
});