Hello,
I have a API response where I want to search for a entry and validate against the value in my data sheet. The below tests work fine to do that except that if one of the entry does not get list the test will not highlight the missing entry.
Test flow:
- Search the Entire array where to find a block that contains ACCOUNTTITLE = “Inventory” and TR_TYPE=1 within it
- If the above combination is not found in the response notify the missing entry
Any suggestion would be helpful. Thanks in advance.
JSON Response:
[
{
"BATCHNO": "1",
"ENTRY_DATE": "02/01/2020",
"TR_TYPE": "1",
"ACCOUNTNO": "1400",
"ACCOUNTTITLE": "Inventory",
"TRX_AMOUNT": "716.11",
"AMOUNT": "776.82"
},
{
"BATCHNO": "1",
"ENTRY_DATE": "02/01/2020",
"TR_TYPE": "1",
"ACCOUNTNO": "5005",
"ACCOUNTTITLE": "Purchase Tax Paid",
"TRX_AMOUNT": "143.22",
"AMOUNT": "155.36"
},
{
"BATCHNO": "1",
"ENTRY_DATE": "02/01/2020",
"TR_TYPE": "-1",
"ACCOUNTNO": "2000",
"ACCOUNTTITLE": "Accounts Payable",
"TRX_AMOUNT": "859.33",
"AMOUNT": "932.18"
}
]
**Tests:**
var jsonData = JSON.parse(responseBody); //Parse the JSON responseBody
var glAccounts = [data.je_sales_tax_credit, data.je_accs_payable_credit, data.je_purchase_tax_debit, data.je_purchase_tax_credit, data.jeInventoryDebit, data.jeInventoryCredit, data.jeInventoryHardwareCredit, data.jeInventoryHardwareDebit];
//Get the total count of the number of Journal Entries
var jeCount = jsonData.length;
tests["Verify total number of Journal Entries listed : " + jeCount] = jeCount === data.resultCount;
//Check if Inventory Account needs to be debited
if (data.jeInventoryDebit !== "")
//Search through the API response for ACCOUNTTITLE
for (je = 0; je < jeCount; je++) {
var accountTitle = jsonData[je].ACCOUNTTITLE;
var transactionType = jsonData[je].TR_TYPE;
if (accountTitle == "Inventory" && transactionType == "1") {
tests["Verify Inventory - Transaction Amount Debited : " + jsonData[je].TRX_AMOUNT] = jsonData[je].TRX_AMOUNT === "" + data.jeInventoryDebit + "";
break;
}
}