Skip to content

Commit

Permalink
chore(test): add integration test for Users::executeActionsEmail()
Browse files Browse the repository at this point in the history
  • Loading branch information
fschmtt committed Jan 23, 2025
1 parent 00ff821 commit f26a0a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Http/CommandExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function executeCommand(Command $command): void
'body' => $this->serializer->serialize($command->getPayload()),
'headers' => [
'Content-Type' => $command->getContentType()->value,
]
],
],
ContentType::FORM_PARAMS => ['form_params' => $command->getPayload()],
};
Expand Down
10 changes: 9 additions & 1 deletion tests/Integration/Resource/UsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Fschmtt\Keycloak\Representation\Role;
use Fschmtt\Keycloak\Representation\User;
use Fschmtt\Keycloak\Test\Integration\IntegrationTestBehaviour;
use GuzzleHttp\Exception\ServerException;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;

Expand Down Expand Up @@ -195,13 +196,20 @@ public function testExecuteActionsEmail(): void
$username = Uuid::uuid4()->toString();

$users->create('master', new User(
email: '[email protected]',
enabled: true,
username: $username,
));

$user = $this->searchUserByUsername($username);
static::assertInstanceOf(User::class, $user);

$users->executeActionsEmail('master', $user->getId(), ['UPDATE_PASSWORD']);
try {
$users->executeActionsEmail('master', $user->getId(), ['UPDATE_PASSWORD']);
} catch (ServerException $e) {
static::assertSame(500, $e->getResponse()->getStatusCode());
static::assertStringContainsString('Failed to send execute actions email', $e->getResponse()->getBody()->getContents());
}

$users->delete('master', $user->getId());

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Http/CommandExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testCallsClientWithoutBodyIfCommandHasNoRepresentation(): void
'body' => null,
'headers' => [
'Content-Type' => 'application/json',
]
],
],
);

Expand Down

0 comments on commit f26a0a5

Please sign in to comment.