<commit_before>require 'test_helper'

class Kaui::SubscriptionsControllerTest < Kaui::FunctionalTestHelper

  test 'should handle Kill Bill errors in new screen' do
    bundle_id = SecureRandom.uuid.to_s
    get :new, :bundle_id => bundle_id, :account_id => @account.account_id, :product_category => 'ADD_ON'
    assert_redirected_to account_path(@account.account_id)
    assert_equal "Error while communicating with the Kill Bill server: Error 404: Object id=#{bundle_id} type=BUNDLE doesn't exist!", flash[:error]
  end

  test 'should get new page for base plan' do
    get :new,
        :account_id => @account.account_id,
        :product_category => 'BASE'
    assert assigns(:plans).size > 0
  end

  test 'should get new page for base addon' do
    get :new,
        :base_product_name => 'Sports',
        :bundle_id => @bundle.bundle_id,
        :account_id => @account.account_id,
        :product_category => 'ADD_ON'
    assert assigns(:plans).size > 0, 'Plans were not created'
  end

  test 'should handle errors during creation' do
    post :create,
         :subscription => {
             :bundle_id => @bundle.bundle_id,
             :account_id => @account.account_id,
             :product_category => 'ADD_ON'
         },
         :base_product_name => 'Sports'
    assert_redirected_to account_path(@account.account_id)
    assert_equal 'Required parameter missing: plan_name', flash[:error]

    post :create,
         :subscription => {
             :bundle_id => @bundle.bundle_id,
             :account_id => @account.account_id,
             :product_category => 'ADD_ON'
         },
         :base_product_name => 'Sports',
         :plan_name => 'not-exists'
    assert_template :new
    assert_equal 'Error while creating the subscription: Unable to find plan not-exists', flash[:error]
  end

  test 'should create a new base subscription' do
    post :create,
         :subscription => {
             :account_id => @account.account_id,
             :external_key => SecureRandom.uuid,
             :product_category => 'BASE'<commit_msg>Subscription Test: Removed product category since is unnecessary if there is plan name<commit_after>require 'test_helper'

class Kaui::SubscriptionsControllerTest < Kaui::FunctionalTestHelper

  test 'should handle Kill Bill errors in new screen' do
    bundle_id = SecureRandom.uuid.to_s
    get :new, :bundle_id => bundle_id, :account_id => @account.account_id, :product_category => 'ADD_ON'
    assert_redirected_to account_path(@account.account_id)
    assert_equal "Error while communicating with the Kill Bill server: Error 404: Object id=#{bundle_id} type=BUNDLE doesn't exist!", flash[:error]
  end

  test 'should get new page for base plan' do
    get :new,
        :account_id => @account.account_id,
        :product_category => 'BASE'
    assert assigns(:plans).size > 0
  end

  test 'should get new page for base addon' do
    get :new,
        :base_product_name => 'Sports',
        :bundle_id => @bundle.bundle_id,
        :account_id => @account.account_id,
        :product_category => 'ADD_ON'
    assert assigns(:plans).size > 0, 'Plans were not created'
  end

  test 'should handle errors during creation' do
    post :create,
         :subscription => {
             :bundle_id => @bundle.bundle_id,
             :account_id => @account.account_id,
             :product_category => 'ADD_ON'
         },
         :base_product_name => 'Sports'
    assert_redirected_to account_path(@account.account_id)
    assert_equal 'Required parameter missing: plan_name', flash[:error]

    post :create,
         :subscription => {
             :bundle_id => @bundle.bundle_id,
             :account_id => @account.account_id,
             :product_category => 'ADD_ON'
         },
         :base_product_name => 'Sports',
         :plan_name => 'not-exists'
    assert_template :new
    assert_equal 'Error while creating the subscription: Unable to find plan not-exists', flash[:error]
  end

  test 'should create a new base subscription' do
    post :create,
         :subscription => {
             :account_id => @account.account_id,
             :external_key => SecureRandom.uuid,
{'fraction_non_alphanumeric': 0.10397700047915669, 'fraction_numerical': 0.0023957834211787254, 'mean_word_length': 2.92018779342723, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 54, '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': '5446875', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1209, 'n_words': 333}