diff --git a/lib/RetailCrm/Client/ApiVersion5.php b/lib/RetailCrm/Client/ApiVersion5.php index b9af3d6..c4fd5c0 100644 --- a/lib/RetailCrm/Client/ApiVersion5.php +++ b/lib/RetailCrm/Client/ApiVersion5.php @@ -44,6 +44,7 @@ class ApiVersion5 extends AbstractLoader use V5\Delivery; use V5\Files; use V5\Module; + use V5\Notifications; use V5\Orders; use V5\Packs; use V5\References; diff --git a/lib/RetailCrm/Methods/V5/Notifications.php b/lib/RetailCrm/Methods/V5/Notifications.php new file mode 100644 index 0000000..e3121eb --- /dev/null +++ b/lib/RetailCrm/Methods/V5/Notifications.php @@ -0,0 +1,47 @@ +client->makeRequest( + "/notifications/send", + "POST", + ['notification' => \json_encode($notification, JSON_UNESCAPED_SLASHES)] + ); + } +} diff --git a/tests/RetailCrm/Tests/Methods/Version5/ApiClientNotificationsTest.php b/tests/RetailCrm/Tests/Methods/Version5/ApiClientNotificationsTest.php new file mode 100644 index 0000000..c214953 --- /dev/null +++ b/tests/RetailCrm/Tests/Methods/Version5/ApiClientNotificationsTest.php @@ -0,0 +1,106 @@ +expectException($exceptionClass); + } + $response = $client->request->sendNotification($getNotification()); + if (empty($exceptionClass)) { + static::assertTrue(in_array($response->getStatusCode(), [200, 201])); + static::assertTrue($response->isSuccessful()); + } + } + + /** + * @return array[] + */ + public function notificationsProvider() + { + return [ + 'error_type' => [ + static function () { + $notification = self::getErrorNotification(); + $notification['type'] = 'another'; + + return $notification; + }, + 'InvalidArgumentException', + ], + 'error_message' => [ + static function () { + $notification = self::getErrorNotification(); + $notification['message'] = []; + + return $notification; + }, + 'InvalidArgumentException', + ], + 'error_users_empty' => [ + static function () { + $notification = self::getErrorNotification(); + $notification['userGroups'] = []; + $notification['userIds'] = []; + + return $notification; + }, + 'InvalidArgumentException', + ], + 'error_users_filled' => [ + static function () { + return self::getErrorNotification();; + }, + 'InvalidArgumentException', + ], + 'success_group' => [ + static function () { + $notification = self::getErrorNotification(); + unset($notification['userIds']); + + return $notification; + }, + null, + ], + 'success_ids' => [ + static function () { + $notification = self::getErrorNotification(); + unset($notification['userGroups']); + + return $notification; + }, + null, + ], + ]; + } + + /** + * @return array + */ + protected static function getErrorNotification() + { + return [ + 'type' => 'api.error', + 'userIds' => [1], + 'userGroups' => ['superadmins'], + 'message' => '[Модуль МойСклад] +Возникли проблемы при проверке доступов входа. Введен неверный логин/пароль, проверьте корректность введенных данных.', + ]; + } +}