Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Service/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ public function sendCodeToSign(string $email, string $name, string $code): void
}
$message->useTemplate($emailTemplate);
try {
$this->mailer->send($message);
if ($this->mailer->send($message) !== []) {
throw new \RuntimeException('Mail transport reported rejected recipients');
}
} catch (\Exception $e) {
$this->logger->error('Mail with code to sign document could not be sent: ' . $e->getMessage());
throw new LibresignException('Mail with code to sign document could not be sent', 1);
Expand Down
28 changes: 28 additions & 0 deletions tests/php/Unit/Service/MailServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,34 @@ public function testRequesterStrategyThrowsWhenFallbackAlsoFails(): void {
$this->service->notifyUnsignedUser($this->mockSignRequest(), 'a@b.coop');
}

public function testSendCodeToSignAcceptsSuccessfulSubmission(): void {
$this->mockEmailTemplate();
$message = $this->mockSystemMessage();
$message->expects($this->once())
->method('setTo')
->with(['recipient@example.com']);
$this->mailer->expects($this->once())
->method('send')
->with($message)
->willReturn([]);

$this->service->sendCodeToSign('recipient@example.com', '', '123456');
}

public function testSendCodeToSignReportsRejectedRecipients(): void {
$this->mockEmailTemplate();
$message = $this->mockSystemMessage();
$this->mailer->expects($this->once())
->method('send')
->with($message)
->willReturn(['recipient@example.com']);
$this->logger->expects($this->once())->method('error');

$this->expectException(LibresignException::class);
$this->expectExceptionMessage('Mail with code to sign document could not be sent');
$this->service->sendCodeToSign('recipient@example.com', 'Recipient', '123456');
}

private function mockSignRequest(string $displayName = 'John Doe'): SignRequest&MockObject {
$signRequest = $this->createMock(SignRequest::class);
$signRequest
Expand Down
Loading