Skip to content

Commit 59bb8d7

Browse files
author
Rodion Liuborets
committed
Add testing coverage
1 parent 2007192 commit 59bb8d7

File tree

5 files changed

+236
-12
lines changed

5 files changed

+236
-12
lines changed

src/DocScan/Session/Retrieve/CustomAccountWatchlistCaSearchConfigResponse.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace Yoti\DocScan\Session\Retrieve;
66

7-
use Yoti\DocScan\Session\Retrieve\Contracts\WatchlistAdvancedCaSearchConfigResponse;
8-
97
class CustomAccountWatchlistCaSearchConfigResponse extends WatchlistAdvancedCaSearchConfigResponse
108
{
119
/**
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
declare(strict_types=1);
44

5-
namespace Yoti\DocScan\Session\Retrieve\Contracts;
5+
namespace Yoti\DocScan\Session\Retrieve;
66

77
use Yoti\DocScan\Constants;
8+
use Yoti\DocScan\Session\Retrieve\Contracts\CaMatchingStrategyResponse;
9+
use Yoti\DocScan\Session\Retrieve\Contracts\CaSourcesResponse;
10+
use Yoti\DocScan\Session\Retrieve\Contracts\WatchlistSearchConfigResponse;
811
use Yoti\DocScan\Session\Retrieve\Matching\ExactMatchingStrategyResponse;
12+
use Yoti\DocScan\Session\Retrieve\Matching\FuzzyMatchingStrategyResponse;
913
use Yoti\DocScan\Session\Retrieve\Sources\SearchProfileSourcesResponse;
1014
use Yoti\DocScan\Session\Retrieve\Sources\TypeListSourcesResponse;
1115

@@ -55,10 +59,10 @@ public function __construct(array $searchConfig)
5559
private function setSources(array $searchConfig): void
5660
{
5761
if ($searchConfig['sources']['type'] == Constants::PROFILE) {
58-
$this->sources = new SearchProfileSourcesResponse($searchConfig['search_profile']);
62+
$this->sources = new SearchProfileSourcesResponse($searchConfig['sources']['search_profile']);
5963
}
6064
if ($searchConfig['sources']['type'] == Constants::TYPE_LIST) {
61-
$this->sources = new TypeListSourcesResponse($searchConfig['types']);
65+
$this->sources = new TypeListSourcesResponse($searchConfig['sources']['types']);
6266
}
6367
}
6468

@@ -73,7 +77,7 @@ private function setMatchingStrategy(array $searchConfig): void
7377
);
7478
}
7579
if ($searchConfig['matching_strategy']['type'] == Constants::FUZZY) {
76-
$this->matchingStrategy = new ExactMatchingStrategyResponse(
80+
$this->matchingStrategy = new FuzzyMatchingStrategyResponse(
7781
$searchConfig['matching_strategy']['fuzziness']
7882
);
7983
}

src/DocScan/Session/Retrieve/WatchlistSummaryResponse.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,13 @@ public function __construct(array $watchListSummary)
5353
*/
5454
private function setSearchConfig(array $searchConfig): void
5555
{
56-
if ($searchConfig['type'] == Constants::WITH_YOTI_ACCOUNT) {
57-
$this->searchConfig = new YotiAccountWatchlistCaSearchConfigResponse($searchConfig);
58-
} elseif ($searchConfig['type'] == Constants::WITH_CUSTOM_ACCOUNT) {
59-
$this->searchConfig = new CustomAccountWatchlistCaSearchConfigResponse($searchConfig);
56+
if (isset($searchConfig['type'])) {
57+
if ($searchConfig['type'] == Constants::WITH_YOTI_ACCOUNT) {
58+
$this->searchConfig = new YotiAccountWatchlistCaSearchConfigResponse($searchConfig);
59+
}
60+
if ($searchConfig['type'] == Constants::WITH_CUSTOM_ACCOUNT) {
61+
$this->searchConfig = new CustomAccountWatchlistCaSearchConfigResponse($searchConfig);
62+
}
6063
} else {
6164
$this->searchConfig = new WatchlistScreeningSearchConfigResponse($searchConfig);
6265
}

src/DocScan/Session/Retrieve/YotiAccountWatchlistCaSearchConfigResponse.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace Yoti\DocScan\Session\Retrieve;
66

7-
use Yoti\DocScan\Session\Retrieve\Contracts\WatchlistAdvancedCaSearchConfigResponse;
8-
97
class YotiAccountWatchlistCaSearchConfigResponse extends WatchlistAdvancedCaSearchConfigResponse
108
{
119
}

tests/DocScan/Session/Retrieve/ReportResponseTest.php

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
namespace Yoti\Test\DocScan\Session\Retrieve;
66

7+
use Yoti\DocScan\Constants;
8+
use Yoti\DocScan\Session\Retrieve\Contracts\CaMatchingStrategyResponse;
9+
use Yoti\DocScan\Session\Retrieve\Contracts\CaSourcesResponse;
10+
use Yoti\DocScan\Session\Retrieve\Contracts\WatchlistSearchConfigResponse;
11+
use Yoti\DocScan\Session\Retrieve\MediaResponse;
12+
use Yoti\DocScan\Session\Retrieve\RawResultsResponse;
713
use Yoti\DocScan\Session\Retrieve\ReportResponse;
814
use Yoti\Test\TestCase;
915

@@ -12,6 +18,15 @@
1218
*/
1319
class ReportResponseTest extends TestCase
1420
{
21+
private const TOTAL_HITS = 7;
22+
private const SOME_COUNTRY_CODE = ['GBR', 'USA'];
23+
private const SOME_TYPES = [ "someString", "someOtherString" ];
24+
private const SOME_API_KEY = 'SOME_API_KEY';
25+
private const SOME_CLIENT_REF = 'SOME_CLIENT_REF';
26+
private const SOME_SEARCH_PROFILE = 'SOME_SEARCH_PROFILE';
27+
private const SOME_FUZZINESS = 0.7;
28+
private const SOME_CATEGORIES = [ "someString", "someOtherString" ];
29+
1530
/**
1631
* @test
1732
* @covers ::__construct
@@ -45,4 +60,210 @@ public function shouldNotThrowExceptionWhenMissingValues()
4560
$this->assertNull($result->getRecommendation());
4661
$this->assertCount(0, $result->getBreakdown());
4762
}
63+
64+
/**
65+
* @test
66+
* @covers ::__construct
67+
* @covers ::getWatchlistSummary
68+
* @covers \Yoti\DocScan\Session\Retrieve\WatchlistSummaryResponse::__construct
69+
* @covers \Yoti\DocScan\Session\Retrieve\WatchlistSummaryResponse::setSearchConfig
70+
* @covers \Yoti\DocScan\Session\Retrieve\WatchlistSummaryResponse::getTotalHits
71+
* @covers \Yoti\DocScan\Session\Retrieve\WatchlistSummaryResponse::getRawResults
72+
* @covers \Yoti\DocScan\Session\Retrieve\WatchlistSummaryResponse::getSearchConfig
73+
* @covers \Yoti\DocScan\Session\Retrieve\WatchlistAdvancedCaSearchConfigResponse::__construct
74+
* @covers \Yoti\DocScan\Session\Retrieve\WatchlistAdvancedCaSearchConfigResponse::getSources
75+
* @covers \Yoti\DocScan\Session\Retrieve\WatchlistAdvancedCaSearchConfigResponse::getMatchingStrategy
76+
* @covers \Yoti\DocScan\Session\Retrieve\WatchlistAdvancedCaSearchConfigResponse::getType
77+
* @covers \Yoti\DocScan\Session\Retrieve\WatchlistAdvancedCaSearchConfigResponse::isShareUrl
78+
* @covers \Yoti\DocScan\Session\Retrieve\WatchlistAdvancedCaSearchConfigResponse::isRemoveDeceased
79+
* @covers \Yoti\DocScan\Session\Retrieve\WatchlistAdvancedCaSearchConfigResponse::setMatchingStrategy
80+
* @covers \Yoti\DocScan\Session\Retrieve\WatchlistAdvancedCaSearchConfigResponse::setSources
81+
* @covers \Yoti\DocScan\Session\Retrieve\RawResultsResponse::__construct
82+
* @covers \Yoti\DocScan\Session\Retrieve\RawResultsResponse::getMedia
83+
* @covers \Yoti\DocScan\Session\Retrieve\Sources\TypeListSourcesResponse::__construct
84+
* @covers \Yoti\DocScan\Session\Retrieve\Sources\TypeListSourcesResponse::getTypes
85+
* @covers \Yoti\DocScan\Session\Retrieve\Sources\TypeListSourcesResponse::getType
86+
* @covers \Yoti\DocScan\Session\Retrieve\Sources\SearchProfileSourcesResponse::__construct
87+
* @covers \Yoti\DocScan\Session\Retrieve\Sources\SearchProfileSourcesResponse::getSearchProfile
88+
* @covers \Yoti\DocScan\Session\Retrieve\Sources\SearchProfileSourcesResponse::getType
89+
* @covers \Yoti\DocScan\Session\Retrieve\Contracts\CaSourcesResponse::getType
90+
* @covers \Yoti\DocScan\Session\Retrieve\Matching\FuzzyMatchingStrategyResponse::__construct
91+
* @covers \Yoti\DocScan\Session\Retrieve\Matching\FuzzyMatchingStrategyResponse::getFuzziness
92+
* @covers \Yoti\DocScan\Session\Retrieve\Matching\FuzzyMatchingStrategyResponse::getType
93+
* @covers \Yoti\DocScan\Session\Retrieve\Matching\ExactMatchingStrategyResponse::__construct
94+
* @covers \Yoti\DocScan\Session\Retrieve\Matching\ExactMatchingStrategyResponse::isExactMatch
95+
* @covers \Yoti\DocScan\Session\Retrieve\Matching\ExactMatchingStrategyResponse::getType
96+
* @covers \Yoti\DocScan\Session\Retrieve\Contracts\CaSourcesResponse::getType
97+
* @covers \Yoti\DocScan\Session\Retrieve\Contracts\CaMatchingStrategyResponse::getType
98+
* @covers \Yoti\DocScan\Session\Retrieve\CustomAccountWatchlistCaSearchConfigResponse::__construct
99+
* @covers \Yoti\DocScan\Session\Retrieve\CustomAccountWatchlistCaSearchConfigResponse::getApiKey
100+
* @covers \Yoti\DocScan\Session\Retrieve\CustomAccountWatchlistCaSearchConfigResponse::getMonitoring
101+
* @covers \Yoti\DocScan\Session\Retrieve\CustomAccountWatchlistCaSearchConfigResponse::getTags
102+
* @covers \Yoti\DocScan\Session\Retrieve\CustomAccountWatchlistCaSearchConfigResponse::getClientRef
103+
*/
104+
public function shouldBuildWithWatchlistSummaryResponse()
105+
{
106+
$tags = [
107+
'some' => 'exact'
108+
];
109+
$someTags = json_encode($tags);
110+
111+
$input = [
112+
'watchlist_summary' => [
113+
'total_hits' => self::TOTAL_HITS,
114+
'raw_results' => [
115+
'media' => [
116+
'id' => 'SOME_ID',
117+
'type' => 'SOME_TYPE',
118+
'created' => "2021-02-16T17:02:53.519Z",
119+
'last_updated' => "2021-02-16T17:02:53.519Z"
120+
]
121+
],
122+
'associated_country_codes' => self::SOME_COUNTRY_CODE,
123+
'search_config' => [
124+
'type' => Constants::WITH_YOTI_ACCOUNT,
125+
'remove_deceased' => true,
126+
'share_url' => true,
127+
'sources' => [
128+
'type' => Constants::TYPE_LIST,
129+
'types' => self::SOME_TYPES
130+
],
131+
'matching_strategy' => [
132+
'type' => Constants::EXACT,
133+
'exact_match' => true
134+
]
135+
]
136+
]
137+
];
138+
139+
$result = new ReportResponse($input);
140+
141+
$this->assertNotNull($result->getWatchlistSummary());
142+
$this->assertEquals(self::TOTAL_HITS, $result->getWatchlistSummary()->getTotalHits());
143+
$this->assertEquals(
144+
self::SOME_COUNTRY_CODE,
145+
$result->getWatchlistSummary()->getAssociatedCountryCodes()
146+
);
147+
148+
$this->assertInstanceOf(RawResultsResponse::class, $result->getWatchlistSummary()->getRawResults());
149+
$this->assertInstanceOf(
150+
WatchlistSearchConfigResponse::class,
151+
$result->getWatchlistSummary()->getSearchConfig()
152+
);
153+
154+
$this->assertTrue($result->getWatchlistSummary()->getSearchConfig()->isRemoveDeceased());
155+
$this->assertTrue($result->getWatchlistSummary()->getSearchConfig()->isShareUrl());
156+
$this->assertInstanceOf(
157+
CaMatchingStrategyResponse::class,
158+
$result->getWatchlistSummary()->getSearchConfig()->getMatchingStrategy()
159+
);
160+
$this->assertInstanceOf(
161+
CaSourcesResponse::class,
162+
$result->getWatchlistSummary()->getSearchConfig()->getSources()
163+
);
164+
$this->assertEquals(
165+
Constants::WITH_YOTI_ACCOUNT,
166+
$result->getWatchlistSummary()->getSearchConfig()->getType()
167+
);
168+
169+
$this->assertEquals(
170+
self::SOME_TYPES,
171+
$result->getWatchlistSummary()->getSearchConfig()->getSources()->getTypes()
172+
);
173+
174+
$this->assertTrue(
175+
$result->getWatchlistSummary()->getSearchConfig()->getMatchingStrategy()->isExactMatch()
176+
);
177+
178+
$input2 = [
179+
'watchlist_summary' => [
180+
'total_hits' => self::TOTAL_HITS,
181+
'raw_results' => [
182+
'media' => [
183+
'id' => 'SOME_ID',
184+
'type' => 'SOME_TYPE',
185+
'created' => "2021-02-16T17:02:53.519Z",
186+
'last_updated' => "2021-02-16T17:02:53.519Z"
187+
]
188+
],
189+
'associated_country_codes' => self::SOME_COUNTRY_CODE,
190+
'search_config' => [
191+
'type' => Constants::WITH_CUSTOM_ACCOUNT,
192+
'remove_deceased' => true,
193+
'share_url' => true,
194+
'api_key' => self::SOME_API_KEY,
195+
'monitoring' => false,
196+
'client_ref' => self::SOME_CLIENT_REF,
197+
'tags' => $someTags,
198+
'sources' => [
199+
'type' => Constants::PROFILE,
200+
'search_profile' => self::SOME_SEARCH_PROFILE
201+
],
202+
'matching_strategy' => [
203+
'type' => Constants::FUZZY,
204+
'fuzziness' => self::SOME_FUZZINESS
205+
]
206+
]
207+
]
208+
];
209+
210+
$result2 = new ReportResponse($input2);
211+
212+
$this->assertEquals(
213+
self::SOME_SEARCH_PROFILE,
214+
$result2->getWatchlistSummary()->getSearchConfig()->getSources()->getSearchProfile()
215+
);
216+
217+
$this->assertInstanceOf(
218+
MediaResponse::class,
219+
$result2->getWatchlistSummary()->getRawResults()->getMedia()
220+
);
221+
222+
$this->assertEquals(
223+
self::SOME_FUZZINESS,
224+
$result2->getWatchlistSummary()->getSearchConfig()->getMatchingStrategy()->getFuzziness()
225+
);
226+
227+
$this->assertEquals(
228+
self::SOME_API_KEY,
229+
$result2->getWatchlistSummary()->getSearchConfig()->getApiKey()
230+
);
231+
232+
$this->assertFalse(
233+
$result2->getWatchlistSummary()->getSearchConfig()->getMonitoring()
234+
);
235+
236+
$this->assertEquals(
237+
$tags,
238+
$result2->getWatchlistSummary()->getSearchConfig()->getTags()
239+
);
240+
241+
$this->assertEquals(
242+
self::SOME_CLIENT_REF,
243+
$result2->getWatchlistSummary()->getSearchConfig()->getCLientRef()
244+
);
245+
}
246+
247+
/**
248+
* @test
249+
* @covers \Yoti\DocScan\Session\Retrieve\WatchlistScreeningSearchConfigResponse::__construct
250+
* @covers \Yoti\DocScan\Session\Retrieve\WatchlistScreeningSearchConfigResponse::getCategories
251+
*/
252+
public function shouldBuildWithWatchlistScreening()
253+
{
254+
$input = [
255+
'watchlist_summary' => [
256+
'total_hits' => self::TOTAL_HITS,
257+
'search_config' => [
258+
'categories' => self::SOME_CATEGORIES
259+
]
260+
]
261+
];
262+
$result = new ReportResponse($input);
263+
264+
$this->assertEquals(
265+
self::SOME_CATEGORIES,
266+
$result->getWatchlistSummary()->getSearchConfig()->getCategories()
267+
);
268+
}
48269
}

0 commit comments

Comments
 (0)