1

Friends, From this situation I am taking the following error response:
FAIL Check value is either 1 or 2 | TypeError: Cannot read properties of undefined (reading 'gender')
FAIL Check value fullName | TypeError: Cannot read properties of undefined (reading 'fullName')

const response = pm.response.json();
    
pm.test("Check value is either 1 or 2", function() {
    pm.expect(response.naturalPerson.gender).to.be.oneOf([1, 2]);
});

pm.test("Check value fullName", function() {
    pm.expect(response.naturalPerson.fullName).to.eql("Bia Teste");
});
{
   "party":{
      "partyId":1555,
      "partyExternalId":"0",
      "partyType":1,
      "partyIdentification":{
         "partyIdentificationType":1,
         "documentNumber":"16250560017"
      },
      "naturalPerson":{
         "fullName":"Bia Teste",
         "gender":2,
         "pronoun":1,
         "maritalStatus":{
            "maritalStatusSituation":2
         },
         "filiation":{
            "fullNameFirstFiliation":"Ana Souza",
            "firstFiliationType":1,
            "fullNameSecondFiliation":"João Souza",
            "secondFiliationType":2
         },

enter image description here

Christian Baumann
  • 3,188
  • 3
  • 20
  • 37
Staulik
  • 19
  • 1
  • 5
  • Should `response.naturalPerson.gender` not be: `response.party.naturalPerson.gender`. ?? – Luuk Apr 04 '23 at 17:13

1 Answers1

0

You forgot the party in your JSON path, the following will do:

pm.test("Check value is either 1 or 2", function() {
    pm.expect(response.party.naturalPerson.gender).to.be.oneOf([1, 2]);
});

pm.test("Check value fullName", function() {
    pm.expect(response.party.naturalPerson.fullName).to.eql("Bia Teste");
});
Christian Baumann
  • 3,188
  • 3
  • 20
  • 37