Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/notifications.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-09-30 10:40:25 +0300
committerJoas Schilling <coding@schilljs.com>2020-09-30 10:40:25 +0300
commitf29d53790984b4c6e292b2c3c50ccbd5446608d7 (patch)
tree059095d55d80a0fc4cb9679842e090236328ae28 /tests/Unit
parent9ade32fe9aab26b2be0c05817e399982465ecc96 (diff)
Add test for the new code
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests/Unit')
-rw-r--r--tests/Unit/PushTest.php39
1 files changed, 36 insertions, 3 deletions
diff --git a/tests/Unit/PushTest.php b/tests/Unit/PushTest.php
index c6e2cbe..63497ba 100644
--- a/tests/Unit/PushTest.php
+++ b/tests/Unit/PushTest.php
@@ -405,7 +405,7 @@ class PushTest extends TestCase {
* @param bool $isDebug
*/
public function testPushToDeviceSending($isDebug) {
- $push = $this->getPush(['getDevicesForUser', 'encryptAndSign', 'deletePushToken', 'validateToken']);
+ $push = $this->getPush(['getDevicesForUser', 'encryptAndSign', 'deletePushToken', 'validateToken', 'deletePushTokenByDeviceIdentifier']);
/** @var INotification|MockObject $notification */
$notification = $this->createMock(INotification::class);
@@ -449,6 +449,11 @@ class PushTest extends TestCase {
'token' => 64,
'apptype' => 'other',
],
+ [
+ 'proxyserver' => 'badrequest-with-devices',
+ 'token' => 128,
+ 'apptype' => 'other',
+ ],
]);
$this->config
@@ -474,11 +479,11 @@ class PushTest extends TestCase {
->with($user)
->willReturn($key);
- $push->expects($this->exactly(5))
+ $push->expects($this->exactly(6))
->method('validateToken')
->willReturn(true);
- $push->expects($this->exactly(5))
+ $push->expects($this->exactly(6))
->method('encryptAndSign')
->willReturn(['Payload']);
@@ -581,6 +586,34 @@ class PushTest extends TestCase {
])
->willReturn($response3);
+ /** @var IResponse|MockObject $response1 */
+ $response4 = $this->createMock(IResponse::class);
+ $response4->expects($this->once())
+ ->method('getStatusCode')
+ ->willReturn(Http::STATUS_BAD_REQUEST);
+ $response4->expects($this->once())
+ ->method('getBody')
+ ->willReturn(json_encode([
+ 'failed' => 1,
+ 'unknown' => [
+ '123456'
+ ]
+ ]));
+ $e = $this->createMock(ClientException::class);
+ $e->method('getResponse')
+ ->willReturn($response4);
+ $client->expects($this->at(4))
+ ->method('post')
+ ->with('badrequest-with-devices/notifications', [
+ 'body' => [
+ 'notifications' => ['["Payload"]'],
+ ],
+ ])
+ ->willThrowException($e);
+
+ $push->method('deletePushTokenByDeviceIdentifier')
+ ->with('123456');
+
$push->pushToDevice(207787, $notification);
}