Skip to content

Commit

Permalink
first template test
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasVHG committed Jun 6, 2024
1 parent 51ffe29 commit 5c7dc1f
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions tests/UiTiDv1/Listeners/UnblockConsumersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@

namespace Tests\UiTiDv1\Listeners;

use App\Domain\Integrations\Events\IntegrationUnblocked;
use App\Domain\Integrations\Integration;
use App\Domain\Integrations\IntegrationPartnerStatus;
use App\Domain\Integrations\IntegrationStatus;
use App\Domain\Integrations\IntegrationType;
use App\Domain\Integrations\Repositories\IntegrationRepository;
use App\UiTiDv1\Listeners\UnblockConsumers;
use App\UiTiDv1\Repositories\UiTiDv1ConsumerRepository;
use App\UiTiDv1\UiTiDv1Consumer;
use App\UiTiDv1\UiTiDv1Environment;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Response;
use LogicException;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Http\Message\RequestInterface;
use Psr\Log\NullLogger;
use Ramsey\Uuid\Uuid;
use Tests\TestCase;
use Tests\UiTiDv1\CreatesMockUiTiDv1ClusterSDK;

Expand Down Expand Up @@ -40,6 +51,98 @@ public function setUp(): void

public function test_it_can_unblock_consumers(): void
{
$integrationId = Uuid::uuid4();

$integration = new Integration(
$integrationId,
IntegrationType::EntryApi,
'dummy',
'This is a dummy',
Uuid::uuid4(),
IntegrationStatus::Blocked,
IntegrationPartnerStatus::THIRD_PARTY
);

$consumers = [
new UiTiDv1Consumer(
Uuid::uuid4(),
$integrationId,
'4135',
'mock-consumer-key-1',
'mock-consumer-secret-1',
'mock-api-key-1',
UiTiDv1Environment::Acceptance
),
new UiTiDv1Consumer(
Uuid::uuid4(),
$integrationId,
'4136',
'mock-consumer-key-2',
'mock-consumer-secret-2',
'mock-api-key-2',
UiTiDv1Environment::Testing
),
new UiTiDv1Consumer(
Uuid::uuid4(),
$integrationId,
'4137',
'mock-consumer-key-3',
'mock-consumer-secret-3',
'mock-api-key-3',
UiTiDv1Environment::Production
),
];

$this->consumerRepository
->expects($this->once())
->method('getByIntegrationId')
->with($integrationId)
->willReturn($consumers);

$this->integrationRepository
->expects($this->once())
->method('getById')
->with($integrationId)
->willReturn($integration);

$this->httpClient
->expects($this->exactly(3))
->method('request')
->willReturnCallback(
fn (string $actualMethod, string $actualUri) =>
match ([$actualMethod, $actualUri]) {
[
'POST',
'serviceconsumer/mock-consumer-key-1',
/*[
'http_errors' => false,
'headers' => ['content-type' => 'application/x-www-form-urlencoded'],
'body' => 'status=ACTIVE&group=1&group=2',
],*/
],
[
'POST',
'serviceconsumer/mock-consumer-key-2',
/*[
'http_errors' => false,
'headers' => ['content-type' => 'application/x-www-form-urlencoded'],
'body' => 'status=ACTIVE&group=1&group=2',
],*/
],
[
'POST',
'serviceconsumer/mock-consumer-key-3',
/*[
'http_errors' => false,
'headers' => ['content-type' => 'application/x-www-form-urlencoded'],
'body' => 'status=ACTIVE&group=1&group=2',
],*/
] => new Response(200, [], ''),
default => throw new \LogicException('Invalid arguments received'),
}
);


$this->unblockConsumers->handle(new IntegrationUnblocked($integrationId));
}
}

0 comments on commit 5c7dc1f

Please sign in to comment.