I encountered an error when creating a predicate that matches the request body with type number using contains, startsWith, or endsWith. For example, when creating a predicate for the API /transfer-money with an amount that starts with 200:
predicates = {
startsWith: { amount: 200 }
}
Sending a request with an amount of 200.01 results in the following error:
{
"errors": [
{
"message": "actual.indexOf is not a function",
"name": "TypeError",
"stack": "TypeError: actual.indexOf is not a function\n at ..."
}
]
}
Modifications
I have created three new methods (contains, startsWith, endsWith) that check whether the actual type is a string. If it is not, the value is converted to a string before calling the .indexOf method.
However, I'm considering instead of allow using contains, startsWith, endsWith with type number it might be better to throw an exception and provide more understandable error messages, such as:
Type not supported for this parameter {name}. Consider using equals or matches instead.
Or maybe we could add features such as lessThan or greaterThan to support specific types of numbers. What do you think?
Description
I encountered an error when creating a predicate that matches the request body with type number using
contains
,startsWith
, orendsWith
. For example, when creating a predicate for the API/transfer-money
with an amount that starts with 200:Sending a request with an amount of 200.01 results in the following error:
Modifications
I have created three new methods (
contains
,startsWith
,endsWith
) that check whether the actual type is a string. If it is not, the value is converted to a string before calling the.indexOf
method.However, I'm considering instead of allow using
contains
,startsWith
,endsWith
with type number it might be better to throw an exception and provide more understandable error messages, such as:Or maybe we could add features such as
lessThan
orgreaterThan
to support specific types of numbers. What do you think?Details
Mountebank version 2.9.1