<commit_before>require 'veritrans'
require 'minitest/autorun'

class TestVeritrans < Minitest::Test

  def setup
    @mt_test = Veritrans.new(
      server_key: "<KEY>",
      client_key: "<KEY>",
      api_host: "https://api.sandbox.midtrans.com",
      logger: Logger.new(STDOUT),
      file_logger: Logger.new(STDOUT)
    )
  end

  def test_create_widget_token
    result = @mt_test.create_widget_token(
      transaction_details: {
        order_id: "THE-ITEM-ORDER-#{rand(1..10000)}",
        gross_amount: 200000
      },
      "credit_card": {
        "secure": true
      }
    )
    assert_equal 201, result.status_code
  end

  end<commit_msg>add unit test with invalid server key<commit_after>require 'veritrans'
require 'minitest/autorun'

class TestVeritrans < Minitest::Test

  def setup
    @mt_test = Veritrans.new(
      server_key: "<KEY>",
      client_key: "<KEY>",
      api_host: "https://api.sandbox.midtrans.com",
      logger: Logger.new(STDOUT),
      file_logger: Logger.new(STDOUT)
    )
  end

  def test_create_widget_token
    result = @mt_test.create_widget_token(
      transaction_details: {
        order_id: "ruby-lib-test-#{Time.now.to_i}",
        gross_amount: 200000
      },
      "credit_card": {
        "secure": true
      }
    )
    assert_equal 201, result.status_code
  end

  def test_snap_invalid_serverkey
    @mt_test_invalid_key = Veritrans.new(
      server_key: "invalid server key",
      client_key: "invalid client key",
      api_host: "https://api.sandbox.midtrans.com",
      logger: Logger.new(STDOUT),
      file_logger: Logger.new(STDOUT)
    )

    result = @mt_test_invalid_key.create_widget_token(
      transaction_details: {
        order_id: "ruby-lib-test-#{Time.now.to_i}",
        gross_amount: 200000
      },
      "credit_card": {
        "secure": true
      }
    )
    assert_equal 401, result.status_code
    assert_equal ["Access denied due to unauthorized transaction, please check client or server key", "Visit https://snap-docs.midtrans.com/#request-headers for more details"], result.error_messages
  end

  end
{'fraction_non_alphanumeric': 0.11582459485224023, 'fraction_numerical': 0.01572926596758818, 'mean_word_length': 2.837294332723949, 'pattern_counts': {'":': 6, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, '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': '1032614', 'n_tokens_mistral': 741, 'n_tokens_neox': 696, 'n_words': 134}