1
0
Fork 0
mirror of synced 2024-07-02 05:00:33 +12:00

fix tests and code changes

This commit is contained in:
Prateek Banga 2023-09-20 15:55:22 +05:30
parent bd36a09473
commit 67397cd763
3 changed files with 57 additions and 42 deletions

View file

@ -166,13 +166,13 @@ App::patch('/v1/messaging/providers/:id/mailgun')
->label('sdk.response.model', Response::MODEL_PROVIDER)
->param('id', '', new UID(), 'Provider ID.')
->param('name', '', new Text(128), 'Provider name.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', true)
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
->param('isEuRegion', false, new Boolean(), 'Set as eu region.', true)
->param('apiKey', '', new Text(0), 'Mailgun API Key.', true)
->param('domain', '', new Text(0), 'Mailgun Domain.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $id, string $name, bool $enabled, bool $isEuRegion, string $apiKey, string $domain, Database $dbForProject, Response $response) {
->action(function (string $id, string $name, ?bool $enabled, bool $isEuRegion, string $apiKey, string $domain, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $id);
if ($provider->isEmpty()) {
@ -184,7 +184,7 @@ App::patch('/v1/messaging/providers/:id/mailgun')
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
}
if ($name) {
if (!empty($name)) {
$provider->setAttribute('name', $name);
$provider->setAttribute('search', $provider->getId() . ' ' . $name . ' ' . 'mailgun' . ' ' . 'email');
}
@ -292,11 +292,11 @@ App::patch('/v1/messaging/providers/:id/sendgrid')
->label('sdk.response.model', Response::MODEL_PROVIDER)
->param('id', '', new UID(), 'Provider ID.')
->param('name', '', new Text(128), 'Provider name.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', true)
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
->param('apiKey', '', new Text(0), 'Sendgrid API key.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $id, string $name, bool $enabled, string $apiKey, Database $dbForProject, Response $response) {
->action(function (string $id, string $name, ?bool $enabled, string $apiKey, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $id);
if ($provider->isEmpty()) {
@ -308,7 +308,7 @@ App::patch('/v1/messaging/providers/:id/sendgrid')
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
}
if ($name) {
if (!empty($name)) {
$provider->setAttribute('name', $name);
$provider->setAttribute('search', $provider->getId() . ' ' . $name . ' ' . 'sendgrid' . ' ' . 'email');
}
@ -405,12 +405,12 @@ App::patch('/v1/messaging/providers/:id/msg91')
->label('sdk.response.model', Response::MODEL_PROVIDER)
->param('id', '', new UID(), 'Provider ID.')
->param('name', '', new Text(128), 'Provider name.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', true)
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
->param('senderId', '', new Text(0), 'Msg91 Sender ID.', true)
->param('authKey', '', new Text(0), 'Msg91 Auth Key.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $id, string $name, bool $enabled, string $senderId, string $authKey, Database $dbForProject, Response $response) {
->action(function (string $id, string $name, ?bool $enabled, string $senderId, string $authKey, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $id);
if ($provider->isEmpty()) {
@ -422,7 +422,7 @@ App::patch('/v1/messaging/providers/:id/msg91')
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
}
if ($name) {
if (!empty($name)) {
$provider->setAttribute('name', $name);
$provider->setAttribute('search', $provider->getId() . ' ' . $name . ' ' . 'msg91' . ' ' . 'sms');
}
@ -523,12 +523,12 @@ App::patch('/v1/messaging/providers/:id/telesign')
->label('sdk.response.model', Response::MODEL_PROVIDER)
->param('id', '', new UID(), 'Provider ID.')
->param('name', '', new Text(128), 'Provider name.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', true)
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
->param('username', '', new Text(0), 'Telesign username.', true)
->param('password', '', new Text(0), 'Telesign password.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $id, string $name, bool $enabled, string $username, string $password, Database $dbForProject, Response $response) {
->action(function (string $id, string $name, ?bool $enabled, string $username, string $password, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $id);
if ($provider->isEmpty()) {
@ -540,7 +540,7 @@ App::patch('/v1/messaging/providers/:id/telesign')
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
}
if ($name) {
if (!empty($name)) {
$provider->setAttribute('name', $name);
$provider->setAttribute('search', $provider->getId() . ' ' . $name . ' ' . 'telesign' . ' ' . 'sms');
}
@ -641,12 +641,12 @@ App::patch('/v1/messaging/providers/:id/textmagic')
->label('sdk.response.model', Response::MODEL_PROVIDER)
->param('id', '', new UID(), 'Provider ID.')
->param('name', '', new Text(128), 'Provider name.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', true)
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
->param('username', '', new Text(0), 'Textmagic username.', true)
->param('apiKey', '', new Text(0), 'Textmagic apiKey.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $id, string $name, bool $enabled, string $username, string $apiKey, Database $dbForProject, Response $response) {
->action(function (string $id, string $name, ?bool $enabled, string $username, string $apiKey, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $id);
if ($provider->isEmpty()) {
@ -658,7 +658,7 @@ App::patch('/v1/messaging/providers/:id/textmagic')
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
}
if ($name) {
if (!empty($name)) {
$provider->setAttribute('name', $name);
$provider->setAttribute('search', $provider->getId() . ' ' . $name . ' ' . 'textmagic' . ' ' . 'sms');
}
@ -759,12 +759,12 @@ App::patch('/v1/messaging/providers/:id/twilio')
->label('sdk.response.model', Response::MODEL_PROVIDER)
->param('id', '', new UID(), 'Provider ID.')
->param('name', '', new Text(128), 'Provider name.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', true)
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
->param('accountSid', null, new Text(0), 'Twilio account secret ID.', true)
->param('authToken', null, new Text(0), 'Twilio authentication token.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $id, string $name, bool $enabled, string $accountSid, string $authToken, Database $dbForProject, Response $response) {
->action(function (string $id, string $name, ?bool $enabled, string $accountSid, string $authToken, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $id);
if ($provider->isEmpty()) {
@ -776,7 +776,7 @@ App::patch('/v1/messaging/providers/:id/twilio')
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
}
if ($name) {
if (!empty($name)) {
$provider->setAttribute('name', $name);
$provider->setAttribute('search', $provider->getId() . ' ' . $name . ' ' . 'twilio' . ' ' . 'sms');
}
@ -877,12 +877,12 @@ App::patch('/v1/messaging/providers/:id/vonage')
->label('sdk.response.model', Response::MODEL_PROVIDER)
->param('id', '', new UID(), 'Provider ID.')
->param('name', '', new Text(128), 'Provider name.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', true)
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
->param('apiKey', '', new Text(0), 'Vonage API key.', true)
->param('apiSecret', '', new Text(0), 'Vonage API secret.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $id, string $name, bool $enabled, string $apiKey, string $apiSecret, Database $dbForProject, Response $response) {
->action(function (string $id, string $name, ?bool $enabled, string $apiKey, string $apiSecret, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $id);
if ($provider->isEmpty()) {
@ -894,7 +894,7 @@ App::patch('/v1/messaging/providers/:id/vonage')
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
}
if ($name) {
if (!empty($name)) {
$provider->setAttribute('name', $name);
$provider->setAttribute('search', $provider->getId() . ' ' . $name . ' ' . 'vonage' . ' ' . 'sms');
}
@ -996,11 +996,11 @@ App::patch('/v1/messaging/providers/:id/fcm')
->label('sdk.response.model', Response::MODEL_PROVIDER)
->param('id', '', new UID(), 'Provider ID.')
->param('name', '', new Text(128), 'Provider name.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', true)
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
->param('serverKey', '', new Text(0), 'FCM Server Key.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $id, string $name, bool $enabled, string $serverKey, Database $dbForProject, Response $response) {
->action(function (string $id, string $name, ?bool $enabled, string $serverKey, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $id);
if ($provider->isEmpty()) {
@ -1012,7 +1012,7 @@ App::patch('/v1/messaging/providers/:id/fcm')
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
}
if ($name) {
if (!empty($name)) {
$provider->setAttribute('name', $name);
$provider->setAttribute('search', $provider->getId() . ' ' . $name . ' ' . 'fcm' . ' ' . 'push');
}
@ -1110,7 +1110,7 @@ App::patch('/v1/messaging/providers/:id/apns')
->label('sdk.response.model', Response::MODEL_PROVIDER)
->param('id', '', new UID(), 'Provider ID.')
->param('name', '', new Text(128), 'Provider name.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', true)
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
->param('authKey', '', new Text(0), 'APNS authentication key.', true)
->param('authKeyId', '', new Text(0), 'APNS authentication key ID.', true)
->param('teamId', '', new Text(0), 'APNS team ID.', true)
@ -1118,7 +1118,7 @@ App::patch('/v1/messaging/providers/:id/apns')
->param('endpoint', '', new Text(0), 'APNS endpoint.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $id, string $name, bool $enabled, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Database $dbForProject, Response $response) {
->action(function (string $id, string $name, ?bool $enabled, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $id);
if ($provider->isEmpty()) {
@ -1130,7 +1130,7 @@ App::patch('/v1/messaging/providers/:id/apns')
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
}
if ($name) {
if (!empty($name)) {
$provider->setAttribute('name', $name);
$provider->setAttribute('search', $provider->getId() . ' ' . $name . ' ' . 'apns' . ' ' . 'push');
}
@ -1234,18 +1234,18 @@ App::patch('/v1/messaging/providers/:id/general')
->label('sdk.response.model', Response::MODEL_PROVIDER)
->param('id', '', new UID(), 'Provider ID.')
->param('name', '', new Text(128), 'Provider name.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', true)
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
->param('credentials', '', new JSON(), 'Provider credentials.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $id, string $name, bool $enabled, array $credentials, Database $dbForProject, Response $response) {
->action(function (string $id, string $name, ?bool $enabled, array $credentials, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $id);
if ($provider->isEmpty()) {
throw new Exception(Exception::PROVIDER_NOT_FOUND);
}
if ($name) {
if (!empty($name)) {
$provider->setAttribute('name', $name);
}

24
composer.lock generated
View file

@ -4145,16 +4145,16 @@
},
{
"name": "phpstan/phpdoc-parser",
"version": "1.24.0",
"version": "1.24.1",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpdoc-parser.git",
"reference": "3510b0a6274cc42f7219367cb3abfc123ffa09d6"
"reference": "9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/3510b0a6274cc42f7219367cb3abfc123ffa09d6",
"reference": "3510b0a6274cc42f7219367cb3abfc123ffa09d6",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01",
"reference": "9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01",
"shasum": ""
},
"require": {
@ -4186,22 +4186,22 @@
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": {
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.0"
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.1"
},
"time": "2023-09-07T20:46:32+00:00"
"time": "2023-09-18T12:18:02+00:00"
},
{
"name": "phpunit/php-code-coverage",
"version": "9.2.28",
"version": "9.2.29",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "7134a5ccaaf0f1c92a4f5501a6c9f98ac4dcc0ef"
"reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7134a5ccaaf0f1c92a4f5501a6c9f98ac4dcc0ef",
"reference": "7134a5ccaaf0f1c92a4f5501a6c9f98ac4dcc0ef",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6a3a87ac2bbe33b25042753df8195ba4aa534c76",
"reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76",
"shasum": ""
},
"require": {
@ -4258,7 +4258,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy",
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.28"
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.29"
},
"funding": [
{
@ -4266,7 +4266,7 @@
"type": "github"
}
],
"time": "2023-09-12T14:36:20+00:00"
"time": "2023-09-19T04:57:46+00:00"
},
{
"name": "phpunit/php-file-iterator",

View file

@ -145,6 +145,21 @@ trait MessagingBase
$this->assertEquals($providersParams[$key]['name'], $response['body']['name']);
}
$response = $this->client->call(Client::METHOD_PATCH, '/messaging/providers/' . $providers[1]['$id'] . '/mailgun', [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
], [
'name' => 'Mailgun2',
'apiKey' => 'my-apikey',
'domain' => 'my-domain',
'isEuRegion' => true,
'enabled' => false,
]);
$providers[1] = $response['body'];
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('Mailgun2', $response['body']['name']);
$this->assertEquals(false, $response['body']['enabled']);
return $providers;
}