-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: STRF-9707 Improve money helper to support input params #164
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const Lab = require('lab'); | ||
const { expect } = require('code'); | ||
const lab = exports.lab = Lab.script(); | ||
const describe = lab.experiment; | ||
const it = lab.it; | ||
const { testRunner, renderString } = require('../spec-helpers'); | ||
|
||
describe('money helper', function() { | ||
const context = { | ||
price: 1234.56, | ||
}; | ||
const siteSettings = { | ||
money: { | ||
currency_location: "left", | ||
currency_token: "$", | ||
decimal_places: 2, | ||
thousands_token: ',', | ||
decimal_token: '.', | ||
} | ||
}; | ||
|
||
|
||
it('should correctly set money value from money site settings', function(done) { | ||
const runTestCases = testRunner({context, siteSettings}); | ||
runTestCases([ | ||
{ | ||
input: '{{money price}}', | ||
output: '$ 1,234.56', | ||
}, | ||
{ | ||
input: '{{money 12.34}}', | ||
output: '$ 12.34', | ||
}, | ||
], done); | ||
}); | ||
|
||
it('should read money site settings from input parameters', function(done) { | ||
const runTestCases = testRunner({context, siteSettings}); | ||
runTestCases([ | ||
{ | ||
input: '{{money price 1}}', | ||
output: '$ 1,234.6', | ||
}, | ||
{ | ||
input: '{{money price 3}}', | ||
output: '$ 1,234.560', | ||
}, | ||
{ | ||
input: '{{money price 2 "."}}', | ||
output: '$ 1.234.56', | ||
}, | ||
{ | ||
input: '{{money price 2 "," ","}}', | ||
output: '$ 1,234,56', | ||
}, | ||
], done); | ||
}); | ||
|
||
it('should throw an exception if the price value parameter has an invalid type', function(done) { | ||
renderString('{{money "hello"}}').catch(err => { | ||
expect(err.message).to.equal("money helper accepts only Number's as first parameter"); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should throw an exception if the decimal places parameter has an invalid type', function(done) { | ||
renderString('{{money 1.2 "hello"}}').catch(err => { | ||
expect(err.message).to.equal("money helper accepts only Number's for decimal places"); | ||
done(); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we able to exclude this by doing something like
return function(options, ...args)
to pull out the first param as "options" and just use the remaining inargs
to avoid this step?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really, cause I'm removing the last parameter, rather then the first one.
So it should be like
return function(...args, options)
, but this kind of syntax is not supported 😒There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it necessary to remove this at all, since we're just accessing the other elements by
args[0]
etc, wont those indexes be the same regardless if the last element in present?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmwiese the thing is that number of arguments may vary. Just to be sure, that hash object (that has handlebars utility functions) was removed, I'm using a
pop()
. We are also using same approach in other helpers, to actually read that hash object by assigning it to a variable.