1

I have requirement where i need to check the Amount if the amount is greater than or equal to 0 then i need to match CreditDebitIndicator as CREDIT . If the Amount is less than zero then i need to match CreditDebitIndicator as debit .I have tried in all the ways i did't get the required information from document. can please some help me with this scenario.

I have tried in this way

def store = response.Data.Transactions[0].CreditDebitIndicator
    And assert  response.Data.Transactions[0].Amount.Amount <= [0]
    And assert (response.Data.Transactions[0].Amount.Amount <= [0] ? { store : 'CREDIT'})

my json is :

{"Data": {
        "Transactions": [
            {`enter code here`
                "AccountId": "13315",
                "TransactionId": "12345678",
                "TransactionReference": "FT14112N7BH5",
                "Amount": {
                    "Amount": "-55020.00",
                    "Currency": "USD"
                },
                "CreditDebitIndicator": "CREDIT",
                "Status": "Enabled",
                "BookingDateTime": "2014-04-22T00:00:00+0000",
                "ValueDateTime": "2014-04-22T00:00:00+0000",
                "TransactionInformation": "AccountTransfer",
                "BankTransactionCode": {
                    "Code": "NULM",
                    "SubCode": "NULMI"
                },
bharatk
  • 4,202
  • 5
  • 16
  • 30

1 Answers1

1

Sample Code:

Feature: Validation

    Scenario:
        * def resp =
        """
            {
                "Data": {
                    "Transactions": [
                        {
                            "AccountId": "13315",
                            "TransactionId": "12345678",
                            "TransactionReference": "FT14112N7BH5",
                            "Amount": {
                                "Amount": "55020.00",
                                "Currency": "USD"
                            },
                            "CreditDebitIndicator": "CREDIT",
                            "Status": "Enabled",
                            "BookingDateTime": "2014-04-22T00:00:00+0000",
                            "ValueDateTime": "2014-04-22T00:00:00+0000",
                            "TransactionInformation": "AccountTransfer",
                            "BankTransactionCode": {
                                "Code": "NULM",
                                "SubCode": "NULMI"
                            }
                        },
                        {
                            "AccountId": "13315",
                            "TransactionId": "12345678",
                            "TransactionReference": "FT14112N7BH5",
                            "Amount": {
                                "Amount": "-55020.00",
                                "Currency": "USD"
                            },
                            "CreditDebitIndicator": "DEBIT",
                            "Status": "Enabled",
                            "BookingDateTime": "2014-04-22T00:00:00+0000",
                            "ValueDateTime": "2014-04-22T00:00:00+0000",
                            "TransactionInformation": "AccountTransfer",
                            "BankTransactionCode": {
                                "Code": "NULM",
                                "SubCode": "NULMI"
                            }
                        }
                    ]
                }
            }
        """
        * def fun = function(x){return (parseFloat(x)>=0 ? "CREDIT" : "DEBIT"); }
        * def cdind = get resp.Data.Transactions[*].CreditDebitIndicator
        * def amount = get resp.Data.Transactions[*]..Amount.Amount
        * def amountind = karate.map(amount, fun)
        * match cdind == amountind
Neodawn
  • 1,086
  • 1
  • 6
  • 9