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

require 'test_base'

module KillBillIntegrationTests

  class TestCatalog < Base

    def setup
      @user = 'Catalog'
      setup_base(@user)

      upload_catalog('Catalog-v1.xml')

      @account = create_account(@user, nil, @options)
    end

    def teardown
      teardown_base
    end

    # Increase the price in a subsequent catalog
    def test_price_increase
      create_basic_entitlement(1, 'MONTHLY', '2013-08-01', '2013-09-01', 1000.0)

      # Effective date of the second catalog is 2013-09-01
      upload_catalog('Catalog-v2.xml')

      # Original subscription is grandfathered
      add_days_and_check_invoice_item(31, 2, 'basic-monthly', '2013-09-01', '2013-10-01', 1000.0)

      # Create a new subscription and check the new price is effective
      create_basic_entitlement(3, 'MONTHLY', '2013-09-01', '2013-10-01', 1200.0)

      add_days_and_check_invoice_balance(30, 4, '2013-10-01', 2200.0)
    end

    # Add a plan in a subsequent catalog
    def test_add_plan
      create_basic_entitlement(1, 'MONTHLY', '2013-08-01', '2013-09-01', 1000.0)

      add_days_and_check_invoice_item(31, 2, 'basic-monthly', '2013-09-01', '2013-10-01', 1000.0)

      # Effective date of the second catalog is 2013-10-01
      upload_catalog('Catalog-v3.xml')

      # Original subscription is grandfathered
      add_days_and_check_invoice_item(30, 3, 'basic-monthly', '2013-10-01', '2013-11-01', 1000.0)

      # The annual plan is only present in the v3 catalog
      create_basic_entitlement(4, 'ANNUAL', '2013-10-01', '2014-10-01', 14000.0)

      add_days_and_check_invoice_item(31, 5, 'basic-monthly', '2013-11-01', '2013-12-01', 1000.0)
    end

    # Remove a phase in a subsequent catalog
    def test_remove_phase
      upload_catalog('Catalog-WithTrial.xml')

      # The first subscription has a trial phase
      create_basic_entitlement(1, 'MONTHLY', '2013-08-01', nil, 0.0)

      # Move the clock to 2013-08-15
      add_days(14)

      # Effective date of the second catalog is 2013-08-15
      upload_catalog('Catalog-NoTrial.xml')

      # The new subscription doesn't have a trial phase
      # Because of the ACCOUNT billing alignment, there is a leading proration
      create_basic_entitlement(2, 'MONTHLY', '2013-08-15', '2013-08-31', 516.13)

      # Move the clock to 2013-08-31 (30 days trial)
      add_days(16)

      invoice = check_invoice_balance(3, '2013-08-31', 2000.0)
      check_invoice_item(invoice.items[0], invoice.invoice_id, 1000.0, 'USD', 'RECURRING', 'basic-monthly', 'basic-monthly-evergreen', '2013-08-31', '2013-09-30')
      check_invoice_item(invoice.items[1], invoice.invoice_id, 1000.0, 'USD', 'RECURRING', 'basic-monthly', 'basic-monthly-evergreen', '2013-08-31', '2013-09-30')
    end

    def test_create_alignment
      upload_catalog('Catalog-CreateAlignment.xml')

      bp = create_basic_entitlement(1, 'MONTHLY', '2013-08-01', nil, 0.0)

      # Move the clock to 2013-08-15
      add_days(14)

      # Add a first add-on with a START_OF_BUNDLE creation alignment. The subscription is aligned
      # with the bundle creation date (2013-08-01) meaning the trial will be from 2013-08-15 to 2013-08-31
      create_ao_entitlement(bp, 2, 'BasicAOStartOfBundle', 'MONTHLY', '2013-08-15', 0)

      # Add a second add-on with a START_OF_SUBSCRIPTION creation alignment. The subscription is aligned
      # with the add-on subscription creation date (2013-08-15) meaning the trial will be from 2013-08-15 to 2013-09-14
      create_ao_entitlement(bp, 3, 'BasicAOStartOfSubscription', 'MONTHLY', '2013-08-15', 0)

      # Move the clock to 2013-08-31 (30 days trial)
      add_days(16)

      # The first evergreen invoice will contain the line items for the base plan and the bundle-aligned add-on
      invoice = check_invoice_balance(4, '2013-08-31', 1100.0)<commit_msg>test_catalog: integrate comments from 3dd49e75dc459273fef90b7dbedcec880aa414c5<commit_after>$LOAD_PATH.unshift File.expand_path('../..', __FILE__)

require 'test_base'

module KillBillIntegrationTests

  class TestCatalog < Base

    def setup
      @user = 'Catalog'
      setup_base(@user)

      upload_catalog('Catalog-v1.xml')

      @account = create_account(@user, nil, @options)
    end

    def teardown
      teardown_base
    end

    # Increase the price in a subsequent catalog
    def test_price_increase
      create_basic_entitlement(1, 'MONTHLY', '2013-08-01', '2013-09-01', 1000.0)

      # Effective date of the second catalog is 2013-09-01
      upload_catalog('Catalog-v2.xml')

      # Original subscription is grandfathered
      add_days_and_check_invoice_item(31, 2, 'basic-monthly', '2013-09-01', '2013-10-01', 1000.0)

      # Create a new subscription and check the new price is effective
      create_basic_entitlement(3, 'MONTHLY', '2013-09-01', '2013-10-01', 1200.0)

      add_days_and_check_invoice_balance(30, 4, '2013-10-01', 2200.0)
    end

    # Add a plan in a subsequent catalog
    def test_add_plan
      create_basic_entitlement(1, 'MONTHLY', '2013-08-01', '2013-09-01', 1000.0)

      add_days_and_check_invoice_item(31, 2, 'basic-monthly', '2013-09-01', '2013-10-01', 1000.0)

      # Effective date of the second catalog is 2013-10-01
      upload_catalog('Catalog-v3.xml')

      # Original subscription is grandfathered
      add_days_and_check_invoice_item(30, 3, 'basic-monthly', '2013-10-01', '2013-11-01', 1000.0)

      # The annual plan is only present in the v3 catalog
      create_basic_entitlement(4, 'ANNUAL', '2013-10-01', '2014-10-01', 14000.0)

      add_days_and_check_invoice_item(31, 5, 'basic-monthly', '2013-11-01', '2013-12-01', 1000.0)
    end

    # Remove a phase in a subsequent catalog
    def test_remove_phase
      upload_catalog('Catalog-WithTrial.xml')

      # The first subscription has a trial phase
      create_basic_entitlement(1, 'MONTHLY', '2013-08-01', nil, 0.0)

      # Move the clock to 2013-08-15
      add_days(14)

      # Effective date of the second catalog is 2013-08-15
      upload_catalog('Catalog-NoTrial.xml')

      # The new subscription doesn't have a trial phase
      # Because of the ACCOUNT billing alignment, there is a leading proration
      create_basic_entitlement(2, 'MONTHLY', '2013-08-15', '2013-08-31', 516.13)

      # Move the clock to 2013-08-31 (30 days trial)
      add_days(16)

      invoice = check_invoice_balance(3, '2013-08-31', 2000.0)
      check_invoice_item(invoice.items[0], invoice.invoice_id, 1000.0, 'USD', 'RECURRING', 'basic-monthly', 'basic-monthly-evergreen', '2013-08-31', '2013-09-30')
      check_invoice_item(invoice.items[1], invoice.invoice_id, 1000.0, 'USD', 'RECURRING', 'basic-monthly', 'basic-monthly-evergreen', '2013-08-31', '2013-09-30')

      # Move the clock to 2013-09-30
      add_days(30)

      invoice = check_invoice_balance(4, '2013-09-30', 2000.0)
      check_invoice_item(invoice.items[0], invoice.invoice_id, 1000.0, 'USD', 'RECURRING', 'basic-monthly', 'basic-monthly-evergreen', '2013-09-30', '2013-10-31')
      check_invoice_item(invoice.items[1], invoice.invoice_id, 1000.0, 'USD', 'RECURRING', 'basic-monthly', 'basic-monthly-evergreen', '2013-09-30', '2013-10-31')
    end

    def test_create_alignment
      upload_catalog('Catalog-CreateAlignment.xml')

      bp = create_basic_entitlement(1, 'MONTHLY', '2013-08-01', nil, 0.0)

      # Move the clock to 2013-08-15
      add_days(14)

      # Add a first add-on with a START_OF_BUNDLE creation alignment. The subscription is aligned
      # with the bundle creation date (2013-08-01) meaning the trial will be from 2013-08-15 to 2013-08-31
      create_ao_entitlement(bp, 2, 'BasicAOStartOfBundle', 'MONTHLY', '2013-08-15', 0)

      # Add a second add-on with a START_OF_SUBSCRIPTION creation alignment. The subscription is aligned
      # with the add-on subscription creation date (2013-08-15) meaning the trial will be from 2013-08-15 to 2013-09-14
      create_ao_entitlement(bp, 3, 'BasicAOStartOfSubscription', 'MONTHLY', '2013-08-15', 0)

      # Move the clock to 2013-08-31 (30 days trial)
      add_days(16)

      # The first evergreen invoice will contain the line items for the base plan and the bundle-aligned add-on
      invoice = check_invoice_balance(4, '2013-08-31', 1100.0)
{'fraction_non_alphanumeric': 0.12028811524609843, 'fraction_numerical': 0.12040816326530612, 'mean_word_length': 3.3572175732217575, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '4884389', 'n_tokens_mistral': 3576, 'n_tokens_neox': 2836, 'n_words': 725}