vendredi 14 septembre 2018

Postman test - object's schema

I have a response body:

{
    "Id": 15,
    "Name": "Carrier1",
    "Fein": "Fein1",
    "McNumber": "McNumber1",
    "DotNumber": "DotNumber1",
    "Address": {
        "Street": "Street1",
        "City": "City1",
        "ZipPostalCode": null,
        "StateName": "AA (Armed Forces Americas)",
        "StateAbbr": "AA",
        "ContactName": null,
        "ContactPhone": null,
        "ContactFaxNumber": null,
        "ContactEmail": null
    }
}

I use Postman and want to describe schema for validation in tests:

const schema = {
  "required": ["Id"],
  "properties": {
    "Id": {
      "type": "integer",
    },
    "Name": {
      "type": "string",
    },
    "Fein": {
      "type": "string",
    },
    "McNumber": {
      "type": "string",
    },
    "DotNumber": {
      "type": "string",
    },
    "Address": {
        "type" : {
            "properties": {
                "Street": {
                "type": "string",
                },            
            },
        }
    }
  }
};

var carrier = JSON.parse(responseBody);
tests["Carrier is valid"] = tv4.validate(carrier, schema);

but it does not work. Validation that it just should be object:

"Address": {
    "type" : "object"
    }

works fine. How to describe it details?

Aucun commentaire:

Enregistrer un commentaire