Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
annemirasol committed Nov 11, 2024
1 parent 334b26c commit 0940a78
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/phpunit/test-class-wc-stripe-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,69 @@ public function test_delete_previously_configured_webhooks_without_exclusion() {
// Confirm that all expected request call params were called.
$this->assertEmpty( WC_Helper_Stripe_Api::$expected_request_call_params );
}

/**
* Tests for is_webhook_enabled().
*/
public function test_is_webhook_enabled() {
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();

// False if webhook secrets are not set.
$stripe_settings['testmode'] = 'yes';
$stripe_settings['test_webhook_data'] = [
'id' => 'wh_123_test',
'secret' => '',
];
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
$this->assertFalse( $this->account->is_webhook_enabled() );

$stripe_settings['test_webhook_data'] = [];
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
$this->assertFalse( $this->account->is_webhook_enabled() );

unset( $stripe_settings['test_webhook_data'] );
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
$this->assertFalse( $this->account->is_webhook_enabled() );

$stripe_settings['testmode'] = 'yes';
$stripe_settings['webhook_data'] = [
'id' => 'wh_123',
'secret' => 'wh_secret_123',
];
$stripe_settings['test_webhook_data'] = [
'id' => 'wh_123_test',
'secret' => 'wh_secret_123_test',
];
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );

WC_Helper_Stripe_Api::$expected_request_call_params = [
[ [], 'webhook_endpoints/wh_123_test', 'GET' ],
[ [], 'webhook_endpoints/wh_123_test', 'GET' ],
];

// Assert that it correctly reads the webhook status field.
WC_Helper_Stripe_Api::$request_response = (object) [
'id' => 'wh_123_test',
'status' => 'disabled',
];
$this->assertFalse( $this->account->is_webhook_enabled() );

WC_Helper_Stripe_Api::$request_response = (object) [
'id' => 'wh_123_test',
'status' => 'enabled',
];
$this->assertTrue( $this->account->is_webhook_enabled() );

// Assert that it queries the correct webhook (live).
$stripe_settings['testmode'] = 'no';
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
WC_Helper_Stripe_Api::$expected_request_call_params = [
[ [], 'webhook_endpoints/wh_123', 'GET' ],
];
WC_Helper_Stripe_Api::$request_response = (object) [
'id' => 'wh_123_test',
'status' => 'enabled',
];
$this->assertTrue( $this->account->is_webhook_enabled() );
}
}

0 comments on commit 0940a78

Please sign in to comment.