Skip to content

Commit 15dc438

Browse files
committed
Unit test fixes for value object usage
1 parent 353c5c6 commit 15dc438

File tree

2 files changed

+31
-48
lines changed

2 files changed

+31
-48
lines changed

service-api/app/test/AppTest/DataAccess/DynamoDb/ViewerCodesTest.php

+23-38
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use App\DataAccess\DynamoDb\ViewerCodes;
88
use App\DataAccess\Repository\KeyCollisionException;
9+
use App\Entity\Value\LpaUid;
910
use Aws\CommandInterface;
1011
use Aws\DynamoDb\DynamoDbClient;
1112
use Aws\DynamoDb\Exception\DynamoDbException;
@@ -113,7 +114,7 @@ public function cannot_lookup_a_missing_code(): void
113114
#[Test]
114115
public function can_query_by_lpa_id(): void
115116
{
116-
$testSiriusUid = '98765-43210';
117+
$testSiriusUid = new LpaUid('98765-43210');
117118

118119
$this->dynamoDbClientProphecy->query(
119120
Argument::that(function (array $data) use ($testSiriusUid) {
@@ -154,7 +155,7 @@ public function can_query_by_lpa_id(): void
154155
#[Test]
155156
public function lpa_with_no_generated_codes_returns_empty_array(): void
156157
{
157-
$testSiriusUid = '98765-43210';
158+
$testSiriusUid = new LpaUid('98765-43210');
158159

159160
$this->dynamoDbClientProphecy->query(
160161
Argument::that(function (array $data) use ($testSiriusUid) {
@@ -191,8 +192,7 @@ public function add_unique_code_for_Sirius_LPA(): void
191192
{
192193
$testCode = 'test-code';
193194
$testUserLpaActorToken = 'test-token';
194-
$testSiriusUid = 'test-uid';
195-
$testLpaUid = 'null';
195+
$testLpaUid = new LpaUid('98765-43210');
196196
$testExpires = new DateTime();
197197
$testOrganisation = 'test-organisation';
198198
$testActorId = '123';
@@ -201,11 +201,10 @@ public function add_unique_code_for_Sirius_LPA(): void
201201
Argument::that(function (array $data) use (
202202
$testCode,
203203
$testUserLpaActorToken,
204-
$testSiriusUid,
205204
$testLpaUid,
206205
$testExpires,
207206
$testOrganisation,
208-
$testActorId
207+
$testActorId,
209208
) {
210209
$this->assertArrayHasKey('TableName', $data);
211210
$this->assertEquals(self::TABLE_NAME, $data['TableName']);
@@ -220,7 +219,7 @@ public function add_unique_code_for_Sirius_LPA(): void
220219

221220
$this->assertEquals(['S' => $testCode], $data['Item']['ViewerCode']);
222221
$this->assertEquals(['S' => $testUserLpaActorToken], $data['Item']['UserLpaActor']);
223-
$this->assertEquals(['S' => $testSiriusUid], $data['Item']['SiriusUid']);
222+
$this->assertEquals(['S' => $testLpaUid], $data['Item']['SiriusUid']);
224223
$this->assertEquals(['S' => $testExpires->format('c')], $data['Item']['Expires']);
225224
$this->assertEquals(['S' => $testOrganisation], $data['Item']['Organisation']);
226225

@@ -235,16 +234,20 @@ public function add_unique_code_for_Sirius_LPA(): void
235234

236235
$repo->add(
237236
$testCode,
238-
$testUserLpaActorToken, $testSiriusUid, $testLpaUid, $testExpires, $testOrganisation, $testActorId);
237+
$testUserLpaActorToken,
238+
$testLpaUid,
239+
$testExpires,
240+
$testOrganisation,
241+
$testActorId
242+
);
239243
}
240244

241245
#[Test]
242246
public function add_unique_code_for_data_store_LPA(): void
243247
{
244248
$testCode = 'test-code';
245249
$testUserLpaActorToken = 'test-token';
246-
$testSiriusUid = null;
247-
$testLpaUid = 'M-test-uid';
250+
$testLpaUid = new LpaUid('M-1098-7654-3210');
248251
$testExpires = new DateTime();
249252
$testOrganisation = 'test-organisation';
250253
$testActorId = '123';
@@ -253,11 +256,10 @@ public function add_unique_code_for_data_store_LPA(): void
253256
Argument::that(function (array $data) use (
254257
$testCode,
255258
$testUserLpaActorToken,
256-
$testSiriusUid,
257259
$testLpaUid,
258260
$testExpires,
259261
$testOrganisation,
260-
$testActorId
262+
$testActorId,
261263
) {
262264
$this->assertArrayHasKey('TableName', $data);
263265
$this->assertEquals(self::TABLE_NAME, $data['TableName']);
@@ -272,7 +274,7 @@ public function add_unique_code_for_data_store_LPA(): void
272274

273275
$this->assertEquals(['S' => $testCode], $data['Item']['ViewerCode']);
274276
$this->assertEquals(['S' => $testUserLpaActorToken], $data['Item']['UserLpaActor']);
275-
$this->assertEquals(['S' => $testLpaUid], $data['Item']['LpaUid']);
277+
$this->assertEquals(['S' => $testLpaUid], $data['Item']['SiriusUid']);
276278
$this->assertEquals(['S' => $testExpires->format('c')], $data['Item']['Expires']);
277279
$this->assertEquals(['S' => $testOrganisation], $data['Item']['Organisation']);
278280

@@ -287,27 +289,12 @@ public function add_unique_code_for_data_store_LPA(): void
287289

288290
$repo->add(
289291
$testCode,
290-
$testUserLpaActorToken, $testSiriusUid, $testLpaUid, $testExpires, $testOrganisation, $testActorId);
291-
}
292-
293-
#[Test]
294-
public function throw_exception_when_add_unique_code_called_wih_null_uid(): void
295-
{
296-
$testCode = 'test-code';
297-
$testUserLpaActorToken = 'test-token';
298-
$testSiriusUid = null;
299-
$testLpaUid = null;
300-
$testExpires = new DateTime();
301-
$testOrganisation = 'test-organisation';
302-
$testActorId = '123';
303-
304-
$repo = new ViewerCodes($this->dynamoDbClientProphecy->reveal(), self::TABLE_NAME);
305-
306-
$this->expectException(\Exception::class);
307-
308-
$repo->add(
309-
$testCode,
310-
$testUserLpaActorToken, $testSiriusUid, $testLpaUid, $testExpires, $testOrganisation, $testActorId);
292+
$testUserLpaActorToken,
293+
$testLpaUid,
294+
$testExpires,
295+
$testOrganisation,
296+
$testActorId
297+
);
311298
}
312299

313300
#[Test]
@@ -333,8 +320,7 @@ public function add_conflicting_code(): void
333320
$repo->add(
334321
'test-val',
335322
'test-val',
336-
'test-val',
337-
'test-val',
323+
new LpaUid('M-1098-7654-3210'),
338324
new DateTime(),
339325
'test-val',
340326
'123'
@@ -358,8 +344,7 @@ public function test_unknown_exception_when_adding_code(): void
358344
$repo->add(
359345
'test-val',
360346
'test-val',
361-
'test-val',
362-
'test-val',
347+
new LpaUid('M-1098-7654-3210'),
363348
new DateTime(),
364349
'test-val',
365350
'123'

service-api/app/test/AppTest/Service/ViewerCodes/ViewerCodeServiceTest.php

+8-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\DataAccess\Repository\UserLpaActorMapInterface;
99
use App\DataAccess\Repository\ViewerCodeActivityInterface;
1010
use App\DataAccess\Repository\ViewerCodesInterface;
11+
use App\Entity\Value\LpaUid;
1112
use App\Service\ViewerCodes\ViewerCodeService;
1213
use DateTime;
1314
use DateTimeImmutable;
@@ -54,8 +55,7 @@ public function it_will_make_a_new_viewer_code_for_a_Sirius_lpa(): void
5455
->add(
5556
Argument::type('string'),
5657
'id',
57-
'700000000047',
58-
null,
58+
new LpaUid('700000000047'),
5959
$codeExpiry,
6060
'token name',
6161
'1234'
@@ -109,8 +109,7 @@ public function it_will_make_a_new_viewer_code_for_a_data_store_lpa(): void
109109
->add(
110110
Argument::type('string'),
111111
'id',
112-
null,
113-
'M-XXXX-1212-ZZZZ',
112+
Argument::that(fn(LpaUid $value) => $value->getLpaUid() === 'M-XXXX-1212-ZZZZ'),
114113
$codeExpiry,
115114
'token name',
116115
'1234'
@@ -125,10 +124,10 @@ public function it_will_make_a_new_viewer_code_for_a_data_store_lpa(): void
125124
->shouldBeCalled()
126125
->willReturn(
127126
[
128-
'Id' => 'id',
129-
'UserId' => 'user_id',
130-
'LpaUid' => 'M-XXXX-1212-ZZZZ',
131-
'ActorId' => '1234',
127+
'Id' => 'id',
128+
'UserId' => 'user_id',
129+
'LpaUid' => 'M-XXXX-1212-ZZZZ',
130+
'ActorId' => '1234',
132131
]
133132
);
134133

@@ -192,8 +191,7 @@ public function it_will_generate_codes_until_a_new_one_is_found(): void
192191
->add(
193192
Argument::type('string'),
194193
'id',
195-
'700000000047',
196-
null,
194+
new LpaUid('700000000047'),
197195
Argument::type(DateTime::class),
198196
'token name',
199197
'1234'

0 commit comments

Comments
 (0)