Skip to content

Commit

Permalink
Add a comment for the array check
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Oct 1, 2020
1 parent 0e66c05 commit 938c005
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
3 changes: 3 additions & 0 deletions lib/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
namespace OCA\Notifications;


use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;
use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Token\IProvider;
use OC\Security\IdentityProof\Key;
Expand Down Expand Up @@ -297,6 +299,7 @@ protected function sendNotificationsToProxies(): void {

if (is_array($bodyData) && isset($bodyData['unknown'], $bodyData['failed'])) {
if (is_array($bodyData['unknown'])) {
// Proxy returns null when the array is empty
foreach ($bodyData['unknown'] as $unknownDevice) {
$this->printInfo('Deleting device because it is unknown by the push server: ' . $unknownDevice);
$this->deletePushTokenByDeviceIdentifier($unknownDevice);
Expand Down
43 changes: 22 additions & 21 deletions tests/Unit/PushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
namespace OCA\Notifications\Tests\Unit;


use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;
use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Token\IProvider;
use OC\Security\IdentityProof\Key;
Expand Down Expand Up @@ -407,7 +409,7 @@ public function testPushToDeviceSending($isDebug) {

/** @var INotification|MockObject $notification */
$notification = $this->createMock(INotification::class);
$notification->expects($this->exactly(3))
$notification
->method('getUser')
->willReturn('valid');

Expand Down Expand Up @@ -454,10 +456,9 @@ public function testPushToDeviceSending($isDebug) {
],
]);

$this->config->expects($this->exactly(2))
$this->config->expects($this->exactly(1))
->method('getSystemValue')
->willReturnMap([
['debug', false, $isDebug],
['force_language', false, false],
]);

Expand Down Expand Up @@ -506,10 +507,10 @@ public function testPushToDeviceSending($isDebug) {
$client->expects($this->at(0))
->method('post')
->with('proxyserver1/notifications', [
'body' => [
'notifications' => ['["Payload"]', '["Payload"]'],
],
])
'body' => [
'notifications' => ['["Payload"]', '["Payload"]'],
],
])
->willThrowException($e);

$this->logger->expects($this->at(0))
Expand All @@ -533,11 +534,11 @@ public function testPushToDeviceSending($isDebug) {
$client->expects($this->at(1))
->method('post')
->with('badrequest/notifications', [
'body' => [
'notifications' => ['["Payload"]'],
],
])
->willReturn($response1);
'body' => [
'notifications' => ['["Payload"]'],
],
])
->willThrowException($e);

$this->logger->expects($this->at(1))
->method('warning')
Expand All @@ -558,11 +559,11 @@ public function testPushToDeviceSending($isDebug) {
$client->expects($this->at(2))
->method('post')
->with('unavailable/notifications', [
'body' => [
'notifications' => ['["Payload"]'],
],
])
->willReturn($response2);
'body' => [
'notifications' => ['["Payload"]'],
],
])
->willThrowException($e);

$this->logger->expects($this->at(2))
->method('debug')
Expand All @@ -580,10 +581,10 @@ public function testPushToDeviceSending($isDebug) {
$client->expects($this->at(3))
->method('post')
->with('ok/notifications', [
'body' => [
'notifications' => ['["Payload"]'],
],
])
'body' => [
'notifications' => ['["Payload"]'],
],
])
->willReturn($response3);

/** @var IResponse|MockObject $response1 */
Expand Down

0 comments on commit 938c005

Please sign in to comment.