Comments (11)
@eykhagen I don't have too much of an opinion but here are the scenarios that are important from my point of view.
- Verify specific array element.
- Verify all array elements to make sure they match some value/condition.
- This might be a bit more involved since in this case most likely you want to have a condition as opposed to a fixed value.
- Verify length of array.
I think this would cover a lot of scenarios where returned things are arrays.
from strest.
I think a good start for handling arrays would be to have the ability to define an item "template" like :
validate:
json:
[array]:
name: Type(String)
age: Type(Number)
email: Type(String.Email)
Each item must match the template for the JSON to be validated.
I don't know if it's implementable but the Joi library has very advanced objects validation that would fit a lot of use case. 😄
Woops! Did not even see that Joi was already in the package.json and is already used in the lib 😁
I guess it's just a story of YAML <> Joi syntax
from strest.
P.S I really like the choice of YAML as the description of a test case. Yes, some test cases are very complex and require a lot of setup, but for the most part, 90% of basic verification tests are "check that f(x) = y" , so having a data only input like this helps simplify the whole thing. So thanks for putting this together!
from strest.
What if a joi validator is implemented:
version: 1
requests:
getStatuses:
url: http://domain.com/endpoint
method: POST
data:
json: {"foo": "bar"}
validate:
joi:
?????????
I don't know what the syntax beyond joi: would be, but this seems more explicit and potentially could handle more use cases.
from strest.
that is supported. Assuming .name is not an object. If .name is a string or number, then this functionality already exists:
https://github.com/eykrehbein/strest/blob/master/tests/success/validate/jsonpath.strest.yml
If you are trying to validate an entire array or an object, then close this issue and open a new issue with that goal.
from strest.
Apparently, this works.
validate:
json:
[0]:
gameID: 'SomePreDefiniedValue'
Is this a hacky way of doing it or is there a proper way to do it?
from strest.
@betsegaw
Unfortunately, there is no proper way to handle arrays, yet. Do you have any suggestions on how to improve this? 🤔
from strest.
Also interested in using this to validate arrays contain valid things, my response is like this :
{
"d": [{
"__type": "string",
"boolValue": false,
"descriptionString": "string",
"name": "string",
"Identifier": "string",
"shortCode": "string",
"shortName": "string",
"statusId": "string"
}]
}
So, the "d" object contains an array of objects of with the same properties. I'd like to validate that each of the objects in the array has the correct properties.
I'm able to validate that "d" is of type Array with this :
version: 1
requests:
getStatuses:
url: http://domain.com/endpoint
method: POST
headers:
"ApiKey" : "myApiKey"
data:
json: {"foo": "bar"}
validate:
json:
d: Type(Array)
log : true
But what I'd like to do is make sure each of the objects inside the "d" array is correct. Specifically I would like to avoid having to specify an array index identifier like [0] or whatever.
In the mean time, if anyone has any idea on the syntax I could use to check the first object in the "d" array I'm listening; would be good to have a further play.
from strest.
This should do what is noted in the original request
validate:
jsonpath:
$[?(@.amount==0)].amount: 0
It should be possible to use Value() in place of the 0's above.
from strest.
My suggestion for this validation:
Validade:
body.name: 'all names is the same'
and
validade:
body.0.name: 'first name is the same'
For me, this way is so good for read and write.
from strest.
that is supported. Assuming .name is not an object. If .name is a string or number, then this functionality already exists:
https://github.com/eykrehbein/strest/blob/master/tests/success/validate/jsonpath.strest.ymlIf you are trying to validate an entire array or an object, then close this issue and open a new issue with that goal.
This is it. Tks
from strest.
Related Issues (20)
- View variable information when using the `-p` switch HOT 2
- Print output when call fails HOT 1
- Printout response when running repetitive calls
- Print response with Warning when ignore error is true HOT 2
- Iterate Calls without validation
- More MimeTypes HOT 1
- Validation Rules do not work for some special values (false, 0, null, ...) HOT 1
- [Feature Request] Install locally HOT 7
- Install fails because of jsonpath postinstall HOT 8
- Run requests asynchronously HOT 3
- nunjucks escapes & characters HOT 3
- add module export to allow other services to consume results of test runs
- command 'strest.request' not found HOT 1
- Allow for validating undefined / non-existent properties in responses HOT 2
- Improve the JSON output to hold validation results
- CodeClimate integration HOT 3
- Error: Unable to call `file` HOT 1
- How to use a cookie from response in the next request? HOT 1
- Configurable Timeout
- TypeError: Cannot read property 'hex' of undefined
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from strest.