<commit_before># encoding: utf-8

$LOAD_PATH.unshift File.expand_path('../..', __FILE__)

require 'test_base'

module KillBillIntegrationTests

  class TestEntitlementChangePlanTest < Base

    def setup
      setup_base
      load_default_catalog
      @account = create_account(@user, @options)
    end

    def teardown
      teardown_base
    end

    def test_change_default

      bp = create_entitlement_base(@account.account_id, 'Sports', 'MONTHLY', 'DEFAULT', @user, @options)
      check_entitlement(bp, 'Sports', 'BASE', 'MONTHLY', 'DEFAULT', DEFAULT_KB_INIT_DATE, nil)

      # Change plan
      requested_date = nil
      billing_policy = nil
      bp = bp.change_plan({:productName => 'Super', :billingPeriod => 'MONTHLY', :priceList => 'DEFAULT'}, @user, nil, nil, requested_date, billing_policy, false, @options)
      check_entitlement(bp, 'Super', 'BASE', 'MONTHLY', 'DEFAULT', DEFAULT_KB_INIT_DATE, nil)

      changed_bp = get_subscription(bp.subscription_id, @options)
      assert_not_nil(changed_bp)
      assert_nil(changed_bp.cancelled_date)
      assert_nil(changed_bp.billing_end_date)

      events = get_events(@account.account_id, changed_bp.subscription_id)
      assert_equal(events.size, 4)
      assert_equal(events[0].effective_date, DEFAULT_KB_INIT_DATE)
      assert_equal(events[0].event_type, "START_ENTITLEMENT")
      assert_equal(events[1].effective_date, DEFAULT_KB_INIT_DATE)
      assert_equal(events[1].event_type, "START_BILLING")
      assert_equal(events[2].effective_date, DEFAULT_KB_INIT_DATE)<commit_msg>core: fix flaky change plan test<commit_after># encoding: utf-8

$LOAD_PATH.unshift File.expand_path('../..', __FILE__)

require 'test_base'

module KillBillIntegrationTests

  class TestEntitlementChangePlanTest < Base

    def setup
      setup_base
      load_default_catalog
      @account = create_account(@user, @options)
    end

    def teardown
      teardown_base
    end

    def test_change_default

      bp = create_entitlement_base(@account.account_id, 'Sports', 'MONTHLY', 'DEFAULT', @user, @options)
      check_entitlement(bp, 'Sports', 'BASE', 'MONTHLY', 'DEFAULT', DEFAULT_KB_INIT_DATE, nil)

      kb_clock_add_days(1, nil, @options)

      # Change plan
      requested_date = nil
      billing_policy = nil
      bp = bp.change_plan({:productName => 'Super', :billingPeriod => 'MONTHLY', :priceList => 'DEFAULT'}, @user, nil, nil, requested_date, billing_policy, false, @options)
      check_entitlement(bp, 'Super', 'BASE', 'MONTHLY', 'DEFAULT', DEFAULT_KB_INIT_DATE, nil)

      changed_bp = get_subscription(bp.subscription_id, @options)
      assert_not_nil(changed_bp)
      assert_nil(changed_bp.cancelled_date)
      assert_nil(changed_bp.billing_end_date)

      events = get_events(@account.account_id, changed_bp.subscription_id)
      assert_equal(events.size, 4)
      assert_equal(events[0].effective_date, DEFAULT_KB_INIT_DATE)
      assert_equal(events[0].event_type, "START_ENTITLEMENT")
      assert_equal(events[1].effective_date, DEFAULT_KB_INIT_DATE)
      assert_equal(events[1].event_type, "START_BILLING")
      assert_equal(events[2].effective_date, "2013-08-02")
{'fraction_non_alphanumeric': 0.11244472520530638, 'fraction_numerical': 0.007264687302590019, 'mean_word_length': 4.367796610169491, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3957046', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1036, 'n_words': 185}