2023-10-05 09:42:04 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\E2E\Services\GraphQL;
|
|
|
|
|
|
|
|
use Tests\E2E\Client;
|
|
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
use Tests\E2E\Scopes\SideServer;
|
2023-10-17 11:11:42 +13:00
|
|
|
use Utopia\App;
|
2023-10-05 09:42:04 +13:00
|
|
|
use Utopia\Database\Helpers\ID;
|
2023-10-31 09:35:50 +13:00
|
|
|
use Utopia\DSN\DSN;
|
2023-10-05 09:42:04 +13:00
|
|
|
|
|
|
|
class MessagingTest extends Scope
|
|
|
|
{
|
|
|
|
use ProjectCustom;
|
|
|
|
use SideServer;
|
|
|
|
use Base;
|
|
|
|
|
|
|
|
public function testCreateProviders()
|
|
|
|
{
|
|
|
|
$providersParams = [
|
|
|
|
'Sendgrid' => [
|
|
|
|
'providerId' => ID::unique(),
|
|
|
|
'name' => 'Sengrid1',
|
|
|
|
'apiKey' => 'my-apikey',
|
2023-12-20 07:15:20 +13:00
|
|
|
'fromName' => 'Sender Name',
|
|
|
|
'fromEmail' => 'sender-email@my-domain.com',
|
2023-10-05 09:42:04 +13:00
|
|
|
],
|
|
|
|
'Mailgun' => [
|
|
|
|
'providerId' => ID::unique(),
|
|
|
|
'name' => 'Mailgun1',
|
|
|
|
'apiKey' => 'my-apikey',
|
|
|
|
'domain' => 'my-domain',
|
2023-12-20 07:15:20 +13:00
|
|
|
'fromName' => 'Sender Name',
|
|
|
|
'fromEmail' => 'sender-email@my-domain.com',
|
2023-10-26 07:25:45 +13:00
|
|
|
'isEuRegion' => false,
|
2023-10-05 09:42:04 +13:00
|
|
|
],
|
|
|
|
'Twilio' => [
|
|
|
|
'providerId' => ID::unique(),
|
|
|
|
'name' => 'Twilio1',
|
|
|
|
'accountSid' => 'my-accountSid',
|
|
|
|
'authToken' => 'my-authToken',
|
2023-10-24 08:35:46 +13:00
|
|
|
'from' => '+123456789',
|
2023-10-05 09:42:04 +13:00
|
|
|
],
|
|
|
|
'Telesign' => [
|
|
|
|
'providerId' => ID::unique(),
|
|
|
|
'name' => 'Telesign1',
|
|
|
|
'username' => 'my-username',
|
|
|
|
'password' => 'my-password',
|
2023-10-24 08:35:46 +13:00
|
|
|
'from' => '+123456789',
|
2023-10-05 09:42:04 +13:00
|
|
|
],
|
2023-11-21 20:05:36 +13:00
|
|
|
'Textmagic' => [
|
2023-10-05 09:42:04 +13:00
|
|
|
'providerId' => ID::unique(),
|
|
|
|
'name' => 'Textmagic1',
|
|
|
|
'username' => 'my-username',
|
|
|
|
'apiKey' => 'my-apikey',
|
2023-10-24 08:35:46 +13:00
|
|
|
'from' => '+123456789',
|
2023-10-05 09:42:04 +13:00
|
|
|
],
|
|
|
|
'Msg91' => [
|
|
|
|
'providerId' => ID::unique(),
|
|
|
|
'name' => 'Ms91-1',
|
|
|
|
'senderId' => 'my-senderid',
|
|
|
|
'authKey' => 'my-authkey',
|
|
|
|
'from' => '+123456789'
|
|
|
|
],
|
|
|
|
'Vonage' => [
|
|
|
|
'providerId' => ID::unique(),
|
|
|
|
'name' => 'Vonage1',
|
|
|
|
'apiKey' => 'my-apikey',
|
|
|
|
'apiSecret' => 'my-apisecret',
|
2023-10-24 08:35:46 +13:00
|
|
|
'from' => '+123456789',
|
2023-10-05 09:42:04 +13:00
|
|
|
],
|
2024-01-11 15:58:24 +13:00
|
|
|
'FCM' => [
|
2023-10-05 09:42:04 +13:00
|
|
|
'providerId' => ID::unique(),
|
|
|
|
'name' => 'FCM1',
|
2023-12-20 07:15:20 +13:00
|
|
|
'serviceAccountJSON' => [
|
|
|
|
'type' => 'service_account',
|
2024-01-09 13:41:55 +13:00
|
|
|
"project_id" => "test-project",
|
|
|
|
"private_key_id" => "test-private-key-id",
|
|
|
|
"private_key" => "test-private-key",
|
2023-12-20 07:15:20 +13:00
|
|
|
]
|
2023-10-05 09:42:04 +13:00
|
|
|
],
|
2024-01-11 15:58:24 +13:00
|
|
|
'APNS' => [
|
2023-10-05 09:42:04 +13:00
|
|
|
'providerId' => ID::unique(),
|
|
|
|
'name' => 'APNS1',
|
|
|
|
'authKey' => 'my-authkey',
|
|
|
|
'authKeyId' => 'my-authkeyid',
|
|
|
|
'teamId' => 'my-teamid',
|
|
|
|
'bundleId' => 'my-bundleid',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$providers = [];
|
|
|
|
|
|
|
|
foreach (\array_keys($providersParams) as $key) {
|
|
|
|
$query = $this->getQuery('create_' . \strtolower($key) . '_provider');
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => $providersParams[$key],
|
|
|
|
];
|
|
|
|
$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);
|
2024-01-09 13:41:55 +13:00
|
|
|
|
2023-10-05 09:42:04 +13:00
|
|
|
\array_push($providers, $response['body']['data']['messagingCreate' . $key . 'Provider']);
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals($providersParams[$key]['name'], $response['body']['data']['messagingCreate' . $key . 'Provider']['name']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $providers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateProviders
|
|
|
|
*/
|
|
|
|
public function testUpdateProviders(array $providers): array
|
|
|
|
{
|
|
|
|
$providersParams = [
|
|
|
|
'Sendgrid' => [
|
2023-10-07 02:53:46 +13:00
|
|
|
'providerId' => $providers[0]['_id'],
|
2023-10-05 09:42:04 +13:00
|
|
|
'name' => 'Sengrid2',
|
|
|
|
'apiKey' => 'my-apikey',
|
|
|
|
],
|
|
|
|
'Mailgun' => [
|
2023-10-07 02:53:46 +13:00
|
|
|
'providerId' => $providers[1]['_id'],
|
2023-10-05 09:42:04 +13:00
|
|
|
'name' => 'Mailgun2',
|
|
|
|
'apiKey' => 'my-apikey',
|
|
|
|
'domain' => 'my-domain',
|
|
|
|
],
|
|
|
|
'Twilio' => [
|
2023-10-07 02:53:46 +13:00
|
|
|
'providerId' => $providers[2]['_id'],
|
2023-10-05 09:42:04 +13:00
|
|
|
'name' => 'Twilio2',
|
|
|
|
'accountSid' => 'my-accountSid',
|
|
|
|
'authToken' => 'my-authToken',
|
|
|
|
],
|
|
|
|
'Telesign' => [
|
2023-10-07 02:53:46 +13:00
|
|
|
'providerId' => $providers[3]['_id'],
|
2023-10-05 09:42:04 +13:00
|
|
|
'name' => 'Telesign2',
|
|
|
|
'username' => 'my-username',
|
|
|
|
'password' => 'my-password',
|
|
|
|
],
|
2023-11-21 20:05:36 +13:00
|
|
|
'Textmagic' => [
|
2023-10-07 02:53:46 +13:00
|
|
|
'providerId' => $providers[4]['_id'],
|
2023-10-05 09:42:04 +13:00
|
|
|
'name' => 'Textmagic2',
|
|
|
|
'username' => 'my-username',
|
|
|
|
'apiKey' => 'my-apikey',
|
|
|
|
],
|
|
|
|
'Msg91' => [
|
2023-10-07 02:53:46 +13:00
|
|
|
'providerId' => $providers[5]['_id'],
|
2023-10-05 09:42:04 +13:00
|
|
|
'name' => 'Ms91-2',
|
|
|
|
'senderId' => 'my-senderid',
|
|
|
|
'authKey' => 'my-authkey',
|
|
|
|
],
|
|
|
|
'Vonage' => [
|
2023-10-07 02:53:46 +13:00
|
|
|
'providerId' => $providers[6]['_id'],
|
2023-10-05 09:42:04 +13:00
|
|
|
'name' => 'Vonage2',
|
|
|
|
'apiKey' => 'my-apikey',
|
|
|
|
'apiSecret' => 'my-apisecret',
|
|
|
|
],
|
2024-01-11 15:58:24 +13:00
|
|
|
'FCM' => [
|
2023-10-07 02:53:46 +13:00
|
|
|
'providerId' => $providers[7]['_id'],
|
2023-10-05 09:42:04 +13:00
|
|
|
'name' => 'FCM2',
|
2023-12-20 07:15:20 +13:00
|
|
|
'serviceAccountJSON' => [
|
|
|
|
'type' => 'service_account',
|
2024-01-09 13:41:55 +13:00
|
|
|
'project_id' => 'test-project',
|
|
|
|
'private_key_id' => 'test-project-id',
|
|
|
|
'private_key' => "test-private-key",
|
2023-12-20 07:15:20 +13:00
|
|
|
]
|
2023-10-05 09:42:04 +13:00
|
|
|
],
|
2024-01-11 15:58:24 +13:00
|
|
|
'APNS' => [
|
2023-10-07 02:53:46 +13:00
|
|
|
'providerId' => $providers[8]['_id'],
|
2023-10-05 09:42:04 +13:00
|
|
|
'name' => 'APNS2',
|
|
|
|
'authKey' => 'my-authkey',
|
|
|
|
'authKeyId' => 'my-authkeyid',
|
|
|
|
'teamId' => 'my-teamid',
|
|
|
|
'bundleId' => 'my-bundleid',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
foreach (\array_keys($providersParams) as $index => $key) {
|
|
|
|
$query = $this->getQuery('update_' . \strtolower($key) . '_provider');
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => $providersParams[$key],
|
|
|
|
];
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/graphql', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], $graphQLPayload);
|
|
|
|
$providers[$index] = $response['body']['data']['messagingUpdate' . $key . 'Provider'];
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals($providersParams[$key]['name'], $response['body']['data']['messagingUpdate' . $key . 'Provider']['name']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/graphql', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'query' => $this->getQuery('update_mailgun_provider'),
|
|
|
|
'variables' => [
|
2023-10-07 02:53:46 +13:00
|
|
|
'providerId' => $providers[1]['_id'],
|
2023-10-05 09:42:04 +13:00
|
|
|
'name' => 'Mailgun2',
|
|
|
|
'apiKey' => 'my-apikey',
|
|
|
|
'domain' => 'my-domain',
|
|
|
|
'isEuRegion' => true,
|
|
|
|
'enabled' => false,
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
$providers[1] = $response['body']['data']['messagingUpdateMailgunProvider'];
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals('Mailgun2', $response['body']['data']['messagingUpdateMailgunProvider']['name']);
|
|
|
|
$this->assertEquals(false, $response['body']['data']['messagingUpdateMailgunProvider']['enabled']);
|
|
|
|
return $providers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testUpdateProviders
|
|
|
|
*/
|
|
|
|
public function testListProviders(array $providers)
|
|
|
|
{
|
|
|
|
$query = $this->getQuery(self::$LIST_PROVIDERS);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
];
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/graphql', [
|
|
|
|
'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(\count($providers), \count($response['body']['data']['messagingListProviders']['providers']));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testUpdateProviders
|
|
|
|
*/
|
|
|
|
public function testGetProvider(array $providers)
|
|
|
|
{
|
|
|
|
$query = $this->getQuery(self::$GET_PROVIDER);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
2023-10-07 02:53:46 +13:00
|
|
|
'providerId' => $providers[0]['_id'],
|
2023-10-05 09:42:04 +13:00
|
|
|
]
|
|
|
|
];
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/graphql', [
|
|
|
|
'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($providers[0]['name'], $response['body']['data']['messagingGetProvider']['name']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testUpdateProviders
|
|
|
|
*/
|
|
|
|
public function testDeleteProvider(array $providers)
|
|
|
|
{
|
|
|
|
foreach ($providers as $provider) {
|
|
|
|
$query = $this->getQuery(self::$DELETE_PROVIDER);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
2023-10-07 02:53:46 +13:00
|
|
|
'providerId' => $provider['_id'],
|
2023-10-05 09:42:04 +13:00
|
|
|
]
|
|
|
|
];
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/graphql', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], $graphQLPayload);
|
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
}
|
|
|
|
}
|
2023-10-17 11:11:42 +13:00
|
|
|
|
|
|
|
public function testCreateTopic()
|
|
|
|
{
|
|
|
|
$query = $this->getQuery(self::$CREATE_TOPIC);
|
|
|
|
$graphQLPayload = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'topicId' => ID::unique(),
|
|
|
|
'name' => 'topic1',
|
|
|
|
],
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
$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']);
|
|
|
|
|
|
|
|
return $response['body']['data']['messagingCreateTopic'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateTopic
|
|
|
|
*/
|
|
|
|
public function testUpdateTopic(array $topic)
|
|
|
|
{
|
|
|
|
$topicId = $topic['_id'];
|
|
|
|
$query = $this->getQuery(self::$UPDATE_TOPIC);
|
|
|
|
$graphQLPayload = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'topicId' => $topicId,
|
|
|
|
'name' => 'topic2',
|
|
|
|
],
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
$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']);
|
|
|
|
|
|
|
|
return $topicId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateTopic
|
|
|
|
*/
|
|
|
|
public function testListTopics()
|
|
|
|
{
|
|
|
|
$query = $this->getQuery(self::$LIST_TOPICS);
|
|
|
|
$graphQLPayload = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
$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 = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'topicId' => $topicId,
|
|
|
|
],
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
$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']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateTopic
|
|
|
|
*/
|
|
|
|
public function testCreateSubscriber(array $topic)
|
|
|
|
{
|
|
|
|
$topicId = $topic['_id'];
|
|
|
|
|
|
|
|
$userId = $this->getUser()['$id'];
|
|
|
|
|
2023-10-27 03:14:06 +13:00
|
|
|
$providerParam = [
|
|
|
|
'sendgrid' => [
|
|
|
|
'providerId' => ID::unique(),
|
|
|
|
'name' => 'Sengrid1',
|
|
|
|
'apiKey' => 'my-apikey',
|
2023-12-20 07:15:20 +13:00
|
|
|
'fromName' => 'Sender',
|
|
|
|
'fromEmail' => 'sender-email@my-domain.com',
|
2023-10-27 03:14:06 +13:00
|
|
|
]
|
|
|
|
];
|
|
|
|
$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'];
|
|
|
|
|
2023-10-17 11:11:42 +13:00
|
|
|
$query = $this->getQuery(self::$CREATE_USER_TARGET);
|
|
|
|
$graphQLPayload = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'targetId' => ID::unique(),
|
2023-11-15 01:44:07 +13:00
|
|
|
'providerType' => 'email',
|
2023-10-18 06:23:26 +13:00
|
|
|
'userId' => $userId,
|
2023-10-27 03:14:06 +13:00
|
|
|
'providerId' => $providerId,
|
2023-11-21 22:41:09 +13:00
|
|
|
'identifier' => 'random-email@mail.org',
|
2023-10-18 06:23:26 +13:00
|
|
|
],
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
$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']);
|
2023-11-21 22:41:09 +13:00
|
|
|
$this->assertEquals('random-email@mail.org', $response['body']['data']['usersCreateTarget']['identifier']);
|
2023-10-17 11:11:42 +13:00
|
|
|
|
|
|
|
$targetId = $response['body']['data']['usersCreateTarget']['_id'];
|
|
|
|
|
|
|
|
$query = $this->getQuery(self::$CREATE_SUBSCRIBER);
|
|
|
|
$graphQLPayload = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'subscriberId' => ID::unique(),
|
|
|
|
'topicId' => $topicId,
|
|
|
|
'targetId' => $targetId,
|
|
|
|
],
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
$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']);
|
2023-11-20 20:04:50 +13:00
|
|
|
$this->assertEquals($response['body']['data']['messagingCreateSubscriber']['topicId'], $topicId);
|
|
|
|
$this->assertEquals($response['body']['data']['messagingCreateSubscriber']['targetId'], $targetId);
|
2023-11-24 06:44:02 +13:00
|
|
|
$this->assertEquals($response['body']['data']['messagingCreateSubscriber']['target']['userId'], $userId);
|
2023-10-17 11:11:42 +13:00
|
|
|
|
|
|
|
return $response['body']['data']['messagingCreateSubscriber'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-11-20 20:04:50 +13:00
|
|
|
* @depends testCreateSubscriber
|
2023-10-17 11:11:42 +13:00
|
|
|
*/
|
2023-11-20 20:04:50 +13:00
|
|
|
public function testListSubscribers(array $subscriber)
|
2023-10-17 11:11:42 +13:00
|
|
|
{
|
|
|
|
$query = $this->getQuery(self::$LIST_SUBSCRIBERS);
|
|
|
|
$graphQLPayload = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
2023-11-20 20:04:50 +13:00
|
|
|
'topicId' => $subscriber['topicId'],
|
2023-10-18 06:23:26 +13:00
|
|
|
],
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
$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']);
|
2023-11-24 06:44:02 +13:00
|
|
|
$this->assertEquals($subscriber['topicId'], $response['body']['data']['messagingListSubscribers']['subscribers'][0]['topicId']);
|
|
|
|
$this->assertEquals($subscriber['targetId'], $response['body']['data']['messagingListSubscribers']['subscribers'][0]['targetId']);
|
|
|
|
$this->assertEquals($subscriber['target']['userId'], $response['body']['data']['messagingListSubscribers']['subscribers'][0]['target']['userId']);
|
2023-10-17 11:11:42 +13:00
|
|
|
$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 = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'topicId' => $topicId,
|
|
|
|
'subscriberId' => $subscriberId,
|
|
|
|
],
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
|
|
|
|
$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']);
|
2023-11-20 20:04:50 +13:00
|
|
|
$this->assertEquals($topicId, $response['body']['data']['messagingGetSubscriber']['topicId']);
|
|
|
|
$this->assertEquals($subscriber['targetId'], $response['body']['data']['messagingGetSubscriber']['targetId']);
|
2023-11-24 06:44:02 +13:00
|
|
|
$this->assertEquals($subscriber['target']['userId'], $response['body']['data']['messagingGetSubscriber']['target']['userId']);
|
2023-10-17 11:11:42 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateSubscriber
|
|
|
|
*/
|
|
|
|
public function testDeleteSubscriber(array $subscriber)
|
|
|
|
{
|
|
|
|
$topicId = $subscriber['topicId'];
|
|
|
|
$subscriberId = $subscriber['_id'];
|
|
|
|
|
|
|
|
$query = $this->getQuery(self::$DELETE_SUBSCRIBER);
|
|
|
|
$graphQLPayload = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'topicId' => $topicId,
|
|
|
|
'subscriberId' => $subscriberId,
|
|
|
|
],
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
|
|
|
|
$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 = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'topicId' => $topicId,
|
|
|
|
],
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
$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()
|
|
|
|
{
|
2023-10-31 10:04:18 +13:00
|
|
|
if (empty(App::getEnv('_APP_MESSAGE_EMAIL_TEST_DSN'))) {
|
|
|
|
$this->markTestSkipped('Email DSN not provided');
|
|
|
|
}
|
|
|
|
|
2023-10-31 09:35:50 +13:00
|
|
|
$emailDSN = new DSN(App::getEnv('_APP_MESSAGE_EMAIL_TEST_DSN'));
|
|
|
|
$to = $emailDSN->getParam('to');
|
2023-12-20 07:15:20 +13:00
|
|
|
$fromName = $emailDSN->getParam('fromName');
|
|
|
|
$fromEmail = $emailDSN->getParam('fromEmail');
|
2023-10-31 09:35:50 +13:00
|
|
|
$isEuRegion = $emailDSN->getParam('isEuRegion');
|
|
|
|
$apiKey = $emailDSN->getPassword();
|
|
|
|
$domain = $emailDSN->getUser();
|
|
|
|
|
2023-10-17 11:11:42 +13:00
|
|
|
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 = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'providerId' => ID::unique(),
|
|
|
|
'name' => 'Mailgun1',
|
|
|
|
'apiKey' => $apiKey,
|
|
|
|
'domain' => $domain,
|
2023-12-20 07:15:20 +13:00
|
|
|
'fromName' => $fromName,
|
|
|
|
'fromEmail' => $fromEmail,
|
2023-10-27 03:14:06 +13:00
|
|
|
'isEuRegion' => filter_var($isEuRegion, FILTER_VALIDATE_BOOLEAN),
|
2023-10-18 06:23:26 +13:00
|
|
|
],
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
$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 = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'topicId' => ID::unique(),
|
|
|
|
'name' => 'topic1',
|
|
|
|
],
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
$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 = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
2023-10-19 20:59:48 +13:00
|
|
|
'userId' => ID::unique(),
|
|
|
|
'email' => 'random1-mail@mail.org',
|
2023-10-18 06:23:26 +13:00
|
|
|
'password' => 'password',
|
|
|
|
'name' => 'Messaging User',
|
|
|
|
]
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
$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 = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'targetId' => ID::unique(),
|
2023-11-15 01:44:07 +13:00
|
|
|
'providerType' => 'email',
|
2023-10-18 06:23:26 +13:00
|
|
|
'userId' => $user['body']['data']['usersCreate']['_id'],
|
|
|
|
'providerId' => $providerId,
|
|
|
|
'identifier' => $to,
|
|
|
|
],
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
$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 = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'subscriberId' => ID::unique(),
|
|
|
|
'topicId' => $topic['body']['data']['messagingCreateTopic']['_id'],
|
|
|
|
'targetId' => $target['body']['data']['usersCreateTarget']['_id'],
|
|
|
|
],
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
$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 = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'messageId' => ID::unique(),
|
2023-10-31 07:07:57 +13:00
|
|
|
'topics' => [$topic['body']['data']['messagingCreateTopic']['_id']],
|
2023-10-18 06:23:26 +13:00
|
|
|
'subject' => 'Khali beats Undertaker',
|
|
|
|
'content' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
|
|
|
],
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
$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 = [
|
2023-10-18 06:23:26 +13:00
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'messageId' => $email['body']['data']['messagingCreateEmail']['_id'],
|
|
|
|
],
|
2023-10-17 11:11:42 +13:00
|
|
|
];
|
|
|
|
$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']);
|
2023-10-31 07:07:57 +13:00
|
|
|
$this->assertEquals(1, $message['body']['data']['messagingGetMessage']['deliveredTotal']);
|
2023-10-17 11:11:42 +13:00
|
|
|
$this->assertEquals(0, \count($message['body']['data']['messagingGetMessage']['deliveryErrors']));
|
2023-10-19 20:59:48 +13:00
|
|
|
|
|
|
|
return $message['body']['data']['messagingGetMessage'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testSendEmail
|
|
|
|
*/
|
|
|
|
public function testUpdateEmail(array $email)
|
|
|
|
{
|
|
|
|
$query = $this->getQuery(self::$CREATE_EMAIL);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'messageId' => ID::unique(),
|
|
|
|
'status' => 'draft',
|
2023-11-15 08:54:55 +13:00
|
|
|
'topics' => [$email['topics'][0]],
|
2023-10-19 20:59:48 +13:00
|
|
|
'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']);
|
|
|
|
|
|
|
|
$query = $this->getQuery(self::$UPDATE_EMAIL);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'messageId' => $email['body']['data']['messagingCreateEmail']['_id'],
|
|
|
|
'status' => 'processing',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$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']['messagingUpdateEmail']['_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']);
|
2023-10-31 07:07:57 +13:00
|
|
|
$this->assertEquals(1, $message['body']['data']['messagingGetMessage']['deliveredTotal']);
|
2023-10-19 20:59:48 +13:00
|
|
|
$this->assertEquals(0, \count($message['body']['data']['messagingGetMessage']['deliveryErrors']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSendSMS()
|
|
|
|
{
|
2023-10-31 10:04:18 +13:00
|
|
|
if (empty(App::getEnv('_APP_MESSAGE_SMS_TEST_DSN'))) {
|
|
|
|
$this->markTestSkipped('SMS DSN not provided');
|
|
|
|
}
|
|
|
|
|
2023-10-31 09:35:50 +13:00
|
|
|
$smsDSN = new DSN(App::getEnv('_APP_MESSAGE_SMS_TEST_DSN'));
|
|
|
|
$to = $smsDSN->getParam('to');
|
|
|
|
$from = $smsDSN->getParam('from');
|
|
|
|
$authKey = $smsDSN->getPassword();
|
|
|
|
$senderId = $smsDSN->getUser();
|
|
|
|
|
2023-10-19 20:59:48 +13:00
|
|
|
if (empty($to) || empty($from) || empty($senderId) || empty($authKey)) {
|
|
|
|
$this->markTestSkipped('SMS provider not configured');
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = $this->getQuery(self::$CREATE_MSG91_PROVIDER);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'providerId' => ID::unique(),
|
|
|
|
'name' => 'Msg91-1',
|
|
|
|
'senderId' => $senderId,
|
|
|
|
'authKey' => $authKey,
|
|
|
|
'from' => $from,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$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']['messagingCreateMsg91Provider']['_id'];
|
|
|
|
|
|
|
|
$query = $this->getQuery(self::$CREATE_TOPIC);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'topicId' => ID::unique(),
|
|
|
|
'name' => 'topic1',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$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::unique(),
|
|
|
|
'email' => 'random3-email@mail.org',
|
|
|
|
'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(),
|
2023-11-15 01:44:07 +13:00
|
|
|
'providerType' => 'sms',
|
2023-10-19 20:59:48 +13:00
|
|
|
'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_SMS);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'messageId' => ID::unique(),
|
2023-10-31 07:07:57 +13:00
|
|
|
'topics' => [$topic['body']['data']['messagingCreateTopic']['_id']],
|
2023-10-19 20:59:48 +13:00
|
|
|
'content' => '454665',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$sms = $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, $sms['headers']['status-code']);
|
|
|
|
|
|
|
|
\sleep(5);
|
|
|
|
|
|
|
|
$query = $this->getQuery(self::$GET_MESSAGE);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'messageId' => $sms['body']['data']['messagingCreateSMS']['_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']);
|
2023-10-31 07:07:57 +13:00
|
|
|
$this->assertEquals(1, $message['body']['data']['messagingGetMessage']['deliveredTotal']);
|
2023-10-19 20:59:48 +13:00
|
|
|
$this->assertEquals(0, \count($message['body']['data']['messagingGetMessage']['deliveryErrors']));
|
|
|
|
return $message['body']['data']['messagingGetMessage'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testSendSMS
|
|
|
|
*/
|
|
|
|
public function testUpdateSMS(array $sms)
|
|
|
|
{
|
|
|
|
$query = $this->getQuery(self::$CREATE_SMS);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'messageId' => ID::unique(),
|
|
|
|
'status' => 'draft',
|
2023-11-15 08:54:55 +13:00
|
|
|
'topics' => [$sms['topics'][0]],
|
2023-10-19 20:59:48 +13:00
|
|
|
'content' => '345463',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$sms = $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, $sms['headers']['status-code']);
|
|
|
|
|
|
|
|
$query = $this->getQuery(self::$UPDATE_SMS);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'messageId' => $sms['body']['data']['messagingCreateSMS']['_id'],
|
|
|
|
'status' => 'processing',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$sms = $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, $sms['headers']['status-code']);
|
|
|
|
|
|
|
|
\sleep(5);
|
|
|
|
|
|
|
|
$query = $this->getQuery(self::$GET_MESSAGE);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'messageId' => $sms['body']['data']['messagingUpdateSMS']['_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']);
|
2023-10-31 07:07:57 +13:00
|
|
|
$this->assertEquals(1, $message['body']['data']['messagingGetMessage']['deliveredTotal']);
|
2023-10-19 20:59:48 +13:00
|
|
|
$this->assertEquals(0, \count($message['body']['data']['messagingGetMessage']['deliveryErrors']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSendPushNotification()
|
|
|
|
{
|
2023-10-31 10:04:18 +13:00
|
|
|
if (empty(App::getEnv('_APP_MESSAGE_PUSH_TEST_DSN'))) {
|
|
|
|
$this->markTestSkipped('Push DSN empty');
|
|
|
|
}
|
|
|
|
|
2023-10-31 09:35:50 +13:00
|
|
|
$pushDSN = new DSN(App::getEnv('_APP_MESSAGE_PUSH_TEST_DSN'));
|
|
|
|
$to = $pushDSN->getParam('to');
|
2024-01-09 13:41:55 +13:00
|
|
|
$serviceAccountJSON = $pushDSN->getParam('serviceAccountJSON');
|
2023-10-31 09:35:50 +13:00
|
|
|
|
2023-12-20 07:15:20 +13:00
|
|
|
if (empty($to) || empty($serviceAccountJSON)) {
|
2023-10-19 20:59:48 +13:00
|
|
|
$this->markTestSkipped('Push provider not configured');
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = $this->getQuery(self::$CREATE_FCM_PROVIDER);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'providerId' => ID::unique(),
|
|
|
|
'name' => 'FCM1',
|
2023-12-20 07:15:20 +13:00
|
|
|
'serviceAccountJSON' => [
|
|
|
|
'type' => 'service_account',
|
2024-01-09 13:41:55 +13:00
|
|
|
"project_id" => "test-project",
|
|
|
|
"private_key_id" => "test-private-key-id",
|
|
|
|
"private_key" => "test-private-key",
|
2023-12-20 07:15:20 +13:00
|
|
|
]
|
2023-10-19 20:59:48 +13:00
|
|
|
],
|
|
|
|
];
|
|
|
|
$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']);
|
|
|
|
|
2024-01-11 15:58:24 +13:00
|
|
|
$providerId = $provider['body']['data']['messagingCreateFCMProvider']['_id'];
|
2023-10-19 20:59:48 +13:00
|
|
|
|
|
|
|
$query = $this->getQuery(self::$CREATE_TOPIC);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'topicId' => ID::unique(),
|
|
|
|
'name' => 'topic1',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$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::unique(),
|
|
|
|
'email' => 'random5-mail@mail.org',
|
|
|
|
'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(),
|
2023-11-15 01:44:07 +13:00
|
|
|
'providerType' => 'push',
|
2023-10-19 20:59:48 +13:00
|
|
|
'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_PUSH_NOTIFICATION);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'messageId' => ID::unique(),
|
2023-10-31 07:07:57 +13:00
|
|
|
'topics' => [$topic['body']['data']['messagingCreateTopic']['_id']],
|
2023-10-19 20:59:48 +13:00
|
|
|
'title' => 'Push Notification Title',
|
|
|
|
'body' => 'Push Notifiaction Body',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$push = $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, $push['headers']['status-code']);
|
|
|
|
|
|
|
|
\sleep(5);
|
|
|
|
|
|
|
|
$query = $this->getQuery(self::$GET_MESSAGE);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'messageId' => $push['body']['data']['messagingCreatePushNotification']['_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']);
|
2023-10-31 07:07:57 +13:00
|
|
|
$this->assertEquals(1, $message['body']['data']['messagingGetMessage']['deliveredTotal']);
|
2023-10-19 20:59:48 +13:00
|
|
|
$this->assertEquals(0, \count($message['body']['data']['messagingGetMessage']['deliveryErrors']));
|
|
|
|
|
|
|
|
return $message['body']['data']['messagingGetMessage'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testSendPushNotification
|
|
|
|
*/
|
|
|
|
public function testUpdatePushNotification(array $push)
|
|
|
|
{
|
|
|
|
$query = $this->getQuery(self::$CREATE_PUSH_NOTIFICATION);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'messageId' => ID::unique(),
|
|
|
|
'status' => 'draft',
|
2023-11-15 08:54:55 +13:00
|
|
|
'topics' => [$push['topics'][0]],
|
2023-10-19 20:59:48 +13:00
|
|
|
'title' => 'Push Notification Title',
|
|
|
|
'body' => 'Push Notifiaction Body',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$push = $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, $push['headers']['status-code']);
|
|
|
|
|
|
|
|
$query = $this->getQuery(self::$UPDATE_PUSH_NOTIFICATION);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'messageId' => $push['body']['data']['messagingCreatePushNotification']['_id'],
|
|
|
|
'status' => 'processing',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$push = $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, $push['headers']['status-code']);
|
|
|
|
|
|
|
|
\sleep(5);
|
|
|
|
|
|
|
|
$query = $this->getQuery(self::$GET_MESSAGE);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'messageId' => $push['body']['data']['messagingUpdatePushNotification']['_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']);
|
2023-10-31 07:07:57 +13:00
|
|
|
$this->assertEquals(1, $message['body']['data']['messagingGetMessage']['deliveredTotal']);
|
2023-10-19 20:59:48 +13:00
|
|
|
$this->assertEquals(0, \count($message['body']['data']['messagingGetMessage']['deliveryErrors']));
|
2023-10-17 11:11:42 +13:00
|
|
|
}
|
2023-10-05 09:42:04 +13:00
|
|
|
}
|