Skip to content

Commit

Permalink
Merge pull request #77 from reshmabidikar/fix-tests-for-1739
Browse files Browse the repository at this point in the history
Fix change alignment tests
  • Loading branch information
reshmabidikar authored Aug 23, 2024
2 parents bc08513 + 41145f1 commit d1c4bd1
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 13 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ jobs:
- name: Start stack
run: |
cd docker
docker-compose -p it -f ${{ matrix.docker-compose-file }} up --no-start
docker start it_db_1
docker compose -p it -f ${{ matrix.docker-compose-file }} up --no-start
docker start it-db-1
- name: Wait for MySQL
if: ${{ matrix.docker-compose-file == 'docker-compose.ci.mysql.yml' }}
run: |
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
run: |
# Start all remaining containers
cd docker
docker-compose -p it -f ${{ matrix.docker-compose-file }} up -d
docker compose -p it -f ${{ matrix.docker-compose-file }} up -d
count=0
until $(curl --connect-timeout 10 --max-time 30 --output /dev/null --silent --fail http://${KB_ADDRESS}:${KB_PORT}/1.0/healthcheck); do
if [[ "$count" == "180" ]]; then
Expand Down Expand Up @@ -210,16 +210,16 @@ jobs:
docker ps -a
echo "::endgroup::"
echo "::group::killbill env"
docker exec it_killbill_1 env || true
docker exec it-killbill-1 env || true
echo "::endgroup::"
echo "::group::db env"
docker exec it_db_1 env || true
docker exec it-db-1 env || true
echo "::endgroup::"
echo "::group::killbill logs"
(docker logs -t --details it_killbill_1 || true) | tee /var/tmp/killbill.txt
(docker logs -t --details it-killbill-1 || true) | tee /var/tmp/killbill.txt
echo "::endgroup::"
echo "::group::db logs"
docker logs -t --details it_db_1 || true
docker logs -t --details it-db-1 || true
echo "::endgroup::"
- name: Upload logs
uses: actions/[email protected]
Expand Down
105 changes: 99 additions & 6 deletions killbill-integration-tests/core/test_catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
require 'test_base'
require 'date'

# TODO_1739
## Some tests are failing and deleted. These need to be fixed and added back
## The START_OF_BUNDLE tests need to be updated after the change is made on the KB side
## This test has major changes and needs to be reviewed carefully
# TODO_1739 - This test has major changes and needs to be reviewed carefully
module KillBillIntegrationTests
class TestCatalog < Base
def setup
Expand Down Expand Up @@ -181,6 +178,102 @@ def test_create_alignment
add_days_and_check_invoice_item(14, 7, 'BasicAOStartOfSubscription-monthly', '2013-10-14', '2013-11-14', 150)
end

def test_change_alignment_start_of_bundle
bp, ao = setup_change_alignment_test

# Change plan with a start of bundle change alignment: the trial will still end on 2013-08-31
change_ao_entitlement(ao, 3, 'BasicAOStartOfBundle', 'MONTHLY', '2013-08-05', '2013-08-31', 0.0, '2013-08-15')
check_subscription_events(bp,
ao,
[{ type: 'START_ENTITLEMENT', date: '2013-08-01' },
{ type: 'START_BILLING', date: '2013-08-01' },
{ type: 'PHASE', date: '2013-08-31' }],
[{ type: 'START_ENTITLEMENT', date: '2013-08-05' },
{ type: 'START_BILLING', date: '2013-08-05' },
{ type: 'CHANGE', date: '2013-08-15' },
{ type: 'PHASE', date: '2013-08-31' }])

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

# Both subscriptions are aligned on the same invoice (ACCOUNT billing alignment)
invoice = check_invoice_balance(4, '2013-08-31', 1100.0)
check_invoice_item(invoice.items[0], invoice.invoice_id, 100.0, 'USD', 'RECURRING', 'BasicAOStartOfBundle-monthly', 'BasicAOStartOfBundle-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_change_alignment_start_of_subscription
bp, ao = setup_change_alignment_test

# Change plan with a start of subscription change alignment: the trial will now end on 2013-09-04
change_ao_entitlement(ao, 3, 'BasicAOStartOfSubscription', 'MONTHLY', '2013-08-05', '2013-09-04', 0.0, '2013-08-15')
check_subscription_events(bp,
ao,
[{ type: 'START_ENTITLEMENT', date: '2013-08-01' },
{ type: 'START_BILLING', date: '2013-08-01' },
{ type: 'PHASE', date: '2013-08-31' }],
[{ type: 'START_ENTITLEMENT', date: '2013-08-05' },
{ type: 'START_BILLING', date: '2013-08-05' },
{ type: 'CHANGE', date: '2013-08-15' },
{ type: 'PHASE', date: '2013-09-04' }])

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

invoice = check_invoice_balance(4, '2013-08-31', 1000.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')

# Move the clock to 2013-09-04
add_days(4)

# Pro-rated invoice for the add-on (ACCOUNT billing alignment)
invoice = check_invoice_balance(5, '2013-09-04', 125.81)
check_invoice_item(invoice.items[0], invoice.invoice_id, 125.81, 'USD', 'RECURRING', 'BasicAOStartOfSubscription-monthly', 'BasicAOStartOfSubscription-monthly-evergreen', '2013-09-04', '2013-09-30')

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

invoice = check_invoice_balance(6, '2013-09-30', 1150.0)
check_invoice_item(invoice.items[0], invoice.invoice_id, 150.0, 'USD', 'RECURRING', 'BasicAOStartOfSubscription-monthly', 'BasicAOStartOfSubscription-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_change_alignment_change_of_plan
bp, ao = setup_change_alignment_test

# Change plan with a start of change of plan change alignment: the trial will now end on 2013-09-14
change_ao_entitlement(ao, 3, 'BasicAOChangeOfPlan', 'MONTHLY', '2013-08-05', '2013-09-14', 0.0, '2013-08-15')
check_subscription_events(bp,
ao,
[{ type: 'START_ENTITLEMENT', date: '2013-08-01' },
{ type: 'START_BILLING', date: '2013-08-01' },
{ type: 'PHASE', date: '2013-08-31' }],
[{ type: 'START_ENTITLEMENT', date: '2013-08-05' },
{ type: 'START_BILLING', date: '2013-08-05' },
{ type: 'CHANGE', date: '2013-08-15' },
{ type: 'PHASE', date: '2013-09-14' }])

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

invoice = check_invoice_balance(4, '2013-08-31', 1000.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')

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

# Pro-rated invoice for the add-on (ACCOUNT billing alignment)
invoice = check_invoice_balance(5, '2013-09-14', 103.23)
check_invoice_item(invoice.items[0], invoice.invoice_id, 103.23, 'USD', 'RECURRING', 'BasicAOChangeOfPlan-monthly', 'BasicAOChangeOfPlan-monthly-evergreen', '2013-09-14', '2013-09-30')

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

invoice = check_invoice_balance(6, '2013-09-30', 1200.0)
check_invoice_item(invoice.items[0], invoice.invoice_id, 200.0, 'USD', 'RECURRING', 'BasicAOChangeOfPlan-monthly', 'BasicAOChangeOfPlan-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_simple_plan
upload_catalog('Catalog-v1.xml', false, @user, @options)

Expand Down Expand Up @@ -276,9 +369,9 @@ def create_ao_entitlement(bp, invoice_nb, product, billing_period = 'MONTHLY', s
end

def change_ao_entitlement(ao, invoice_nb, product, billing_period = 'MONTHLY', ao_start_date = '2013-08-01', ao_end_date = '2013-08-31', amount = 0.0, invoice_date = start_date)
ao = ao.change_plan({ productName: product, billingPeriod: billing_period, priceList: 'DEFAULT' }, @user, nil, nil, nil, nil, nil, false, @options)
ao = ao.change_plan({ productName: product, billingPeriod: billing_period, priceList: 'DEFAULT' }, @user, nil, nil, nil, 'IMMEDIATE', nil, false, @options)
check_subscription(ao, product, 'ADD_ON', billing_period, 'DEFAULT', ao_start_date, nil, ao_start_date, nil)
check_fixed_item(invoice_nb, product + '-' + billing_period.downcase, invoice_date, amount, amount, ao_start_date, ao_end_date)
check_fixed_item(invoice_nb, product + '-' + billing_period.downcase, invoice_date, amount, amount, invoice_date, ao_end_date)
end

def check_subscription_events(bp, ao, bp_events, ao_events)
Expand Down

0 comments on commit d1c4bd1

Please sign in to comment.