From 1831bc4470ff551f16236c3f6d89368c8e6a4df2 Mon Sep 17 00:00:00 2001 From: call-me-matt Date: Tue, 11 Aug 2020 23:38:06 +0200 Subject: update social avatars in chunks Signed-off-by: call-me-matt --- tests/unit/Service/SocialApiServiceTest.php | 66 ++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'tests/unit/Service/SocialApiServiceTest.php') diff --git a/tests/unit/Service/SocialApiServiceTest.php b/tests/unit/Service/SocialApiServiceTest.php index a2033a41..47442c88 100644 --- a/tests/unit/Service/SocialApiServiceTest.php +++ b/tests/unit/Service/SocialApiServiceTest.php @@ -37,6 +37,7 @@ use OCA\DAV\CardDAV\CardDavBackend; use OCP\IURLGenerator; use OCP\IL10N; use OCP\Util; +use OCP\AppFramework\Utility\ITimeFactory; use PHPUnit\Framework\MockObject\MockObject; use ChristophWurst\Nextcloud\Testing\TestCase; @@ -58,6 +59,8 @@ class SocialApiServiceTest extends TestCase { private $urlGen; /** @var CardDavBackend|MockObject */ private $davBackend; + /** @var ITimeFactory|MockObject */ + private $timeFactory; public function socialProfileProvider() { return [ @@ -88,6 +91,7 @@ class SocialApiServiceTest extends TestCase { $this->l10n = $this->createMock(IL10N::class); $this->urlGen = $this->createMock(IURLGenerator::class); $this->davBackend = $this->createMock(CardDavBackend::class); + $this->timeFactory = $this->createMock(ITimeFactory::class); $this->service = new SocialApiService( $this->socialProvider, $this->manager, @@ -95,7 +99,8 @@ class SocialApiServiceTest extends TestCase { $this->clientService, $this->l10n, $this->urlGen, - $this->davBackend + $this->davBackend, + $this->timeFactory ); } @@ -264,6 +269,9 @@ class SocialApiServiceTest extends TestCase { $this->config ->method('getUserValue') ->willReturn($bgSyncEnabledByUser); + $this->timeFactory + ->method('getTime') + ->willReturn(10); $this->setupAddressbooks(); @@ -284,4 +292,60 @@ class SocialApiServiceTest extends TestCase { $this->assertNotContains('Empty Contact', $report[0]['failed']['404']); } } + + + public function testUpdateAddressbooksTimeout() { + $this->config + ->method('getAppValue') + ->willReturn('yes'); + $this->config + ->method('getUserValue') + ->willReturn('yes'); + $this->timeFactory + ->method('getTime') + ->willReturnOnConsecutiveCalls(10, 11, 999); + + $this->setupAddressbooks(); + + $result = $this->service->updateAddressbooks('any', 'msstest'); + + $this->assertEquals(Http::STATUS_PARTIAL_CONTENT, $result->getStatus()); + + $report = $result->getData(); + + $this->assertArrayHasKey('0', $report); + $this->assertArrayHasKey('stoppedAt', $report[0]); + $this->assertArrayHasKey('addressBook', $report[0]['stoppedAt']); + $this->assertArrayHasKey('contact', $report[0]['stoppedAt']); + } + + /** + * @dataProvider updateAddressbookProvider + */ + public function testUpdateAddressbooksContinued($syncAllowedByAdmin, $bgSyncEnabledByUser, $expected) { + $this->config + ->method('getAppValue') + ->willReturn($syncAllowedByAdmin); + $this->config + ->method('getUserValue') + ->willReturn($bgSyncEnabledByUser); + $this->timeFactory + ->method('getTime') + ->willReturn(10); + + $this->setupAddressbooks(); + + $result = $this->service->updateAddressbooks('any', 'mrstest', 'contacts2', '22222222-2222-2222-2222-222222222222'); + + $this->assertEquals($expected, $result->getStatus()); + + if (($syncAllowedByAdmin === 'yes') && ($bgSyncEnabledByUser === 'yes')) { + $report = $result->getData(); + $this->assertArrayHasKey('0', $report); + $this->assertArrayHasKey('updated', $report[0]); + $this->assertNotContains('Valid Contact One', $report[0]['updated']); + $this->assertArrayHasKey('checked', $report[0]); + $this->assertContains('Valid Contact Two', $report[0]['checked']); + } + } } -- cgit v1.2.3 From ba67a50ecedc7dfa9eba36992726504c0e6d39bc Mon Sep 17 00:00:00 2001 From: call-me-matt Date: Sun, 6 Sep 2020 00:48:04 +0200 Subject: perform sanity checks Signed-off-by: call-me-matt --- tests/unit/Service/SocialApiServiceTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/unit/Service/SocialApiServiceTest.php') diff --git a/tests/unit/Service/SocialApiServiceTest.php b/tests/unit/Service/SocialApiServiceTest.php index 47442c88..47bd21ac 100644 --- a/tests/unit/Service/SocialApiServiceTest.php +++ b/tests/unit/Service/SocialApiServiceTest.php @@ -348,4 +348,24 @@ class SocialApiServiceTest extends TestCase { $this->assertContains('Valid Contact Two', $report[0]['checked']); } } + + public function testExistsContact() { + $this->setupAddressbooks(); + + // all good: + $result = $this->service->existsContact('11111111-1111-1111-1111-111111111111', 'contacts1', 'admin'); + $this->assertEquals(true, $result); + + // wrong address book: + $result = $this->service->existsContact('22222222-2222-2222-2222-222222222222', 'contacts1', 'admin'); + $this->assertEquals(false, $result); + + // invalid contactId: + $result = $this->service->existsContact('not-existing', 'contacts1', 'admin'); + $this->assertEquals(false, $result); + + // invalid addressbookId: + $result = $this->service->existsContact('11111111-1111-1111-1111-111111111111', 'not-existing', 'admin'); + $this->assertEquals(false, $result); + } } -- cgit v1.2.3