1
0
Fork 0
mirror of synced 2024-10-01 09:47:43 +13:00

Fix tests

This commit is contained in:
Jake Barnby 2024-01-24 17:34:59 +13:00 committed by Torsten Dittmann
parent 874e3dd8d8
commit 7a5c226110
2 changed files with 17 additions and 7 deletions

View file

@ -616,9 +616,13 @@ App::post('/v1/messaging/providers/fcm')
->inject('queueForEvents')
->inject('dbForProject')
->inject('response')
->action(function (string $providerId, string $name, ?array $serviceAccountJSON, ?bool $enabled, Event $queueForEvents, Database $dbForProject, Response $response) {
->action(function (string $providerId, string $name, array|string|null $serviceAccountJSON, ?bool $enabled, Event $queueForEvents, Database $dbForProject, Response $response) {
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
$serviceAccountJSON = \is_string($serviceAccountJSON)
? \json_decode($serviceAccountJSON, true)
: $serviceAccountJSON;
$credentials = [];
if (!\is_null($serviceAccountJSON)) {
@ -1512,7 +1516,7 @@ App::patch('/v1/messaging/providers/fcm/:providerId')
->inject('queueForEvents')
->inject('dbForProject')
->inject('response')
->action(function (string $providerId, string $name, ?bool $enabled, ?array $serviceAccountJSON, Event $queueForEvents, Database $dbForProject, Response $response) {
->action(function (string $providerId, string $name, ?bool $enabled, array|string|null $serviceAccountJSON, Event $queueForEvents, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $providerId);
if ($provider->isEmpty()) {
@ -1529,6 +1533,10 @@ App::patch('/v1/messaging/providers/fcm/:providerId')
}
if (!\is_null($serviceAccountJSON)) {
$serviceAccountJSON = \is_string($serviceAccountJSON)
? \json_decode($serviceAccountJSON, true)
: $serviceAccountJSON;
$provider->setAttribute('credentials', [
'serviceAccountJSON' => $serviceAccountJSON
]);

View file

@ -188,10 +188,11 @@ trait MessagingBase
public function testUpdateProviderMissingCredentialsThrows(): void
{
// Create new FCM provider with no serviceAccountJSON
$response = $this->client->call(Client::METHOD_POST, '/messaging/providers/fcm', \array_merge([
$response = $this->client->call(Client::METHOD_POST, '/messaging/providers/fcm', [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'x-appwrite-key' => $this->getProject()['apiKey'],
], [
'providerId' => ID::unique(),
'name' => 'FCM3',
]);
@ -199,10 +200,11 @@ trait MessagingBase
$this->assertEquals(201, $response['headers']['status-code']);
// Enable provider with no serviceAccountJSON
$response = $this->client->call(Client::METHOD_PATCH, '/messaging/providers/fcm/' . $response['body']['$id'], \array_merge([
$response = $this->client->call(Client::METHOD_PATCH, '/messaging/providers/fcm/' . $response['body']['$id'], [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'x-appwrite-key' => $this->getProject()['apiKey'],
], [
'enabled' => true,
]);
@ -221,7 +223,7 @@ trait MessagingBase
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals(\count($providers), \count($response['body']['providers']));
$this->assertEquals(10, \count($response['body']['providers']));
return $providers;
}