Skip to content

Commit

Permalink
added unit test for valid regions
Browse files Browse the repository at this point in the history
  • Loading branch information
DjoykeAbyah committed Dec 10, 2024
1 parent 62cfcab commit 37bbbb0
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Adyen/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Client
const ENDPOINT_TERMINAL_CLOUD_LIVE = "https://terminal-api-live.adyen.com";
const ENDPOINT_TERMINAL_CLOUD_US_LIVE = "https://terminal-api-live-us.adyen.com";
const ENDPOINT_TERMINAL_CLOUD_AU_LIVE = "https://terminal-api-live-au.adyen.com";
const ENDPOINT_TERMINAL_CLOUD_IN_LIVE = "https://terminal-api-live-in.adyen.com";
const ENDPOINT_TERMINAL_CLOUD_APSE_LIVE = "https://terminal-api-live-apse.adyen.com";
const ENDPOINT_CHECKOUT_TEST = "https://checkout-test.adyen.com";
const ENDPOINT_CHECKOUT_LIVE_SUFFIX = "-checkout-live.adyenpayments.com/checkout";
Expand Down
28 changes: 28 additions & 0 deletions src/Adyen/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,35 @@

class Region
{
/**
* European Union region
*/
const EU = "eu";

/**
* United States region
*/
const US = "us";

/**
* Australia region
*/
const AU = "au";

/**
* India region
*/
const IN = "in";

/**
* Asia-Pacific, South East region
*/
const APSE = "apse";

/**
* List of all valid regions
* @var array<int,string>
*/
const VALID_REGIONS = [
self::EU,
self::US,
Expand All @@ -18,10 +41,15 @@ class Region
self::APSE
];

/**
* Maps regions to their respective Terminal API endpoints.
* @var array<string, string>
*/
const TERMINAL_API_ENDPOINTS_MAPPING = [
self::EU => Client::ENDPOINT_TERMINAL_CLOUD_LIVE,
self::US => Client::ENDPOINT_TERMINAL_CLOUD_US_LIVE,
self::AU => Client::ENDPOINT_TERMINAL_CLOUD_AU_LIVE,
self::IN => Client::ENDPOINT_TERMINAL_CLOUD_IN_LIVE,
self::APSE => Client::ENDPOINT_TERMINAL_CLOUD_APSE_LIVE,
];
}
55 changes: 55 additions & 0 deletions tests/Unit/RegionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Adyen\Tests\Unit;

use PHPUnit\Framework\TestCase;
use Adyen\Region;

class RegionTest extends TestCase
{
public function testValidRegions()
{
$expected = [
"eu",
"us",
"au",
"in",
"apse",
];

$this->assertEquals(
$expected,
Region::VALID_REGIONS,
"VALID_REGIONS should match the expected regions."
);
}

public function testTerminalApiEndpointsMapping()
{
$expected = [
"eu" => "https://terminal-api-live.adyen.com",
"us" => "https://terminal-api-live-us.adyen.com",
"au" => "https://terminal-api-live-au.adyen.com",
"in" => "https://terminal-api-live-in.adyen.com",
"apse" => "https://terminal-api-live-apse.adyen.com",
];

$this->assertEquals(
$expected,
Region::TERMINAL_API_ENDPOINTS_MAPPING,
"TERMINAL_API_ENDPOINTS_MAPPING should match the expected mappings.");
}

public function testTerminalApiEndpointsExistsForAllRegions()
{
$regionsWithEndpoints = array_keys(Region::TERMINAL_API_ENDPOINTS_MAPPING);
$regions = Region::VALID_REGIONS;

$expected = array_diff($regions, $regionsWithEndpoints);

$this->assertEmpty(
$expected,
"Every region should be mapped to an endpoint."
);
}
}

0 comments on commit 37bbbb0

Please sign in to comment.