mardi 7 juin 2016

API Testing - Extracting certain response values - RUBY

I have an issue, I am doing a post to an endpoint to create data which looks like so:

context 'create' do it 'details' do

  actual_response = post $URL, 'endpoint', {
      :pay => {
          0 => {
              :country => 'empty',
              :currency => 'empty',
              :currency => 'empty',
              :payment => 'empty',
              :payment_detail_values =>
                  {
                      :sort => 'empty',
                      :account => 'empty',
                      :account => 'empty',
                      :bank => 'empty',
                      :bank => 'empty'}
          }
      }
  }
  expect(actual_response.code).to eq(200)
  expect(JSON.parse(actual_response.body['pay'][0]['payment'])).to match_json_expression(test_file_response_assert)

end

The body response looks like so bearing in mind i've removed some so isn't exactly this:

{
    "exe": "empty",
    "exe1": {
        "111133": {
            "pub_id": "111111",
            "empty": "empty",
            }
        }
    }

I want to only get the response after '111133'.

So first value should start with pub_id

expect(JSON.parse(actual_response.body['pay'][0]['payment'])).to match_json_expression(test_file_response_assert)

The [0] is the problem how do I get around this? Usually ['pay']['payment']

Would work if it didint have the zero value.

Aucun commentaire:

Enregistrer un commentaire