Giter Site home page Giter Site logo

Comments (11)

betsegaw avatar betsegaw commented on July 29, 2024 2

@eykhagen I don't have too much of an opinion but here are the scenarios that are important from my point of view.

  1. Verify specific array element.
  2. 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.
  3. Verify length of array.

I think this would cover a lot of scenarios where returned things are arrays.

from strest.

Paic avatar Paic commented on July 29, 2024 1

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.

betsegaw avatar betsegaw commented on July 29, 2024 1

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.

jgroom33 avatar jgroom33 commented on July 29, 2024 1

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.

jgroom33 avatar jgroom33 commented on July 29, 2024 1

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.

betsegaw avatar betsegaw commented on July 29, 2024

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.

eykrehbein avatar eykrehbein commented on July 29, 2024

@betsegaw
Unfortunately, there is no proper way to handle arrays, yet. Do you have any suggestions on how to improve this? 🤔

from strest.

lchallis avatar lchallis commented on July 29, 2024

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.

jgroom33 avatar jgroom33 commented on July 29, 2024

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.

GedersonChiquesi avatar GedersonChiquesi commented on July 29, 2024

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.

GedersonChiquesi avatar GedersonChiquesi commented on July 29, 2024

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.

This is it. Tks

from strest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.