Skip to content

Commit b33a2be

Browse files
committed
update tests
1 parent 3a55616 commit b33a2be

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/ProjectAanvraag/Listeners/SyncWidgetTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Domain\Contacts\Contact;
99
use App\Domain\Contacts\ContactType;
1010
use App\Domain\Contacts\Repositories\ContactRepository;
11+
use App\Domain\Integrations\Environment;
1112
use App\Domain\Integrations\Events\IntegrationActivated;
1213
use App\Domain\Integrations\Events\IntegrationBlocked;
1314
use App\Domain\Integrations\Events\IntegrationCreated;
@@ -19,6 +20,8 @@
1920
use App\Domain\Integrations\IntegrationType;
2021
use App\Domain\Integrations\Repositories\IntegrationRepository;
2122
use App\Json;
23+
use App\Keycloak\Client;
24+
use App\Keycloak\Repositories\KeycloakClientRepository;
2225
use App\ProjectAanvraag\Listeners\SyncWidget;
2326
use App\ProjectAanvraag\ProjectAanvraagClient;
2427
use App\ProjectAanvraag\ProjectAanvraagUrl;
@@ -47,6 +50,8 @@ final class SyncWidgetTest extends TestCase
4750

4851
private UiTiDv1ConsumerRepository&MockObject $uiTiDv1ConsumerRepository;
4952

53+
private KeycloakClientRepository&MockObject $keycloakClientRepository;
54+
5055
private UserRepository&MockObject $userRepository;
5156

5257
private SyncWidget $syncWidget;
@@ -59,6 +64,7 @@ protected function setUp(): void
5964
$this->integrationRepository = $this->createMock(IntegrationRepository::class);
6065
$this->contactRepository = $this->createMock(ContactRepository::class);
6166
$this->uiTiDv1ConsumerRepository = $this->createMock(UiTiDv1ConsumerRepository::class);
67+
$this->keycloakClientRepository = $this->createMock(KeycloakClientRepository::class);
6268
$this->userRepository = $this->createMock(UserRepository::class);
6369
$logger = $this->createMock(LoggerInterface::class);
6470

@@ -70,6 +76,7 @@ protected function setUp(): void
7076
$this->integrationRepository,
7177
$this->contactRepository,
7278
$this->uiTiDv1ConsumerRepository,
79+
$this->keycloakClientRepository,
7380
123,
7481
$this->userRepository,
7582
$logger
@@ -84,6 +91,8 @@ public function test_it_handles_integration_created(): void
8491

8592
$this->givenThereAreConsumers($integration->id);
8693

94+
$this->givenThereAreClients($integration->id);
95+
8796
$this->assertRequest($integration, 'application_sent');
8897

8998
$this->syncWidget->handleIntegrationCreated(new IntegrationCreated($integration->id));
@@ -97,6 +106,8 @@ public function test_it_handles_integration_activated(): void
97106

98107
$this->givenThereAreConsumers($integration->id);
99108

109+
$this->givenThereAreClients($integration->id);
110+
100111
$this->assertRequest($integration, 'active');
101112

102113
$this->syncWidget->handleIntegrationActivated(new IntegrationActivated($integration->id));
@@ -110,6 +121,8 @@ public function test_it_handles_integration_blocked(): void
110121

111122
$this->givenThereAreConsumers($integration->id);
112123

124+
$this->givenThereAreClients($integration->id);
125+
113126
$this->assertRequest($integration, 'blocked');
114127

115128
$this->syncWidget->handleIntegrationBlocked(new IntegrationBlocked($integration->id));
@@ -123,6 +136,8 @@ public function test_it_handles_integration_deleted(): void
123136

124137
$this->givenThereAreConsumers($integration->id);
125138

139+
$this->givenThereAreClients($integration->id);
140+
126141
$this->assertRequest($integration, 'blocked');
127142

128143
$this->syncWidget->handleIntegrationDeleted(new IntegrationDeleted($integration->id));
@@ -136,6 +151,8 @@ public function test_it_handles_integration_updated(): void
136151

137152
$this->givenThereAreConsumers($integration->id);
138153

154+
$this->givenThereAreClients($integration->id);
155+
139156
$this->assertRequest($integration, 'active');
140157

141158
$this->syncWidget->handleIntegrationUpdated(new IntegrationUpdated($integration->id));
@@ -215,6 +232,30 @@ private function givenThereAreConsumers(UuidInterface $integrationId): void
215232
->willReturn([$testConsumer, $productionConsumer]);
216233
}
217234

235+
private function givenThereAreClients(UuidInterface $integrationId): void
236+
{
237+
$testClient = new Client(
238+
Uuid::uuid4(),
239+
$integrationId,
240+
'client-id-testing',
241+
'client-secret-testing',
242+
Environment::Testing
243+
);
244+
245+
$productionClient = new Client(
246+
Uuid::uuid4(),
247+
$integrationId,
248+
'client-id-production',
249+
'client-secret-production',
250+
Environment::Production
251+
);
252+
253+
$this->keycloakClientRepository->expects($this->once())
254+
->method('getByIntegrationId')
255+
->with($integrationId)
256+
->willReturn([$testClient, $productionClient]);
257+
}
258+
218259
private function assertRequest(Integration $integration, string $state): void
219260
{
220261
$expectedRequest = new Request(
@@ -228,6 +269,8 @@ private function assertRequest(Integration $integration, string $state): void
228269
'groupId' => 123,
229270
'testApiKeySapi3' => 'api-key-testing',
230271
'liveApiKeySapi3' => 'api-key-production',
272+
'testClientId' => 'client-id-testing',
273+
'liveClientId' => 'client-id-production',
231274
'state' => $state,
232275
])
233276
);

0 commit comments

Comments
 (0)