Skip to content

Commit

Permalink
Updated ocbc digital class to write test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aashish committed Sep 18, 2023
1 parent 0d4f93a commit f857a71
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
13 changes: 11 additions & 2 deletions includes/gateway/class-omise-payment-ocbc-digital.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,19 @@ public function init_form_fields() {
* @inheritdoc
*/
public function charge($order_id, $order)
{
return OmiseCharge::create($this->get_charge_request($order_id, $order));
}

/**
* @order_id integer
* @order object
*/
public function get_charge_request($order_id, $order)
{
$currency = $order->get_currency();

return OmiseCharge::create([
return [
'amount' => Omise_Money::to_subunit($order->get_total(), $currency),
'currency' => $currency,
'description' => apply_filters('omise_charge_params_description', 'WooCommerce Order id ' . $order_id, $order),
Expand All @@ -69,7 +78,7 @@ public function charge($order_id, $order)
],
'return_uri' => $this->getRedirectUrl("{$this->id}_callback", $order_id, $order),
'metadata' => $this->getMetadata($order_id, $order)
]);
];
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/includes/gateway/class-omise-offsite-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public function setUp(): void
$offsite->shouldReceive('init_settings');
$offsite->shouldReceive('get_option');
$offsite->shouldReceive('get_provider');
$offsite->shouldReceive('getRedirectUrl');
$offsite->shouldReceive('getMetadata');

// mocking WP built-in functions
if (!function_exists('wp_kses')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function supportsIsCorrect()
/**
* @test
*/
public function getIcon()
public function getIconReturnsCorrectImageLink()
{
// mocking WP built-in functions
if (!function_exists('plugins_url')) {
Expand All @@ -75,4 +75,37 @@ function apply_filters() {

$this->assertEquals("http://localhost/image.png", $result);
}

/**
* @test
*/
public function getChargeRequestReturnsCorrectData()
{
$order = new class {
public function get_currency()
{
return 'thb';
}

public function get_total()
{
return 10000;
}
};

if (!function_exists('wc_get_user_agent')) {
function wc_get_user_agent() {
return "Chrome Web";
}
}

$expectedAmount = 1000000;
$expectedCurrency = 'thb';
$expectedSourceType = 'mobile_banking_ocbc';
$order_id = "123";
$result = $this->obj->get_charge_request($order_id, $order);
$this->assertEquals($expectedAmount, $result['amount']);
$this->assertEquals($expectedCurrency, $result['currency']);
$this->assertEquals($expectedSourceType, $result['source']['type']);
}
}

0 comments on commit f857a71

Please sign in to comment.