From 4ccffb6649ece498d95a91f68127980aa1985187 Mon Sep 17 00:00:00 2001 From: Prateek Banga Date: Tue, 17 Oct 2023 03:41:42 +0530 Subject: [PATCH] adds graphql tests for topics, subcribers, email --- .env | 10 +- app/controllers/api/messaging.php | 9 +- composer.lock | 6 +- docker-compose.yml | 10 +- tests/e2e/Services/GraphQL/Base.php | 191 +++++++++ tests/e2e/Services/GraphQL/MessagingTest.php | 402 ++++++++++++++++++ .../e2e/Services/Messaging/MessagingBase.php | 20 +- 7 files changed, 624 insertions(+), 24 deletions(-) diff --git a/.env b/.env index cb0ae9a424..aa90470729 100644 --- a/.env +++ b/.env @@ -103,8 +103,8 @@ _APP_MESSAGE_SMS_PROVIDER_MSG91_SENDER_ID= _APP_MESSAGE_SMS_PROVIDER_MSG91_AUTH_KEY= _APP_MESSAGE_SMS_PROVIDER_MSG91_FROM= _APP_MESSAGE_SMS_PROVIDER_MSG91_TO= -_APP_MESSAGE_SMS_PROVIDER_MAILGUN_API_KEY= -_APP_MESSAGE_SMS_PROVIDER_MAILGUN_DOMAIN= -_APP_MESSAGE_SMS_PROVIDER_MAILGUN_FROM= -_APP_MESSAGE_SMS_PROVIDER_MAILGUN_RECEIVER_EMAIL= -_APP_MESSAGE_SMS_PROVIDER_MAILGUN_IS_EU_REGION= +_APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_API_KEY= +_APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_DOMAIN= +_APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_FROM= +_APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_RECEIVER_EMAIL= +_APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_IS_EU_REGION= diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index e83fc1114d..b3deaa409f 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -1192,7 +1192,9 @@ App::delete('/v1/messaging/providers/:providerId') $dbForProject->deleteDocument('providers', $provider->getId()); - $response->noContent(); + $response + ->setStatusCode(Response::STATUS_CODE_NOCONTENT) + ->noContent(); }); App::post('/v1/messaging/topics') @@ -1376,7 +1378,10 @@ App::delete('/v1/messaging/topics/:topicId') } $topic = $dbForProject->deleteDocument('topics', $topicId); - $response->noContent(); + + $response + ->setStatusCode(Response::STATUS_CODE_NOCONTENT) + ->noContent(); }); App::post('/v1/messaging/topics/:topicId/subscribers') diff --git a/composer.lock b/composer.lock index 8abede5fa4..f80104986c 100644 --- a/composer.lock +++ b/composer.lock @@ -156,11 +156,11 @@ }, { "name": "appwrite/php-runtimes", - "version": "0.13.0", + "version": "0.13.1", "source": { "type": "git", "url": "https://github.com/appwrite/runtimes.git", - "reference": "5ab496b3908992b39275994a23783701c4b3de84" + "reference": "b584d19cdcd82737d0ee5c34d23de791f5ed3610" }, "require": { "php": ">=8.0", @@ -195,7 +195,7 @@ "php", "runtimes" ], - "time": "2023-09-12T19:38:43+00:00" + "time": "2023-10-16T15:39:53+00:00" }, { "name": "chillerlan/php-qrcode", diff --git a/docker-compose.yml b/docker-compose.yml index f0ddbfe41b..a365ce17ba 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -192,11 +192,11 @@ services: - _APP_MESSAGE_SMS_PROVIDER_MSG91_AUTH_KEY - _APP_MESSAGE_SMS_PROVIDER_MSG91_FROM - _APP_MESSAGE_SMS_PROVIDER_MSG91_TO - - _APP_MESSAGE_SMS_PROVIDER_MAILGUN_API_KEY - - _APP_MESSAGE_SMS_PROVIDER_MAILGUN_DOMAIN - - _APP_MESSAGE_SMS_PROVIDER_MAILGUN_FROM - - _APP_MESSAGE_SMS_PROVIDER_MAILGUN_RECEIVER_EMAIL - - _APP_MESSAGE_SMS_PROVIDER_MAILGUN_IS_EU_REGION + - _APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_API_KEY + - _APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_DOMAIN + - _APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_FROM + - _APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_RECEIVER_EMAIL + - _APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_IS_EU_REGION appwrite-realtime: entrypoint: realtime diff --git a/tests/e2e/Services/GraphQL/Base.php b/tests/e2e/Services/GraphQL/Base.php index 0a93ac34c4..f3947c53b4 100644 --- a/tests/e2e/Services/GraphQL/Base.php +++ b/tests/e2e/Services/GraphQL/Base.php @@ -107,6 +107,11 @@ trait Base public static string $DELETE_USER_SESSIONS = 'delete_user_sessions'; public static string $DELETE_USER_SESSION = 'delete_user_session'; public static string $DELETE_USER = 'delete_user'; + public static string $CREATE_USER_TARGET = 'create_user_target'; + public static string $LIST_USER_TARGETS = 'list_user_targets'; + public static string $GET_USER_TARGET = 'get_user_target'; + public static string $UPDATE_USER_TARGET = 'update_user_target'; + public static string $DELETE_USER_TARGET = 'delete_user_target'; // Teams public static string $GET_TEAM = 'get_team'; @@ -220,6 +225,24 @@ trait Base public static string $UPDATE_APNS_PROVIDER = 'update_apns_provider'; public static string $DELETE_PROVIDER = 'delete_provider'; + // Topics + public static string $CREATE_TOPIC = 'create_topic'; + public static string $LIST_TOPICS = 'list_topics'; + public static string $GET_TOPIC = 'get_topic'; + public static string $UPDATE_TOPIC = 'update_topic'; + public static string $DELETE_TOPIC = 'delete_topic'; + + // Subscriptions + public static string $CREATE_SUBSCRIBER = 'create_subscriber'; + public static string $LIST_SUBSCRIBERS = 'list_subscribers'; + public static string $GET_SUBSCRIBER = 'get_subscriber'; + public static string $DELETE_SUBSCRIBER = 'delete_subscriber'; + + // Messages + public static string $CREATE_EMAIL = 'create_email'; + public static string $LIST_MESSAGES = 'list_messages'; + public static string $GET_MESSAGE = 'get_message'; + // Complex queries public static string $COMPLEX_QUERY = 'complex_query'; @@ -902,6 +925,51 @@ trait Base status } }'; + case self::$CREATE_USER_TARGET: + return 'mutation createUserTarget($userId: String!, $targetId: String!, $providerId: String!, $identifier: String!){ + usersCreateTarget(userId: $userId, targetId: $targetId, providerId: $providerId, identifier: $identifier) { + _id + userId + providerId + identifier + } + }'; + case self::$LIST_USER_TARGETS: + return 'query listUserTargets($userId: String!) { + usersListTargets(userId: $userId) { + total + targets { + _id + userId + providerId + identifier + } + } + }'; + case self::$GET_USER_TARGET: + return 'query getUserTarget($userId: String!, $targetId: String!) { + usersGetTarget(userId: $userId, targetId: $targetId) { + _id + userId + providerId + identifier + } + }'; + case self::$UPDATE_USER_TARGET: + return 'mutation updateUserTarget($userId: String!, $targetId: String!, $identifier: String!){ + usersUpdateTargetIdentifier(userId: $userId, targetId: $targetId, identifier: $identifier) { + _id + userId + providerId + identifier + } + }'; + case self::$DELETE_USER_TARGET: + return 'mutation deleteUserTarget($userId: String!, $targetId: String!){ + usersDeleteTarget(userId: $userId, targetId: $targetId) { + status + } + }'; case self::$GET_LOCALE: return 'query getLocale { localeGet { @@ -1938,6 +2006,129 @@ trait Base status } }'; + case self::$CREATE_TOPIC: + return 'mutation createTopic($providerId: String!, $topicId: String!, $name: String!, $description: String!) { + messagingCreateTopic(providerId: $providerId, topicId: $topicId, name: $name, description: $description) { + _id + name + providerId + description + } + }'; + case self::$LIST_TOPICS: + return 'query listTopics { + messagingListTopics { + total + topics { + _id + name + providerId + description + } + } + }'; + case self::$GET_TOPIC: + return 'query getTopic($topicId: String!) { + messagingGetTopic(topicId: $topicId) { + _id + name + providerId + description + } + }'; + case self::$UPDATE_TOPIC: + return 'mutation updateTopic($topicId: String!, $name: String!, $description: String!) { + messagingUpdateTopic(topicId: $topicId, name: $name, description: $description) { + _id + name + providerId + description + } + }'; + case self::$DELETE_TOPIC: + return 'mutation deleteTopic($topicId: String!) { + messagingDeleteTopic(topicId: $topicId) { + status + } + }'; + case self::$CREATE_SUBSCRIBER: + return 'mutation createSubscriber($subscriberId: String!, $targetId: String!, $topicId: String!) { + messagingCreateSubscriber(subscriberId: $subscriberId, targetId: $targetId, topicId: $topicId) { + _id + targetId + topicId + } + }'; + case self::$LIST_SUBSCRIBERS: + return 'query listSubscribers($topicId: String!) { + messagingListSubscribers(topicId: $topicId) { + total + subscribers { + _id + targetId + topicId + } + } + }'; + case self::$GET_SUBSCRIBER: + return 'query getSubscriber($topicId: String!, $subscriberId: String!) { + messagingGetSubscriber(topicId: $topicId, subscriberId: $subscriberId) { + _id + targetId + topicId + } + }'; + case self::$DELETE_SUBSCRIBER: + return 'mutation deleteSubscriber($topicId: String!, $subscriberId: String!) { + messagingDeleteSubscriber(topicId: $topicId, subscriberId: $subscriberId) { + status + } + }'; + case self::$CREATE_EMAIL: + return 'mutation createEmail($messageId: String!, $providerId: String!, $to: [String!]!, $subject: String!, $content: String!, $status: String, $description: String, $html: Boolean, $deliveryTime: String) { + messagingCreateEmail(messageId: $messageId, providerId: $providerId, to: $to, subject: $subject, content: $content, status: $status, description: $description, html: $html, deliveryTime: $deliveryTime) { + _id + providerId + to + deliveryTime + deliveredAt + deliveryErrors + deliveredTo + status + description + } + }'; + case self::$LIST_MESSAGES: + return 'query listMessages { + messagingListMessages { + total + messages { + _id + providerId + to + deliveryTime + deliveredAt + deliveryErrors + deliveredTo + status + description + } + } + }'; + case self::$GET_MESSAGE: + return 'query getMessage($messageId: String!) { + messagingGetMessage(messageId: $messageId) { + _id + providerId + to + deliveryTime + deliveredAt + deliveryErrors + deliveredTo + status + description + } + }'; case self::$COMPLEX_QUERY: return 'mutation complex($databaseId: String!, $databaseName: String!, $collectionId: String!, $collectionName: String!, $documentSecurity: Boolean!, $collectionPermissions: [String!]!) { databasesCreate(databaseId: $databaseId, name: $databaseName) { diff --git a/tests/e2e/Services/GraphQL/MessagingTest.php b/tests/e2e/Services/GraphQL/MessagingTest.php index 99bad52887..178b9a6a6c 100644 --- a/tests/e2e/Services/GraphQL/MessagingTest.php +++ b/tests/e2e/Services/GraphQL/MessagingTest.php @@ -6,6 +6,7 @@ use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; +use Utopia\App; use Utopia\Database\Helpers\ID; class MessagingTest extends Scope @@ -257,4 +258,405 @@ class MessagingTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); } } + + public function testCreateTopic() + { + $providerParam = [ + 'sendgrid' => [ + 'providerId' => ID::unique(), + 'name' => 'Sengrid1', + 'apiKey' => 'my-apikey', + ] + ]; + $query = $this->getQuery(self::$CREATE_SENDGRID_PROVIDER); + $graphQLPayload = [ + 'query' => $query, + 'variables' => $providerParam['sendgrid'], + ]; + $response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), $graphQLPayload); + + $providerId = $response['body']['data']['messagingCreateSendgridProvider']['_id']; + + $query = $this->getQuery(self::$CREATE_TOPIC); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'providerId' => $providerId, + 'topicId' => ID::unique(), + 'name' => 'topic1', + 'description' => 'Active users', + ], + ]; + $response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), $graphQLPayload); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('topic1', $response['body']['data']['messagingCreateTopic']['name']); + $this->assertEquals('Active users', $response['body']['data']['messagingCreateTopic']['description']); + + return $response['body']['data']['messagingCreateTopic']; + } + + /** + * @depends testCreateTopic + */ + public function testUpdateTopic(array $topic) + { + $topicId = $topic['_id']; + $query = $this->getQuery(self::$UPDATE_TOPIC); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'topicId' => $topicId, + 'name' => 'topic2', + 'description' => 'Inactive users', + ], + ]; + $response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), $graphQLPayload); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('topic2', $response['body']['data']['messagingUpdateTopic']['name']); + $this->assertEquals('Inactive users', $response['body']['data']['messagingUpdateTopic']['description']); + + return $topicId; + } + + /** + * @depends testCreateTopic + */ + public function testListTopics() + { + $query = $this->getQuery(self::$LIST_TOPICS); + $graphQLPayload = [ + 'query' => $query, + ]; + $response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), $graphQLPayload); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, \count($response['body']['data']['messagingListTopics']['topics'])); + } + + /** + * @depends testUpdateTopic + */ + public function testGetTopic(string $topicId) + { + $query = $this->getQuery(self::$GET_TOPIC); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'topicId' => $topicId, + ], + ]; + $response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), $graphQLPayload); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('topic2', $response['body']['data']['messagingGetTopic']['name']); + $this->assertEquals('Inactive users', $response['body']['data']['messagingGetTopic']['description']); + } + + /** + * @depends testCreateTopic + */ + public function testCreateSubscriber(array $topic) + { + $topicId = $topic['_id']; + + $userId = $this->getUser()['$id']; + + $query = $this->getQuery(self::$CREATE_USER_TARGET); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'targetId' => ID::unique(), + 'userId' => $userId, + 'providerId' => $topic['providerId'], + 'identifier' => 'token', + ], + ]; + $response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), $graphQLPayload); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals($userId, $response['body']['data']['usersCreateTarget']['userId']); + $this->assertEquals('token', $response['body']['data']['usersCreateTarget']['identifier']); + + $targetId = $response['body']['data']['usersCreateTarget']['_id']; + + $query = $this->getQuery(self::$CREATE_SUBSCRIBER); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'subscriberId' => ID::unique(), + 'topicId' => $topicId, + 'targetId' => $targetId, + ], + ]; + $response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), $graphQLPayload); + + $this->assertEquals(200, $response['headers']['status-code']); + + return $response['body']['data']['messagingCreateSubscriber']; + } + + /** + * @depends testUpdateTopic + */ + public function testListSubscribers(string $topicId) + { + $query = $this->getQuery(self::$LIST_SUBSCRIBERS); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'topicId' => $topicId, + ], + ]; + $response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), $graphQLPayload); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, \count($response['body']['data']['messagingListSubscribers']['subscribers'])); + } + + /** + * @depends testCreateSubscriber + */ + public function testGetSubscriber(array $subscriber) + { + $topicId = $subscriber['topicId']; + $subscriberId = $subscriber['_id']; + + $query = $this->getQuery(self::$GET_SUBSCRIBER); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'topicId' => $topicId, + 'subscriberId' => $subscriberId, + ], + ]; + + $response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), $graphQLPayload); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals($subscriberId, $response['body']['data']['messagingGetSubscriber']['_id']); + } + + /** + * @depends testCreateSubscriber + */ + public function testDeleteSubscriber(array $subscriber) + { + $topicId = $subscriber['topicId']; + $subscriberId = $subscriber['_id']; + + $query = $this->getQuery(self::$DELETE_SUBSCRIBER); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'topicId' => $topicId, + 'subscriberId' => $subscriberId, + ], + ]; + + $response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + ], $this->getHeaders()), $graphQLPayload); + + $this->assertEquals(200, $response['headers']['status-code']); + } + + /** + * @depends testUpdateTopic + */ + public function testDeleteTopic(string $topicId) + { + $query = $this->getQuery(self::$DELETE_TOPIC); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'topicId' => $topicId, + ], + ]; + $response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), $graphQLPayload); + + $this->assertEquals(204, $response['headers']['status-code']); + } + + public function testSendEmail() + { + $to = App::getEnv('_APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_RECEIVER_EMAIL'); + $from = App::getEnv('_APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_FROM'); + $apiKey = App::getEnv('_APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_API_KEY'); + $domain = App::getEnv('_APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_DOMAIN'); + $isEuRegion = App::getEnv('_APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_IS_EU_REGION'); + if (empty($to) || empty($from) || empty($apiKey) || empty($domain) || empty($isEuRegion)) { + $this->markTestSkipped('Email provider not configured'); + } + + $query = $this->getQuery(self::$CREATE_MAILGUN_PROVIDER); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'providerId' => ID::unique(), + 'name' => 'Mailgun1', + 'apiKey' => $apiKey, + 'domain' => $domain, + 'from' => $from, + 'isEuRegion' => $isEuRegion, + ], + ]; + $provider = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), $graphQLPayload); + + $this->assertEquals(200, $provider['headers']['status-code']); + + $providerId = $provider['body']['data']['messagingCreateMailgunProvider']['_id']; + + $query = $this->getQuery(self::$CREATE_TOPIC); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'providerId' => $providerId, + 'topicId' => ID::unique(), + 'name' => 'topic1', + 'description' => 'Active users', + ], + ]; + $topic = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), $graphQLPayload); + + $this->assertEquals(200, $topic['headers']['status-code']); + + $query = $this->getQuery(self::$CREATE_USER); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'userId' => ID::custom('test-user'), + 'email' => $to, + 'password' => 'password', + 'name' => 'Messaging User', + ] + ]; + $user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), $graphQLPayload); + + $this->assertEquals(200, $user['headers']['status-code']); + + $query = $this->getQuery(self::$CREATE_USER_TARGET); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'targetId' => ID::unique(), + 'userId' => $user['body']['data']['usersCreate']['_id'], + 'providerId' => $providerId, + 'identifier' => $to, + ], + ]; + $target = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), $graphQLPayload); + + $this->assertEquals(200, $target['headers']['status-code']); + + $query = $this->getQuery(self::$CREATE_SUBSCRIBER); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'subscriberId' => ID::unique(), + 'topicId' => $topic['body']['data']['messagingCreateTopic']['_id'], + 'targetId' => $target['body']['data']['usersCreateTarget']['_id'], + ], + ]; + $subscriber = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), $graphQLPayload); + + $this->assertEquals(200, $subscriber['headers']['status-code']); + + $query = $this->getQuery(self::$CREATE_EMAIL); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'messageId' => ID::unique(), + 'providerId' => $providerId, + 'to' => [$topic['body']['data']['messagingCreateTopic']['_id']], + 'subject' => 'Khali beats Undertaker', + 'content' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', + ], + ]; + $email = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), $graphQLPayload); + + $this->assertEquals(200, $email['headers']['status-code']); + + \sleep(5); + + $query = $this->getQuery(self::$GET_MESSAGE); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'messageId' => $email['body']['data']['messagingCreateEmail']['_id'], + ], + ]; + $message = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), $graphQLPayload); + + $this->assertEquals(200, $message['headers']['status-code']); + $this->assertEquals(1, $message['body']['data']['messagingGetMessage']['deliveredTo']); + $this->assertEquals(0, \count($message['body']['data']['messagingGetMessage']['deliveryErrors'])); + } } diff --git a/tests/e2e/Services/Messaging/MessagingBase.php b/tests/e2e/Services/Messaging/MessagingBase.php index 3f8039fae6..1c349a2dbe 100644 --- a/tests/e2e/Services/Messaging/MessagingBase.php +++ b/tests/e2e/Services/Messaging/MessagingBase.php @@ -323,7 +323,8 @@ trait MessagingBase $response = $this->client->call(Client::METHOD_GET, '/messaging/topics/' . $data['topicId'] . '/subscriber/' . $data['subscriberId'], \array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); + 'x-appwrite-key' => $this->getProject()['apiKey'], + ])); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals($data['topicId'], $response['body']['topicId']); $this->assertEquals($data['targetId'], $response['body']['targetId']); @@ -337,7 +338,8 @@ trait MessagingBase $response = $this->client->call(Client::METHOD_GET, '/messaging/topics/' . $data['topicId'] . '/subscribers', \array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); + 'x-appwrite-key' => $this->getProject()['apiKey'], + ])); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(1, $response['body']['total']); $this->assertEquals(\count($response['body']['subscribers']), $response['body']['total']); @@ -371,11 +373,11 @@ trait MessagingBase public function testSendEmail() { - $to = App::getEnv('_APP_MESSAGE_SMS_PROVIDER_MAILGUN_RECEIVER_EMAIL'); - $from = App::getEnv('_APP_MESSAGE_SMS_PROVIDER_MAILGUN_FROM'); - $apiKey = App::getEnv('_APP_MESSAGE_SMS_PROVIDER_MAILGUN_API_KEY'); - $domain = App::getEnv('_APP_MESSAGE_SMS_PROVIDER_MAILGUN_DOMAIN'); - $isEuRegion = App::getEnv('_APP_MESSAGE_SMS_PROVIDER_MAILGUN_IS_EU_REGION'); + $to = App::getEnv('_APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_RECEIVER_EMAIL'); + $from = App::getEnv('_APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_FROM'); + $apiKey = App::getEnv('_APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_API_KEY'); + $domain = App::getEnv('_APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_DOMAIN'); + $isEuRegion = App::getEnv('_APP_MESSAGE_EMAIL_PROVIDER_MAILGUN_IS_EU_REGION'); if (empty($to) || empty($from) || empty($apiKey) || empty($domain) || empty($isEuRegion)) { $this->markTestSkipped('Email provider not configured'); } @@ -415,7 +417,7 @@ trait MessagingBase 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ 'userId' => ID::custom('test-user'), - 'email' => 'prateekbanga12@gmail.com', + 'email' => $to, 'password' => 'password', 'name' => 'Messaging User', ], false); @@ -454,7 +456,7 @@ trait MessagingBase ], [ 'messageId' => ID::unique(), 'providerId' => $provider['body']['$id'], - 'to' => [$target['body']['$id']], + 'to' => [$topic['body']['$id']], 'subject' => 'Khali beats Undertaker', 'content' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', ]);