Skip to content

Commit

Permalink
Merge pull request #5 from alldigitalrewards/DS-3439
Browse files Browse the repository at this point in the history
DS-3439 extend country mapping methods to get approved country list a…
  • Loading branch information
jmuto2 authored Nov 2, 2021
2 parents 9802164 + eb9c66f commit 8733f74
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/CountryMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
class CountryMapping
{
/**
* Using assests flags from our language mapper
* Using assets flags from our language mapper
* @var string
*/
private $imageFlagBasePath = 'https://storage.googleapis.com/language_mapping/flags';
private $imageCountryBasePath = 'https://storage.googleapis.com/country_mapper/flags';

public function getMapping()
public function getMapping(): array
{
return [
[
Expand Down Expand Up @@ -86,4 +86,19 @@ public function getMapping()
],
];
}

public function getApprovedCountryList(): array
{
return array_map(
function ($row) {
return $row['short_code'];
},
$this->getMapping()
);
}

public function isApprovedCountry(string $country): bool
{
return in_array($country, $this->getApprovedCountryList());
}
}
26 changes: 26 additions & 0 deletions tests/ApprovedCountryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace AllDigitalRewards\Tests;

use AllDigitalRewards\CountryMapper\CountryMapping;
use PHPUnit\Framework\TestCase;

class ApprovedCountryTest extends TestCase
{
public function testArrayOfApprovedCountries()
{
$approvedList = ['US', 'CA', 'MX', 'ES', 'DE', 'IN', 'JP', 'KR', 'IT', 'MY', 'NL', 'BR', 'RU', 'CN'];
$countries = (new CountryMapping())->getApprovedCountryList();
$this->assertSame($approvedList, $countries);
}

public function testApprovedCountryReturnsFalse()
{
$this->assertFalse((new CountryMapping())->isApprovedCountry('AL'));
}

public function testApprovedCountryReturnsTrue()
{
$this->assertTrue((new CountryMapping())->isApprovedCountry('RU'));
}
}

0 comments on commit 8733f74

Please sign in to comment.