Skip to content

Commit b511814

Browse files
Rodion LiuboretsLuborRod
authored andcommitted
SDK-1840:Add auth type to notification config
1 parent 300f27c commit b511814

File tree

4 files changed

+123
-10
lines changed

4 files changed

+123
-10
lines changed

src/DocScan/Constants.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ class Constants
2525
public const ALWAYS = 'ALWAYS';
2626
public const FALLBACK = 'FALLBACK';
2727
public const NEVER = 'NEVER';
28+
29+
public const BASIC = 'BASIC';
30+
public const BEARER = 'BEARER';
2831
}

src/DocScan/Session/Create/NotificationConfig.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class NotificationConfig implements \JsonSerializable
1414
*/
1515
private $authToken;
1616

17+
/**
18+
* @var string|null
19+
*/
20+
private $authType;
21+
1722
/**
1823
* @var string|null
1924
*/
@@ -27,12 +32,14 @@ class NotificationConfig implements \JsonSerializable
2732
/**
2833
* NotificationConfig constructor.
2934
* @param string|null $authToken
35+
* @param string|null $authType
3036
* @param string|null $endpoint
3137
* @param array<string> $topics
3238
*/
33-
public function __construct(?string $authToken, ?string $endpoint, array $topics = [])
39+
public function __construct(?string $authToken, ?string $authType, ?string $endpoint, array $topics = [])
3440
{
3541
$this->authToken = $authToken;
42+
$this->authType = $authType;
3643
$this->endpoint = $endpoint;
3744
$this->topics = array_unique($topics);
3845
}
@@ -44,6 +51,7 @@ public function jsonSerialize(): \stdClass
4451
{
4552
return (object) Json::withoutNullValues([
4653
'auth_token' => $this->getAuthToken(),
54+
'auth_type' => $this->getAuthType(),
4755
'endpoint' => $this->getEndpoint(),
4856
'topics' => $this->getTopics(),
4957
]);
@@ -57,6 +65,14 @@ public function getAuthToken(): ?string
5765
return $this->authToken;
5866
}
5967

68+
/**
69+
* @return string|null
70+
*/
71+
public function getAuthType(): ?string
72+
{
73+
return $this->authType;
74+
}
75+
6076
/**
6177
* @return string|null
6278
*/

src/DocScan/Session/Create/NotificationConfigBuilder.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Yoti\DocScan\Session\Create;
66

7+
use Yoti\DocScan\Constants;
8+
79
class NotificationConfigBuilder
810
{
911

@@ -17,6 +19,11 @@ class NotificationConfigBuilder
1719
*/
1820
private $authToken;
1921

22+
/**
23+
* @var string
24+
*/
25+
private $authType;
26+
2027
/**
2128
* @var string
2229
*/
@@ -27,46 +34,91 @@ class NotificationConfigBuilder
2734
*/
2835
private $topics = [];
2936

37+
/**
38+
* @param string $authToken
39+
* @return $this
40+
*/
3041
public function withAuthToken(string $authToken): self
3142
{
3243
$this->authToken = $authToken;
3344
return $this;
3445
}
3546

47+
/**
48+
* @return $this
49+
*/
50+
public function withAuthTypeBasic(): self
51+
{
52+
$this->authType = Constants::BASIC;
53+
return $this;
54+
}
55+
56+
/**
57+
* @return $this
58+
*/
59+
public function withAuthTypeBearer(): self
60+
{
61+
$this->authType = Constants::BEARER;
62+
return $this;
63+
}
64+
65+
/**
66+
* @param string $endpoint
67+
* @return $this
68+
*/
3669
public function withEndpoint(string $endpoint): self
3770
{
3871
$this->endpoint = $endpoint;
3972
return $this;
4073
}
4174

75+
/**
76+
* @return $this
77+
*/
4278
public function forResourceUpdate(): self
4379
{
4480
return $this->withTopic(self::RESOURCE_UPDATE);
4581
}
4682

83+
/**
84+
* @param string $topic
85+
* @return $this
86+
*/
4787
public function withTopic(string $topic): self
4888
{
4989
$this->topics[] = $topic;
5090
return $this;
5191
}
5292

93+
/**
94+
* @return $this
95+
*/
5396
public function forTaskCompletion(): self
5497
{
5598
return $this->withTopic(self::TASK_COMPLETION);
5699
}
57100

101+
/**
102+
* @return $this
103+
*/
58104
public function forCheckCompletion(): self
59105
{
60106
return $this->withTopic(self::CHECK_COMPLETION);
61107
}
62108

109+
/**
110+
* @return $this
111+
*/
63112
public function forSessionCompletion(): self
64113
{
65114
return $this->withTopic(self::SESSION_COMPLETION);
66115
}
67116

117+
/**
118+
* @return NotificationConfig
119+
*/
68120
public function build(): NotificationConfig
69121
{
70-
return new NotificationConfig($this->authToken, $this->endpoint, $this->topics);
122+
return new NotificationConfig($this->authToken, $this->authType, $this->endpoint, $this->topics);
71123
}
72124
}

tests/DocScan/Session/Create/NotificationConfigBuilderTest.php

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

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

7+
use Yoti\DocScan\Constants;
78
use Yoti\DocScan\Session\Create\NotificationConfigBuilder;
89
use Yoti\Test\TestCase;
910

@@ -28,7 +29,7 @@ class NotificationConfigBuilderTest extends TestCase
2829
* @covers \Yoti\DocScan\Session\Create\NotificationConfig::getEndpoint
2930
* @covers \Yoti\DocScan\Session\Create\NotificationConfig::getTopics
3031
*/
31-
public function shouldBuildNotificationConfig()
32+
public function shouldBuildNotificationConfig(): void
3233
{
3334
$result = (new NotificationConfigBuilder())
3435
->withAuthToken(self::SOME_AUTH_TOKEN)
@@ -47,7 +48,7 @@ public function shouldBuildNotificationConfig()
4748
* @test
4849
* @covers ::forResourceUpdate
4950
*/
50-
public function shouldUseCorrectValueForResourceUpdate()
51+
public function shouldUseCorrectValueForResourceUpdate(): void
5152
{
5253
$result = (new NotificationConfigBuilder())
5354
->withAuthToken(self::SOME_AUTH_TOKEN)
@@ -62,7 +63,7 @@ public function shouldUseCorrectValueForResourceUpdate()
6263
* @test
6364
* @covers ::forTaskCompletion
6465
*/
65-
public function shouldUseCorrectValueForTaskCompletion()
66+
public function shouldUseCorrectValueForTaskCompletion(): void
6667
{
6768
$result = (new NotificationConfigBuilder())
6869
->withAuthToken(self::SOME_AUTH_TOKEN)
@@ -77,7 +78,7 @@ public function shouldUseCorrectValueForTaskCompletion()
7778
* @test
7879
* @covers ::forCheckCompletion
7980
*/
80-
public function shouldUseCorrectValueForCheckCompletion()
81+
public function shouldUseCorrectValueForCheckCompletion(): void
8182
{
8283
$result = (new NotificationConfigBuilder())
8384
->withAuthToken(self::SOME_AUTH_TOKEN)
@@ -92,7 +93,7 @@ public function shouldUseCorrectValueForCheckCompletion()
9293
* @test
9394
* @covers ::forSessionCompletion
9495
*/
95-
public function shouldUseCorrectValueForSessionCompletion()
96+
public function shouldUseCorrectValueForSessionCompletion(): void
9697
{
9798
$result = (new NotificationConfigBuilder())
9899
->withAuthToken(self::SOME_AUTH_TOKEN)
@@ -111,7 +112,7 @@ public function shouldUseCorrectValueForSessionCompletion()
111112
* @covers ::forSessionCompletion
112113
* @covers ::withTopic
113114
*/
114-
public function shouldAllowAllNotificationTypes()
115+
public function shouldAllowAllNotificationTypes(): void
115116
{
116117
$result = (new NotificationConfigBuilder())
117118
->withAuthToken(self::SOME_AUTH_TOKEN)
@@ -133,7 +134,7 @@ public function shouldAllowAllNotificationTypes()
133134
* @test
134135
* @covers \Yoti\DocScan\Session\Create\NotificationConfig::jsonSerialize
135136
*/
136-
public function shouldSerializeWithCorrectProperties()
137+
public function shouldSerializeWithCorrectProperties(): void
137138
{
138139
$result = (new NotificationConfigBuilder())
139140
->withAuthToken(self::SOME_AUTH_TOKEN)
@@ -156,7 +157,7 @@ public function shouldSerializeWithCorrectProperties()
156157
* @test
157158
* @covers \Yoti\DocScan\Session\Create\NotificationConfig::jsonSerialize
158159
*/
159-
public function shouldSerializeWithoutNullValues()
160+
public function shouldSerializeWithoutNullValues(): void
160161
{
161162
$result = (new NotificationConfigBuilder())->build();
162163

@@ -166,4 +167,45 @@ public function shouldSerializeWithoutNullValues()
166167

167168
$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($result));
168169
}
170+
171+
/**
172+
* @test
173+
* @covers \Yoti\DocScan\Session\Create\NotificationConfig::getAuthType
174+
*/
175+
public function shouldNotImplicitlySetAValueForAuthType(): void
176+
{
177+
$result = (new NotificationConfigBuilder())
178+
->forResourceUpdate()
179+
->build();
180+
181+
$this->assertNull($result->getAuthType());
182+
}
183+
184+
/**
185+
* @test
186+
* @covers \Yoti\DocScan\Session\Create\NotificationConfigBuilder::withAuthTypeBasic
187+
*/
188+
public function shouldSetAuthTypeToBasic()
189+
{
190+
$result = (new NotificationConfigBuilder())
191+
->forResourceUpdate()
192+
->withAuthTypeBasic()
193+
->build();
194+
195+
$this->assertEquals($result->getAuthType(), Constants::BASIC);
196+
}
197+
198+
/**
199+
* @test
200+
* @covers \Yoti\DocScan\Session\Create\NotificationConfigBuilder::withAuthTypeBearer
201+
*/
202+
public function shouldSetAuthTypeToBearer()
203+
{
204+
$result = (new NotificationConfigBuilder())
205+
->forResourceUpdate()
206+
->withAuthTypeBearer()
207+
->build();
208+
209+
$this->assertEquals($result->getAuthType(), Constants::BEARER);
210+
}
169211
}

0 commit comments

Comments
 (0)