Reputation: 75
The following is the response
{ "agentID": null,
"browserData": null,
"channel": "CABLEDOTCOM",
"confidenceLevel": "HIGH",
"creditCustomAttributes": [
{
"name": "accountNumber",
"value": "8009001002003015"
},
{
"name": "alternatePhoneNumber",
"value": "7098863456"
},
{
"name": "customerType",
"value": "Residential"
},
{
"name": "ezEnrollCreditNoCredit",
"value": "NO"
},
{
"name": "houseNumber",
"value": "34"
},
{
"name": "inboundPhoneNumber",
"value": "9079963456"
},
{
"name": "installationDate",
"value": "12-12-2018"
},
{
"name": "installationTimeSlot",
"value": "11AM"
},
{
"name": "installationType",
"value": "self"
},
{
"name": "lineOfBusinessOrdered",
"value": "video,hsd"
},
{
"name": "mrcFromOrder",
"value": "$23"
},
{
"name": "operatorId",
"value": "9097"
},
{
"name": "salesId",
"value": "99998"
},
{
"name": "timezone",
"value": "EST"
},
{
"name": "workOrderDate",
"value": "12-12-2018"
},
{
"name": "workOrderNumber",
"value": "13-00-11-990-2018"
}
],
"csgLocationID": null,
"customerDetails": {
"billingAddress": {
"addressLine1": "PO BOX 445",
"addressLine2": "Apt 345",
"city": "AO",
"country": "USA",
"state": "AE",
"zipCode": "09061"
},
"currentAddress": {
"addressLine1": "PO BOX 445",
"addressLine2": "Apt 345",
"city": "AO",
"country": "USA",
"state": "AE",
"zipCode": "09061"
},
"dateOfBirth": "1975-01-01",
"driversLicense": {
},
"name": {
"firstName": "JOHN",
"lastName": "BREEN",
"middleName": "WAKEFIELD"
},
"shippingAddress": {
"addressLine1": "PO BOX 445",
"addressLine2": "Apt 345",
"city": "AO",
"country": "USA",
"state": "AE",
"zipCode": "09061"
},
"socialSecurityNumber": "666436878",
"telephoneNumber": "7818945369"
},
"customerID": null,
"customerType": "RESIDENTIAL",
"hitPreference": "HIT_WITH_NARRATIVE",
"installationType": null,
"language": null,
"lineOfBusiness": null,
"marketID": "1111",
"matchPreference": "EXACT_ONE",
"orderID": null,
"verificationStatus": {
"bureauResponse": null,
"failureReasons": [
{
"code": "ERROR",
"message": "Retriable Server Error. Response Code: 503, Response Message: Service Unavailable"
},
{
"code": "R0201",
"message": "Workflow Complete."
}
],
"status": "SUCCESS"
},
"workOrderNumber": null
}
The following is the QA_Schema
{ "agentID": null,
"browserData": null,
"channel": "CABLEDOTCOM",
"confidenceLevel": "HIGH",
"creditCustomAttributes": [
{
"name": "lineOfBusinessOrdered",
"value": "video,hsd"
},
{
"name": "timezone",
"value": "EST"
},
{
"name": "alternatePhoneNumber",
"value": "7098863456"
},
{
"name": "mrcFromOrder",
"value": "$23"
},
{
"name": "workOrderDate",
"value": "12-12-2018"
},
{
"name": "installationDate",
"value": "12-12-2018"
},
{
"name": "houseNumber",
"value": "34"
},
{
"name": "accountNumber",
"value": "8009001002003015"
},
{
"name": "ezEnrollCreditNoCredit",
"value": "NO"
},
{
"name": "customerType",
"value": "Residential"
},
{
"name": "installationType",
"value": "self"
},
{
"name": "salesId",
"value": "99998"
},
{
"name": "inboundPhoneNumber",
"value": "9079963456"
},
{
"name": "workOrderNumber",
"value": "13-00-11-990-2018"
},
{
"name": "installationTimeSlot",
"value": "11AM"
},
{
"name": "operatorId",
"value": "9097"
}
],
"csgLocationID": null,
"customerDetails": {
"age": "#ignore",
"billingAddress": {
"addressLine1": "PO BOX 445",
"addressLine2": "Apt 345",
"city": "AO",
"country": "USA",
"state": "AE",
"zipCode": "09061"
},
"currentAddress": {
"addressLine1": "PO BOX 445",
"addressLine2": "Apt 345",
"city": "AO",
"country": "USA",
"state": "AE",
"zipCode": "09061"
},
"dateOfBirth": "##string",
"driversLicense": {
},
"name": {
"firstName": "JOHN",
"lastName": "BREEN",
"middleName": "WAKEFIELD"
},
"shippingAddress": {
"addressLine1": "PO BOX 445",
"addressLine2": "Apt 345",
"city": "AO",
"country": "USA",
"state": "AE",
"zipCode": "09061"
},
"socialSecurityNumber": "#ignore",
"telephoneNumber": "7818945369"
},
"customerID": null,
"customerType": "RESIDENTIAL",
"hitPreference": "HIT_WITH_NARRATIVE",
"installationType": null,
"language": null,
"lineOfBusiness": null,
"marketID": "1111",
"matchPreference": "EXACT_ONE",
"orderID": null,
"verificationStatus": {
"bureauResponse": null,
"failureReasons": [
{
"code": "ERROR",
"message": "Retriable Server Error. Response Code: 503, Response Message: Service Unavailable"
},
{
"code": "R0201",
"message": "Workflow Complete."
}
],
"status": "SUCCESS"
},
"workOrderNumber": null
}
If you compare these 2 manually, both are exactly the same. But only difference is the order. Both are in different order.
So when I do
if there is no way, should I sort the array with in alphabetical order and then do the assertion?
Upvotes: 1
Views: 228
Reputation: 2255
@GopalSubramanian - You can do this in two ways:
....
* match response.creditCustomAtributes.#[]
## OR is you also want to check the size of arry but do not care about values then
* match response.creditCustomAttributes.#[10] ## ensures that there are 10 array values
See documentation here - https://github.com/karatelabs/karate#schema-validation
Upvotes: 1
Reputation: 58058
When you have nesting, always try to do a match
on parts of your JSON. How you divide that is up to you.
I have simplified your complex dump into a simple example. But you will get the idea here:
Feature:
Scenario:
* def response =
"""
{
"channel": "CABLEDOTCOM",
"creditCustomAttributes": [
{
"name": "timezone",
"value": "EST"
},
{
"name": "lineOfBusinessOrdered",
"value": "video,hsd"
}
]
}
"""
* def expected =
"""
{
"channel": "CABLEDOTCOM",
"creditCustomAttributes": "#array",
}
"""
* match response == expected
* match response.creditCustomAttributes contains only
"""
[
{
"name": "lineOfBusinessOrdered",
"value": "video,hsd"
},
{
"name": "timezone",
"value": "EST"
}
]
"""
Please spend some time studying other answers if needed:
https://stackoverflow.com/a/68789345/143475
https://stackoverflow.com/a/65036047/143475
Upvotes: 0