vow icon indicating copy to clipboard operation
vow copied to clipboard

Response Assert Json Structure

Open wardy484 opened this issue 7 years ago • 3 comments

It would be great if there was a function on the like in Laravel that allows you to verify the structure of the JSON response rather than specific value as in all case you might not be interested what really in the data want to be sure that it is present.

e.g. response.assertJSONStructure([ 'bearer', 'token', 'refreshToken ]);

Why this feature is required (specific use-cases will be appreciated)?

It's very much a nice to have. However in my case I am testing a sort of register user endpoint and expect back the auth object. I would like to verify that the token is part of the response but I generally don't care what the actual value is.

Have you tried any other work arounds?

This seems to do the job however it's not particularly clear to read. assert.containsAllKeys(response.body, ['token'])

Are you willing to work on it with little guidance?

yes

wardy484 avatar Dec 02 '18 11:12 wardy484

Hey @wardy484! 👋

This is indeed a very great feature to have. I'll happily merge a PR that provide some JSON Schema validation 👍

RomainLanz avatar Dec 09 '18 09:12 RomainLanz

Any updates?

mfgabriel92 avatar Sep 11 '19 12:09 mfgabriel92

Will start working on it as part of AdonisJs v5 release

thetutlage avatar Nov 07 '19 10:11 thetutlage