diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index b9672b624b..a4cd2d8ef9 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -108,10 +108,10 @@ App::post('/v1/messaging/providers/mailgun') ->inject('dbForProject') ->inject('response') ->action(function (string $providerId, string $name, string $apiKey, string $domain, Database $dbForProject, Response $response) { - $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; - $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $providerId, - 'name' => $name, + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; + $provider = $dbForProject->createDocument('providers', new Document([ + '$id' => $providerId, + 'name' => $name, 'provider' => 'mailgun', 'type' => 'email', 'credentials' => [ @@ -198,10 +198,10 @@ App::post('/v1/messaging/providers/sendgrid') ->inject('dbForProject') ->inject('response') ->action(function (string $providerId, string $name, string $apiKey, Database $dbForProject, Response $response) { - $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; - $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $providerId, - 'name' => $name, + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; + $provider = $dbForProject->createDocument('providers', new Document([ + '$id' => $providerId, + 'name' => $name, 'provider' => 'sendgrid', 'type' => 'email', 'credentials' => [ @@ -276,17 +276,17 @@ App::post('/v1/messaging/providers/msg91') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_PROVIDER) - ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') + ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('senderId', '', new Text(0), 'Msg91 Sender ID.') ->param('authKey', '', new Text(0), 'Msg91 Auth Key.') ->inject('dbForProject') ->inject('response') ->action(function (string $providerId, string $name, string $senderId, string $authKey, Database $dbForProject, Response $response) { - $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; - $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $providerId, - 'name' => $name, + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; + $provider = $dbForProject->createDocument('providers', new Document([ + '$id' => $providerId, + 'name' => $name, 'provider' => 'msg91', 'type' => 'sms', 'credentials' => [ @@ -374,10 +374,10 @@ App::post('/v1/messaging/providers/telesign') ->inject('dbForProject') ->inject('response') ->action(function (string $providerId, string $name, string $username, string $password, Database $dbForProject, Response $response) { - $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; - $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $providerId, - 'name' => $name, + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; + $provider = $dbForProject->createDocument('providers', new Document([ + '$id' => $providerId, + 'name' => $name, 'provider' => 'telesign', 'type' => 'sms', 'credentials' => [ @@ -465,10 +465,10 @@ App::post('/v1/messaging/providers/textmagic') ->inject('dbForProject') ->inject('response') ->action(function (string $providerId, string $name, string $username, string $apiKey, Database $dbForProject, Response $response) { - $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; - $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $providerId, - 'name' => $name, + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; + $provider = $dbForProject->createDocument('providers', new Document([ + '$id' => $providerId, + 'name' => $name, 'provider' => 'text-magic', 'type' => 'sms', 'credentials' => [ @@ -556,10 +556,10 @@ App::post('/v1/messaging/providers/twilio') ->inject('dbForProject') ->inject('response') ->action(function (string $providerId, string $name, string $accountSid, string $authToken, Database $dbForProject, Response $response) { - $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; - $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $providerId, - 'name' => $name, + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; + $provider = $dbForProject->createDocument('providers', new Document([ + '$id' => $providerId, + 'name' => $name, 'provider' => 'twilio', 'type' => 'sms', 'credentials' => [ @@ -647,10 +647,10 @@ App::post('/v1/messaging/providers/vonage') ->inject('dbForProject') ->inject('response') ->action(function (string $providerId, string $name, string $apiKey, string $apiSecret, Database $dbForProject, Response $response) { - $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; - $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $providerId, - 'name' => $name, + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; + $provider = $dbForProject->createDocument('providers', new Document([ + '$id' => $providerId, + 'name' => $name, 'provider' => 'vonage', 'type' => 'sms', 'credentials' => [ @@ -740,10 +740,10 @@ App::post('/v1/messaging/providers/fcm') ->inject('dbForProject') ->inject('response') ->action(function (string $providerId, string $name, string $serverKey, Database $dbForProject, Response $response) { - $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; - $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $providerId, - 'name' => $name, + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; + $provider = $dbForProject->createDocument('providers', new Document([ + '$id' => $providerId, + 'name' => $name, 'provider' => 'fcm', 'type' => 'push', 'credentials' => [ @@ -823,10 +823,10 @@ App::post('/v1/messaging/providers/apns') ->inject('dbForProject') ->inject('response') ->action(function (string $providerId, string $name, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Database $dbForProject, Response $response) { - $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; - $provider = $dbForProject->createDocument('providers', new Document([ - '$id' => $providerId, - 'name' => $name, + $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; + $provider = $dbForProject->createDocument('providers', new Document([ + '$id' => $providerId, + 'name' => $name, 'provider' => 'apns', 'type' => 'push', 'credentials' => [ diff --git a/app/init.php b/app/init.php index ab4848c068..57d99dac83 100644 --- a/app/init.php +++ b/app/init.php @@ -567,8 +567,8 @@ Database::addFilter( ->find('subscribers', [ Query::equal('targetInternalId', [$document->getInternalId()]), Query::limit(APP_LIMIT_SUBQUERY), - ])) - ); + ]) + )); if (\count($topicIds) > 0) { return $database->find('topics', [Query::equal('$id', $topicIds)]); } @@ -588,8 +588,8 @@ Database::addFilter( ->find('subscribers', [ Query::equal('topicInternalId', [$document->getInternalId()]), Query::limit(APP_LIMIT_SUBQUERY), - ])) - ); + ]) + )); if (\count($targetIds) > 0) { return $database->find('targets', [Query::equal('$id', $targetIds)]); } diff --git a/tests/e2e/Services/Messaging/MessagingBase.php b/tests/e2e/Services/Messaging/MessagingBase.php index 3cb57b6301..1fac9b8f7e 100644 --- a/tests/e2e/Services/Messaging/MessagingBase.php +++ b/tests/e2e/Services/Messaging/MessagingBase.php @@ -193,49 +193,49 @@ trait MessagingBase public function testCreateTopic(): string { - $provider = $this->client->call(Client::METHOD_POST, '/messaging/providers/sendgrid', \array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ]), [ - 'id' => 'unique()', - 'name' => 'Sengrid1', - 'apiKey' => 'my-apikey', - ]); - $this->assertEquals(201, $provider['headers']['status-code']); + $provider = $this->client->call(Client::METHOD_POST, '/messaging/providers/sendgrid', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), [ + 'id' => 'unique()', + 'name' => 'Sengrid1', + 'apiKey' => 'my-apikey', + ]); + $this->assertEquals(201, $provider['headers']['status-code']); $response = $this->client->call(Client::METHOD_POST, '/messaging/topics', [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], + 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ 'providerId' => $provider['body']['$id'], - 'topicId' => 'unique()', - 'name' => 'my-app', - 'description' => 'web app' + 'topicId' => 'unique()', + 'name' => 'my-app', + 'description' => 'web app' ]); $this->assertEquals(201, $response['headers']['status-code']); - $this->assertEquals('my-app', $response['body']['name']); + $this->assertEquals('my-app', $response['body']['name']); return $response['body']['$id']; } - /** + /** * @depends testCreateTopic */ public function testUpdateTopic(string $topicId): string { $response = $this->client->call(Client::METHOD_PATCH, '/messaging/topics/' . $topicId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ], [ - 'name' => 'android-app', - 'description' => 'updated-description' - ]); - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('android-app', $response['body']['name']); - $this->assertEquals('updated-description', $response['body']['description']); - return $topicId; + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], [ + 'name' => 'android-app', + 'description' => 'updated-description' + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('android-app', $response['body']['name']); + $this->assertEquals('updated-description', $response['body']['description']); + return $topicId; } public function testListTopic() @@ -249,27 +249,27 @@ trait MessagingBase $this->assertEquals(1, \count($response['body']['topics'])); } - /** + /** * @depends testUpdateTopic */ public function testGetTopic(string $topicId) { - $response = $this->client->call(Client::METHOD_GET, '/messaging/topics/' .$topicId, [ + $response = $this->client->call(Client::METHOD_GET, '/messaging/topics/' . $topicId, [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('android-app', $response['body']['name']); - $this->assertEquals('updated-description', $response['body']['description']); + $this->assertEquals('android-app', $response['body']['name']); + $this->assertEquals('updated-description', $response['body']['description']); } - /** + /** * @depends testUpdateTopic */ public function testDeleteTopic(string $topicId) { - $response = $this->client->call(Client::METHOD_DELETE, '/messaging/topics/' .$topicId, [ + $response = $this->client->call(Client::METHOD_DELETE, '/messaging/topics/' . $topicId, [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], diff --git a/tests/e2e/Services/Messaging/MessagingConsoleClientTest.php b/tests/e2e/Services/Messaging/MessagingConsoleClientTest.php index 8250c0229a..0d533c139b 100644 --- a/tests/e2e/Services/Messaging/MessagingConsoleClientTest.php +++ b/tests/e2e/Services/Messaging/MessagingConsoleClientTest.php @@ -11,5 +11,4 @@ class MessagingConsoleClientTest extends Scope use MessagingBase; use ProjectCustom; use SideConsole; - } diff --git a/tests/e2e/Services/Messaging/MessagingCustomClientTest.php b/tests/e2e/Services/Messaging/MessagingCustomClientTest.php index fd520a38ef..ee7d0c2ad9 100644 --- a/tests/e2e/Services/Messaging/MessagingCustomClientTest.php +++ b/tests/e2e/Services/Messaging/MessagingCustomClientTest.php @@ -11,5 +11,4 @@ class MessagingCustomClientTest extends Scope use MessagingBase; use ProjectCustom; use SideClient; - } diff --git a/tests/e2e/Services/Messaging/MessagingCustomServerTest.php b/tests/e2e/Services/Messaging/MessagingCustomServerTest.php index c126df3261..19e0113364 100644 --- a/tests/e2e/Services/Messaging/MessagingCustomServerTest.php +++ b/tests/e2e/Services/Messaging/MessagingCustomServerTest.php @@ -11,5 +11,4 @@ class MessagingCustomServerTest extends Scope use MessagingBase; use ProjectCustom; use SideServer; - }