<commit_before>require 'rest_client'
require 'json'

RSpec.describe 'testing complex body params' do
  subject do
    SageoneApiRequestSigner.new({
      request_method: 'post',
      url: 'https://api.sageone.com/test/accounts/v1/contacts',
      signing_secret: 'TestSigningSecret',
      access_token: 'TestToken',
    })
  end

  let(:headers) do
    subject.request_headers.merge({
      'Accept' => '*/*',
      'Content-Type' => 'application/x-www-form-urlencoded',
      'User-Agent' => 'NPSS'
    })
  end

  it 'with multi-level hashes' do
    subject.body_params = {
      first: 'level',
      second: {
        multi: 'level',
        third: {
          level: 'the last one'
        },
        ok: 'this is enough'
      }
    }

    check_signature!
  end

  it 'with arrays' do
    subject.body_params = {
      simple: 'param',
      complex: [
        {one:11, two:12, three:13},
        {one:21, two:22, three:23},
      ]
    }
  end

  it 'hardcore one' do
    subject.body_params = {
      hardcore: [
        {one:11, two:12, three:13},
        {four:4, two:22, three:23},
        {
          fuck_all: {
            i_am: 'really nested',
            no: {
              i_am: 'damm more'
            }
          }
        }
      ]
    }
  end

  def check_signature!
    RestClient.post subject.url, subject.body_params, headers

    rescue => e
      raise e unless e.respond_to? :response<commit_msg>arrays is not supported anymore<commit_after>require 'rest_client'
require 'json'

RSpec.describe 'testing complex body params' do
  subject do
    SageoneApiRequestSigner.new({
      request_method: 'post',
      url: 'https://api.sageone.com/test/accounts/v1/contacts',
      signing_secret: 'TestSigningSecret',
      access_token: 'TestToken',
    })
  end

  let(:headers) do
    subject.request_headers.merge({
      'Accept' => '*/*',
      'Content-Type' => 'application/x-www-form-urlencoded',
      'User-Agent' => 'NPSS'
    })
  end

  it 'with multi-level hashes' do
    subject.body_params = {
      first: 'level',
      second: {
        multi: 'level',
        third: {
          level: 'the last one'
        },
        ok: 'this is enough'
      }
    }

    check_signature!
  end

  it 'with something like "arrays"' do
    subject.body_params = {
      simple: 'param',
      complex: {
        0 => {one:11, two:12, three:13},
        1 => {one:21, two:22, three:23},
      }
    }
    check_signature!
  end

  def check_signature!
    RestClient.post subject.url, subject.body_params, headers

    rescue => e
      raise e unless e.respond_to? :response
{'fraction_non_alphanumeric': 0.1308016877637131, 'fraction_numerical': 0.014959723820483314, 'mean_word_length': 2.0754716981132075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3621516', 'n_tokens_mistral': 896, 'n_tokens_neox': 862, 'n_words': 191}