summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2020-09-11 12:28:56 +0200
committerGitHub <noreply@github.com>2020-09-11 12:28:56 +0200
commit96f05d6a5cf3e34b572f26f3320d9b54e36b7f24 (patch)
tree9298ac252afb739b34a14a3d5e876c755f4bba5c /tests
parentce8992545a4bc9b63fb10a69380b5457880002cc (diff)
parentc03bd908b6df2018b54fc6cdbdd90dca922e1c10 (diff)
Merge pull request #1745 from call-me-matt/enh/social-chunks
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/Service/SocialApiServiceTest.php86
1 files changed, 85 insertions, 1 deletions
diff --git a/tests/unit/Service/SocialApiServiceTest.php b/tests/unit/Service/SocialApiServiceTest.php
index 8b5db3d3..327bf161 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,80 @@ 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']);
+ }
+ }
+
+ 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);
+ }
}