kant kodali
08/07/2024, 5:03 AM"response": {
"status": 200,
"jsonBody": {
"weekly_rate": "{{randomDecimal lower=100.00 upper=800.00}}",
"max_amount": "{{randomDecimal lower=5000.00 upper=20000.00}}"
},
"transformers": ["response-template"]
}
and I get this response
{
"weekly_rate": "220.87939761296946",
"max_amount": "8860.916637737479"
}
Two issues
1. The numbers have more than 2 decimal places so the precision is not respected.
2. the numbers are strings instead of numericGradito Tunggulcahyo
08/07/2024, 6:51 AM"response": {
"status": 200,
"jsonBody": {
"weekly_rate": {{randomDecimal lower=100.00 upper=800.00}},
"max_amount": {{randomDecimal lower=5000.00 upper=20000.00}}
},
"transformers": ["response-template"]
}
even tho the json will look like error, but it works, just tryGradito Tunggulcahyo
08/07/2024, 7:16 AM"weekly_rate": {{randomInt lower=100 upper=800}}.{{randomInt lower=1 upper=9}}{{randomInt lower=1 upper=9}}
Lee Turner
08/07/2024, 8:15 AMbody
element instead of the jsonBody
element to make sure the numeric values work.Lee Turner
08/07/2024, 8:15 AMkant kodali
08/07/2024, 8:52 AMUnexpected character ('{' (code 123)): was expecting double-quote to start field name
kant kodali
08/07/2024, 8:55 AM"body": "{\n \"weekly_rate\": {{randomDecimal lower=100.00 upper=800.00}},\n \"max_amount\": {{pickRandom 5000.01 10000.02 15000.03 20000.04}}\n}"
even randomDecimal lower and upper cannot seem to respect the precision at all. In short this framework is just terrible.Lee Turner
08/07/2024, 9:06 AMjsonBody
can handle numeric values but not when you are using templating to generate those values. This is nothing to do with the framework, this is just basic json. Anything that makes the json invalid isn't going to work and adding {{
to generate a numeric value is always going to be invalid json. There are many ways around this using body
or bodyFileName
.
The random decimal precision does seem to be a limitation of the handlebars helper. I'll add an issue and see if we can do something about that for the next release.kant kodali
08/07/2024, 9:08 AMkant kodali
08/07/2024, 9:11 AMkant kodali
08/07/2024, 9:13 AMLee Turner
08/07/2024, 9:24 AM{{numberFormat (randomDecimal lower=100.00 upper=800.00) '###.00' 'en_GB'}}
kant kodali
08/07/2024, 9:35 AM"jsonBody": {
"weekly_rate": "{{numberFormat (randomDecimal lower=100.00 upper=800.00) '###.00' 'en_GB'}}",
"max_amount": "{{numberFormat (randomDecimal lower=5000.00 upper=20000.00) '###.00' 'en_GB'}}"
},
kant kodali
08/07/2024, 9:35 AMkant kodali
08/07/2024, 9:36 AMkant kodali
08/07/2024, 9:41 AM{
"weekly_rate": "583.14",
"max_amount": "13682.04"
}
I am looking for
{"weekly_rate":583.14,max_amount":13682.04}
Lee Turner
08/07/2024, 9:54 AMjsonBody
element won't support this as it is expecting it to be valid json. You can either switch to the body
element like you have above or extract the body out into a separate file using the bodyFileName
element:
{
"request": {
"method": "GET",
"url": "/basic"
},
"response": {
"status": 200,
"bodyFileName": "basic.txt",
"transformers": [
"response-template"
]
}
}
Then basic.txt
needs to be stored in the __files
directory and can look like this:
{
"weekly_rate": {{numberFormat (randomDecimal lower=100.00 upper=800.00) '###.00' 'en_GB'}},
"max_amount": {{numberFormat (randomDecimal lower=5000.00 upper=20000.00) '###.00' 'en_GB'}}
}
This should then generate a response like this:
{
"weekly_rate": 573.97,
"max_amount": 16922.91
}
kant kodali
08/07/2024, 10:04 AM{
"jsonBody": {
"weekly_rate": "{{randomDecimal lower=100.00 upper=800.00 output_type='NUMERIC'}}"
}
}
This is a valid json and the output type is clear. so its really all about how well the wiremock templating protocol is designed. I think things have to change therekant kodali
08/07/2024, 10:04 AMLee Turner
08/07/2024, 10:07 AM