<commit_before># frozen_string_literal: true

require "test_helper"

# Transactions Controller Test
class TransactionsControllerTest < ActionController::TestCase
  ############################################################################### GET /accounts/:account_id/transactions
  test "should get index" do
    get_index       @some_account
    assert_response :success
  end

  test "should not get index - hacker way" do
    get_index            @some_wrong_account
    assert_redirected_to dashboard_url
  end

  test "should not get index - unknow account" do
    get_index            @unknow_account
    assert_redirected_to dashboard_url
  end

  ########################################################################### GET /accounts/:account_id/transactions/new
  test "should get new" do
    get_new         @some_account
    assert_response :success
  end

  test "should not get new - hacker way" do
    get_new              @some_wrong_account
    assert_redirected_to dashboard_url
  end

  test "should not get new - unknow account" do
    get_new              @unknow_account
    assert_redirected_to dashboard_url
  end

  ########################################################################################### GET /transactions/:id/edit
  # TODO: fix
  test "should get edit" do
    get_edit        @some_transaction
    assert_response :success
  end

  test "should not get edit - hacker way" do
    get_edit             @some_wrong_transaction
    assert_redirected_to dashboard_url
  end

  test "should not get edit - unknow transaction" do
    get_edit             @unknow_transaction
    assert_redirected_to dashboard_url
  end

  ############################################################################## POST /accounts/:account_id/transactions
  test "should create transaction" do
    assert_difference("Transaction.count") do
      post_create          @some_account
      assert_redirected_to account_transactions_path @some_account
      assert_equal         I18n.t("transactions.create.successfully_created"), flash[:notice]
    end
  end

  test "should not create transaction - hacker way" do
    assert_no_difference("Transaction.count") do
      post_create          @some_wrong_account
      assert_redirected_to dashboard_url
    end
  end

  ########################################################################################## PATCH/PUT /transactions/:id
  # TODO: fix
  test "should update transaction" do
    patch_update         @some_transaction
    assert_redirected_to account_transactions_path @some_account
    assert_equal         I18n.t("transactions.update.successfully_updated"), flash[:notice]
    assert_not_equal     @previous_transaction_amount, @some_transaction.reload.amount
  end

  test "should not update transaction - hacker way" do
    patch_update         @some_wrong_transaction
    assert_redirected_to dashboard_url
    assert_equal         @previous_transaction_amount,
                         @some_wrong_transaction.reload.amount
  end

  ############################################################################################# DELETE /transactions/:id
  # TODO: fix
  test "should destroy transaction" do
    assert_difference("Transaction.count", -1) do
      delete_destroy       @some_transaction
      assert_redirected_to account_transactions_path(@some_account)
      assert_equal         I18n.t("transactions.destroy.successfully_destroyed"), flash[:notice]
    end
  end

  test "should not destroy transaction - hacker way" do
    assert_no_difference "Transaction.count" do
      delete_destroy       @some_wrong_transaction
      assert_redirected_to dashboard_url
    end
  end

  ##################################################################################### POST /transactions/:id/easycheck
  # TODO: fix
  test "should easycheck transaction" do
    post_easycheck       @some_transaction
    assert_redirected_to account_transactions_path(@some_account)
    assert_equal         I18n.t("transactions.easycheck.successfully_checked"), flash[:notice]
    assert_not_equal     @previous_status, @some_transaction.reload.checked<commit_msg>redirect_back is use in transaction controller<commit_after># frozen_string_literal: true

require "test_helper"

# Transactions Controller Test
class TransactionsControllerTest < ActionController::TestCase
  ############################################################################### GET /accounts/:account_id/transactions
  test "should get index" do
    get_index       @some_account
    assert_response :success
  end

  test "should not get index - hacker way" do
    get_index            @some_wrong_account
    assert_redirected_to dashboard_url
  end

  test "should not get index - unknow account" do
    get_index            @unknow_account
    assert_redirected_to dashboard_url
  end

  ########################################################################### GET /accounts/:account_id/transactions/new
  test "should get new" do
    get_new         @some_account
    assert_response :success
  end

  test "should not get new - hacker way" do
    get_new              @some_wrong_account
    assert_redirected_to dashboard_url
  end

  test "should not get new - unknow account" do
    get_new              @unknow_account
    assert_redirected_to dashboard_url
  end

  ########################################################################################### GET /transactions/:id/edit
  # TODO: fix
  test "should get edit" do
    get_edit        @some_transaction
    assert_response :success
  end

  test "should not get edit - hacker way" do
    get_edit             @some_wrong_transaction
    assert_redirected_to dashboard_url
  end

  test "should not get edit - unknow transaction" do
    get_edit             @unknow_transaction
    assert_redirected_to dashboard_url
  end

  ############################################################################## POST /accounts/:account_id/transactions
  test "should create transaction" do
    assert_difference("Transaction.count") do
      post_create          @some_account
      assert_redirected_to account_transactions_path @some_account
      assert_equal         I18n.t("transactions.create.successfully_created"), flash[:notice]
    end
  end

  test "should not create transaction - hacker way" do
    assert_no_difference("Transaction.count") do
      post_create          @some_wrong_account
      assert_redirected_to dashboard_url
    end
  end

  ########################################################################################## PATCH/PUT /transactions/:id
  # TODO: fix
  test "should update transaction" do
    patch_update         @some_transaction
    assert_redirected_to account_transactions_path @some_account
    assert_equal         I18n.t("transactions.update.successfully_updated"), flash[:notice]
    assert_not_equal     @previous_transaction_amount, @some_transaction.reload.amount
  end

  test "should not update transaction - hacker way" do
    patch_update         @some_wrong_transaction
    assert_redirected_to dashboard_url
    assert_equal         @previous_transaction_amount,
                         @some_wrong_transaction.reload.amount
  end

  ############################################################################################# DELETE /transactions/:id
  # TODO: fix
  test "should destroy transaction" do
    assert_difference("Transaction.count", -1) do
      delete_destroy       @some_transaction
      assert_redirected_to request.env["HTTP_REFERER"]
      assert_equal         I18n.t("transactions.destroy.successfully_destroyed"), flash[:notice]
    end
  end

  test "should not destroy transaction - hacker way" do
    assert_no_difference "Transaction.count" do
      delete_destroy       @some_wrong_transaction
      assert_redirected_to dashboard_url
    end
  end

  ##################################################################################### POST /transactions/:id/easycheck
  # TODO: fix
  test "should easycheck transaction" do
    post_easycheck       @some_transaction
    assert_redirected_to request.env["HTTP_REFERER"]
    assert_equal         I18n.t("transactions.easycheck.successfully_checked"), flash[:notice]
    assert_not_equal     @previous_status, @some_transaction.reload.checked
{'fraction_non_alphanumeric': 0.189205433345354, 'fraction_numerical': 0.002163721601153985, 'mean_word_length': 3.8315911730545875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '6713101', 'n_tokens_mistral': 2178, 'n_tokens_neox': 2053, 'n_words': 516}