diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2022-03-25 13:37:57 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2022-04-07 19:34:32 +0300 |
commit | 9063c6e36e314c77401fa4be5abf02a41c0d0a57 (patch) | |
tree | 336be567876f3a792a2b6f091fddc820c89203bf /tests | |
parent | 2bbcbb9d59e30c87126f048d41c7030680c773d3 (diff) |
Add a background worker job that flushes the outbox
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Integration/Service/OutboxServiceIntegrationTest.php | 39 | ||||
-rw-r--r-- | tests/Unit/Service/OutboxServiceTest.php | 19 |
2 files changed, 56 insertions, 2 deletions
diff --git a/tests/Integration/Service/OutboxServiceIntegrationTest.php b/tests/Integration/Service/OutboxServiceIntegrationTest.php index 501433d16..cbfa17c13 100644 --- a/tests/Integration/Service/OutboxServiceIntegrationTest.php +++ b/tests/Integration/Service/OutboxServiceIntegrationTest.php @@ -37,6 +37,7 @@ use OCA\Mail\Db\MailAccount; use OCA\Mail\Db\MailboxMapper; use OCA\Mail\Db\MessageMapper; use OCA\Mail\IMAP\IMAPClientFactory; +use OCA\Mail\Service\AccountService; use OCA\Mail\Service\Attachment\AttachmentService; use OCA\Mail\Service\Attachment\AttachmentStorage; use OCA\Mail\Service\OutboxService; @@ -45,11 +46,13 @@ use OCA\Mail\Tests\Integration\Framework\ImapTest; use OCA\Mail\Tests\Integration\Framework\ImapTestAccount; use OCA\Mail\Tests\Integration\TestCase; use OCP\AppFramework\Db\DoesNotExistException; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Folder; use OCP\IServerContainer; use OCP\IUser; use Psr\Container\ContainerInterface; +use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; class OutboxServiceIntegrationTest extends TestCase { @@ -84,6 +87,12 @@ class OutboxServiceIntegrationTest extends TestCase { /** @var Folder */ private $userFolder; + /** @var */ + private $accountService; + + /** @var ITimeFactory */ + private $timeFactory; + protected function setUp(): void { parent::setUp(); @@ -109,6 +118,8 @@ class OutboxServiceIntegrationTest extends TestCase { $this->transmission = OC::$server->get(IMailTransmission::class); $this->eventDispatcher = OC::$server->get(IEventDispatcher::class); $this->clientFactory = OC::$server->get(IMAPClientFactory::class); + $this->accountService = OC::$server->get(AccountService::class); + $this->timeFactory = OC::$server->get(ITimeFactory::class); $this->db = \OC::$server->getDatabaseConnection(); $qb = $this->db->getQueryBuilder(); @@ -121,7 +132,10 @@ class OutboxServiceIntegrationTest extends TestCase { $this->attachmentService, $this->eventDispatcher, $this->clientFactory, - $mailManager + $mailManager, + $this->accountService, + $this->timeFactory, + $this->createMock(LoggerInterface::class) ); } @@ -348,4 +362,27 @@ class OutboxServiceIntegrationTest extends TestCase { $this->expectException(DoesNotExistException::class); $this->outbox->getMessage($message->getId(), $this->user->getUID()); } + + public function testSaveAndFlush(): void { + $message = new LocalMessage(); + $message->setType(LocalMessage::TYPE_OUTGOING); + $message->setAccountId($this->account->getId()); + $message->setSubject('subject'); + $message->setBody('message'); + $message->setHtml(true); + $message->setSendAt(100); + + $to = [[ + 'label' => 'Penny', + 'email' => 'library@stardewvalley.com' + ]]; + + $saved = $this->outbox->saveMessage(new Account($this->account), $message, $to, [], []); + $this->assertNotEmpty($saved->getRecipients()); + $this->assertEmpty($saved->getAttachments()); + + $this->outbox->flush(); + $this->expectException(DoesNotExistException::class); + $this->outbox->getMessage($saved->getId(), $this->user->getUID()); + } } diff --git a/tests/Unit/Service/OutboxServiceTest.php b/tests/Unit/Service/OutboxServiceTest.php index c743f635b..78b857bc5 100644 --- a/tests/Unit/Service/OutboxServiceTest.php +++ b/tests/Unit/Service/OutboxServiceTest.php @@ -36,6 +36,7 @@ use OCA\Mail\Db\LocalMessageMapper; use OCA\Mail\Db\Recipient; use OCA\Mail\Exception\ClientException; use OCA\Mail\IMAP\IMAPClientFactory; +use OCA\Mail\Service\AccountService; use OCA\Mail\Service\Attachment\AttachmentService; use OCA\Mail\Service\MailTransmission; use OCA\Mail\Service\OutboxService; @@ -43,6 +44,7 @@ use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Utility\ITimeFactory; use OCP\DB\Exception; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; class OutboxServiceTest extends TestCase { @@ -71,6 +73,15 @@ class OutboxServiceTest extends TestCase { /** @var IMailManager|MockObject */ private $mailManager; + /** @var AccountService|MockObject */ + private $accountService; + + /** @var ITimeFactory|MockObject */ + private $timeFactory; + + /** @var MockObject|LoggerInterface */ + private $logger; + protected function setUp(): void { parent::setUp(); @@ -79,13 +90,19 @@ class OutboxServiceTest extends TestCase { $this->attachmentService = $this->createMock(AttachmentService::class); $this->clientFactory = $this->createMock(IMAPClientFactory::class); $this->mailManager = $this->createMock(IMailManager::class); + $this->accountService = $this->createMock(AccountService::class); + $this->timeFactory = $this->createMock(ITimeFactory::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->outboxService = new OutboxService( $this->transmission, $this->mapper, $this->attachmentService, $this->createMock(EventDispatcher::class), $this->clientFactory, - $this->mailManager + $this->mailManager, + $this->accountService, + $this->timeFactory, + $this->logger, ); $this->userId = 'linus'; $this->time = $this->createMock(ITimeFactory::class); |