vlucas / frisby

Frisby is a REST API testing framework built on Jest that makes testing API endpoints easy, fast, and fun.

Home Page:http://frisbyjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

False positives with body validation

Schoonology opened this issue · comments

I'm currently working on migrating an existing API to a new tech stack. As a part of that process I created a Frisby-based characterization test suite, and intend to test-drive the migration. However, tests are passing under two circumstances that seem incorrect to me:

  • If the Content-Type is not application/json-ish (I'm using JSON:API), such as it's blank, the test passes with a jsonTypesStrict assertion.
  • If the response body is empty but contains an appropriate Content-Type header, the test passes with a jsonTypesStrict assertion.

Are these by design? If so, how can I guarantee these tests fail when the body is the incorrect type or missing?

@Schoonology

If the Content-Type is not application/json-ish (I'm using JSON:API), such as it's blank, the test passes with a jsonTypesStrict assertion.

I think that you should test Content-Type the last. (like this test)

@Schoonology

If the response body is empty but contains an appropriate Content-Type header, the test passes with a jsonTypesStrict assertion.

Will be fixed this issue by #510.

Workaround until released.

          .expect('jsonTypesStrict', Joi.object({
            name: Joi.string(),
            email: Joi.string().email(),
            body: Joi.string()
          }).required()) // <- use required()

@H1Gdev Before I file a second issue, is this related to false positives with missing keys? I currently have a response body missing a key, and the test is passing.

@Schoonology

If JSON is undefined validator will not be an error.