fix test cases
This commit is contained in:
parent
adc76c5797
commit
fdca55b0de
4 changed files with 66 additions and 578 deletions
|
@ -1920,18 +1920,11 @@ $commonCollections = [
|
|||
],
|
||||
[
|
||||
'$id' => ID::custom('_key_identifier'),
|
||||
'type' => Database::INDEX_KEY,
|
||||
'type' => Database::INDEX_UNIQUE,
|
||||
'attributes' => ['identifier'],
|
||||
'lengths' => [],
|
||||
'orders' => [],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('_key_identifier_userInternalId'),
|
||||
'type' => Database::INDEX_UNIQUE,
|
||||
'attributes' => ['identifier', 'userInternalId'],
|
||||
'lengths' => [],
|
||||
'orders' => [],
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
|
@ -147,15 +147,21 @@ App::post('/v1/account')
|
|||
'search' => implode(' ', [$userId, $email, $name]),
|
||||
'accessedAt' => DateTime::now(),
|
||||
]);
|
||||
$userInternalId = $user->getInternalId();
|
||||
$user->removeAttribute('$internalId');
|
||||
Authorization::skip(fn() => $dbForProject->createDocument('users', $user));
|
||||
Authorization::skip(fn() => $dbForProject->createDocument('targets', new Document([
|
||||
$user = Authorization::skip(fn() => $dbForProject->createDocument('users', $user));
|
||||
$target = Authorization::skip(fn() => $dbForProject->createDocument('targets', new Document([
|
||||
'$permissions' => [
|
||||
Permission::read(Role::any()),
|
||||
Permission::update(Role::user($userId)),
|
||||
Permission::delete(Role::user($userId)),
|
||||
],
|
||||
'userId' => $user->getId(),
|
||||
'userInternalId' => $userInternalId,
|
||||
'userInternalId' => $user->getInternalId(),
|
||||
'providerType' => 'email',
|
||||
'identifier' => $email,
|
||||
])));
|
||||
$user->setAttribute('targets', [$target]);
|
||||
$dbForProject->deleteCachedDocument('users', $user->getId());
|
||||
} catch (Duplicate) {
|
||||
throw new Exception(Exception::USER_ALREADY_EXISTS);
|
||||
}
|
||||
|
@ -663,7 +669,18 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
|
|||
'accessedAt' => DateTime::now(),
|
||||
]);
|
||||
$user->removeAttribute('$internalId');
|
||||
Authorization::skip(fn() => $dbForProject->createDocument('users', $user));
|
||||
$userDoc = Authorization::skip(fn() => $dbForProject->createDocument('users', $user));
|
||||
$dbForProject->createDocument('targets', new Document([
|
||||
'$permissions' => [
|
||||
Permission::read(Role::any()),
|
||||
Permission::update(Role::user($user->getId())),
|
||||
Permission::delete(Role::user($user->getId())),
|
||||
],
|
||||
'userId' => $userDoc->getId(),
|
||||
'userInternalId' => $userDoc->getInternalId(),
|
||||
'providerType' => 'email',
|
||||
'identifier' => $email,
|
||||
]));
|
||||
} catch (Duplicate) {
|
||||
$failureRedirect(Exception::USER_ALREADY_EXISTS);
|
||||
}
|
||||
|
@ -1336,16 +1353,21 @@ App::post('/v1/account/sessions/phone')
|
|||
|
||||
$target = $dbForProject->findOne('targets', [
|
||||
Query::equal('identifier', [$phone]),
|
||||
Query::equal('userInternalId', [$user->getInternalId()])
|
||||
]);
|
||||
|
||||
if (!$target || $target->isEmpty()) {
|
||||
$target = $dbForProject->createDocument('targets', new Document([
|
||||
'$permissions' => [
|
||||
Permission::read(Role::any()),
|
||||
Permission::update(Role::user($user->getId())),
|
||||
Permission::delete(Role::user($user->getId())),
|
||||
],
|
||||
'userId' => $user->getId(),
|
||||
'userInternalId' => $user->getInternalId(),
|
||||
'providerType' => 'sms',
|
||||
'identifier' => $phone,
|
||||
]));
|
||||
$dbForProject->deleteCachedDocument('users', $user->getId());
|
||||
}
|
||||
|
||||
$messageDoc = $dbForProject->createDocument('messages', new Document([
|
||||
|
@ -2029,7 +2051,6 @@ App::patch('/v1/account/email')
|
|||
|
||||
$target = $dbForProject->findOne('targets', [
|
||||
Query::equal('identifier', [$email]),
|
||||
Query::equal('userInternalId', [$user->getInternalId()])
|
||||
]);
|
||||
|
||||
if ($target && !$target->isEmpty()) {
|
||||
|
@ -2041,9 +2062,16 @@ App::patch('/v1/account/email')
|
|||
*/
|
||||
$oldTarget = $user->find('identifier', $oldEmail, 'targets');
|
||||
|
||||
if ($oldTarget !== false && !$oldTarget->isEmpty()) {
|
||||
try {
|
||||
$dbForProject->updateDocument('targets', $oldTarget->getId(), $oldTarget->setAttribute('identifier', $email));
|
||||
} catch (Duplicate) {
|
||||
throw new Exception(Exception::USER_TARGET_ALREADY_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$user = $dbForProject->withRequestTimestamp($requestTimestamp, fn () => $dbForProject->updateDocument('users', $user->getId(), $user));
|
||||
$dbForProject->updateDocument('targets', $oldTarget->getId(), $oldTarget->setAttribute('identifier', $email));
|
||||
} catch (Duplicate) {
|
||||
throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS);
|
||||
}
|
||||
|
@ -2090,7 +2118,6 @@ App::patch('/v1/account/phone')
|
|||
|
||||
$target = $dbForProject->findOne('targets', [
|
||||
Query::equal('identifier', [$phone]),
|
||||
Query::equal('userInternalId', [$user->getInternalId()])
|
||||
]);
|
||||
|
||||
if ($target && !$target->isEmpty()) {
|
||||
|
@ -2115,9 +2142,16 @@ App::patch('/v1/account/phone')
|
|||
->setAttribute('passwordUpdate', DateTime::now());
|
||||
}
|
||||
|
||||
if ($oldTarget !== false && !$oldTarget->isEmpty()) {
|
||||
try {
|
||||
$dbForProject->updateDocument('targets', $oldTarget->getId(), $oldTarget->setAttribute('identifier', $phone));
|
||||
} catch (Duplicate) {
|
||||
throw new Exception(Exception::USER_TARGET_ALREADY_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$user = $dbForProject->withRequestTimestamp($requestTimestamp, fn () => $dbForProject->updateDocument('users', $user->getId(), $user));
|
||||
$dbForProject->updateDocument('targets', $oldTarget->getId(), $oldTarget->setAttribute('identifier', $phone));
|
||||
} catch (Duplicate $th) {
|
||||
throw new Exception(Exception::USER_PHONE_ALREADY_EXISTS);
|
||||
}
|
||||
|
@ -2991,9 +3025,23 @@ App::post('/v1/account/verification/phone')
|
|||
|
||||
$target = $dbForProject->findOne('targets', [
|
||||
Query::equal('identifier', [$user->getAttribute('phone')]),
|
||||
Query::equal('userInternalId', [$user->getInternalId()])
|
||||
]);
|
||||
|
||||
if (!$target || $target->isEmpty()) {
|
||||
$target = $dbForProject->createDocument('targets', new Document([
|
||||
'$permissions' => [
|
||||
Permission::read(Role::any()),
|
||||
Permission::update(Role::user($user->getId())),
|
||||
Permission::delete(Role::user($user->getId())),
|
||||
],
|
||||
'userId' => $user->getId(),
|
||||
'userInternalId' => $user->getInternalId(),
|
||||
'providerType' => 'sms',
|
||||
'identifier' => $user->getAttribute('phone'),
|
||||
]));
|
||||
$dbForProject->deleteCachedDocument('users', $user->getId());
|
||||
}
|
||||
|
||||
$messageDoc = $dbForProject->createDocument('messages', new Document([
|
||||
'$id' => $verification->getId(),
|
||||
'targets' => [$target->getId()],
|
||||
|
|
|
@ -680,120 +680,13 @@ class MessagingTest extends Scope
|
|||
*/
|
||||
public function testUpdateEmail(array $email)
|
||||
{
|
||||
if (empty(App::getEnv('_APP_MESSAGE_EMAIL_TEST_DSN'))) {
|
||||
$this->markTestSkipped('Email DSN not provided');
|
||||
}
|
||||
|
||||
$emailDSN = new DSN(App::getEnv('_APP_MESSAGE_EMAIL_TEST_DSN'));
|
||||
$to = $emailDSN->getParam('to');
|
||||
$from = $emailDSN->getParam('from');
|
||||
$isEuRegion = $emailDSN->getParam('isEuRegion');
|
||||
$apiKey = $emailDSN->getPassword();
|
||||
$domain = $emailDSN->getUser();
|
||||
|
||||
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' => 'Mailgun2',
|
||||
'apiKey' => $apiKey,
|
||||
'domain' => $domain,
|
||||
'from' => $from,
|
||||
'isEuRegion' => filter_var($isEuRegion, FILTER_VALIDATE_BOOLEAN),
|
||||
],
|
||||
];
|
||||
$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' => [
|
||||
'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::unique(),
|
||||
'email' => 'random2-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(),
|
||||
'providerType' => 'email',
|
||||
'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(),
|
||||
'status' => 'draft',
|
||||
'topics' => [$topic['body']['data']['messagingCreateTopic']['_id']],
|
||||
'topics' => [$email['topics'][0]],
|
||||
'subject' => 'Khali beats Undertaker',
|
||||
'content' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
||||
],
|
||||
|
@ -992,118 +885,13 @@ class MessagingTest extends Scope
|
|||
*/
|
||||
public function testUpdateSMS(array $sms)
|
||||
{
|
||||
if (empty(App::getEnv('_APP_MESSAGE_SMS_TEST_DSN'))) {
|
||||
$this->markTestSkipped('SMS DSN not provided');
|
||||
}
|
||||
|
||||
$smsDSN = new DSN(App::getEnv('_APP_MESSAGE_SMS_TEST_DSN'));
|
||||
$to = $smsDSN->getParam('to');
|
||||
$from = $smsDSN->getParam('from');
|
||||
$authKey = $smsDSN->getPassword();
|
||||
$senderId = $smsDSN->getUser();
|
||||
|
||||
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-2',
|
||||
'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',
|
||||
'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::unique(),
|
||||
'email' => 'random4-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(),
|
||||
'providerType' => 'sms',
|
||||
'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(),
|
||||
'status' => 'draft',
|
||||
'topics' => [$topic['body']['data']['messagingCreateTopic']['_id']],
|
||||
'topics' => [$sms['topics'][0]],
|
||||
'content' => '345463',
|
||||
],
|
||||
];
|
||||
|
@ -1299,113 +1087,13 @@ class MessagingTest extends Scope
|
|||
*/
|
||||
public function testUpdatePushNotification(array $push)
|
||||
{
|
||||
if (empty(App::getEnv('_APP_MESSAGE_PUSH_TEST_DSN'))) {
|
||||
$this->markTestSkipped('Push DSN empty');
|
||||
}
|
||||
|
||||
$pushDSN = new DSN(App::getEnv('_APP_MESSAGE_PUSH_TEST_DSN'));
|
||||
$to = $pushDSN->getParam('to');
|
||||
$serverKey = $pushDSN->getPassword();
|
||||
|
||||
if (empty($to) || empty($serverKey)) {
|
||||
$this->markTestSkipped('Push provider not configured');
|
||||
}
|
||||
|
||||
$query = $this->getQuery(self::$CREATE_FCM_PROVIDER);
|
||||
$graphQLPayload = [
|
||||
'query' => $query,
|
||||
'variables' => [
|
||||
'providerId' => ID::unique(),
|
||||
'name' => 'FCM2',
|
||||
'serverKey' => $serverKey,
|
||||
],
|
||||
];
|
||||
$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']['messagingCreateFcmProvider']['_id'];
|
||||
|
||||
$query = $this->getQuery(self::$CREATE_TOPIC);
|
||||
$graphQLPayload = [
|
||||
'query' => $query,
|
||||
'variables' => [
|
||||
'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::unique(),
|
||||
'email' => 'random5-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(),
|
||||
'providerType' => 'push',
|
||||
'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(),
|
||||
'status' => 'draft',
|
||||
'topics' => [$topic['body']['data']['messagingCreateTopic']['_id']],
|
||||
'topics' => [$push['topics'][0]],
|
||||
'title' => 'Push Notification Title',
|
||||
'body' => 'Push Notifiaction Body',
|
||||
],
|
||||
|
|
|
@ -649,21 +649,6 @@ trait MessagingBase
|
|||
*/
|
||||
public function testUpdateEmail(array $email)
|
||||
{
|
||||
if (empty(App::getEnv('_APP_MESSAGE_EMAIL_TEST_DSN'))) {
|
||||
$this->markTestSkipped('Email DSN not provided');
|
||||
}
|
||||
|
||||
$emailDSN = new DSN(App::getEnv('_APP_MESSAGE_EMAIL_TEST_DSN'));
|
||||
$to = $emailDSN->getParam('to');
|
||||
$from = $emailDSN->getParam('from');
|
||||
$isEuRegion = $emailDSN->getParam('isEuRegion');
|
||||
$apiKey = $emailDSN->getPassword();
|
||||
$domain = $emailDSN->getUser();
|
||||
|
||||
if (empty($to) || empty($from) || empty($apiKey) || empty($domain) || empty($isEuRegion)) {
|
||||
$this->markTestSkipped('Email provider not configured');
|
||||
}
|
||||
|
||||
$message = $this->client->call(Client::METHOD_PATCH, '/messaging/messages/email/' . $email['body']['$id'], [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
|
@ -673,74 +658,6 @@ trait MessagingBase
|
|||
// Test failure as the message has already been sent.
|
||||
$this->assertEquals(400, $message['headers']['status-code']);
|
||||
|
||||
// Create provider
|
||||
$provider = $this->client->call(Client::METHOD_POST, '/messaging/providers/mailgun', \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
]), [
|
||||
'providerId' => ID::unique(),
|
||||
'name' => 'Mailgun-provider-2',
|
||||
'apiKey' => $apiKey,
|
||||
'domain' => $domain,
|
||||
'isEuRegion' => filter_var($isEuRegion, FILTER_VALIDATE_BOOLEAN),
|
||||
'from' => $from
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $provider['headers']['status-code']);
|
||||
|
||||
// Create Topic
|
||||
$topic = $this->client->call(Client::METHOD_POST, '/messaging/topics', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'topicId' => ID::unique(),
|
||||
'name' => 'topic1',
|
||||
'description' => 'Test Topic'
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $topic['headers']['status-code']);
|
||||
|
||||
// Create User
|
||||
$user = $this->client->call(Client::METHOD_POST, '/users', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'userId' => ID::unique(),
|
||||
'email' => 'random-email@mail.org',
|
||||
'password' => 'password',
|
||||
'name' => 'Messaging User',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $user['headers']['status-code']);
|
||||
|
||||
// Create Target
|
||||
$target = $this->client->call(Client::METHOD_POST, '/users/' . $user['body']['$id'] . '/targets', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'targetId' => ID::unique(),
|
||||
'providerType' => 'email',
|
||||
'providerId' => $provider['body']['$id'],
|
||||
'identifier' => $to,
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $target['headers']['status-code']);
|
||||
|
||||
// Create Subscriber
|
||||
$subscriber = $this->client->call(Client::METHOD_POST, '/messaging/topics/' . $topic['body']['$id'] . '/subscribers', \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'subscriberId' => ID::unique(),
|
||||
'targetId' => $target['body']['$id'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $subscriber['headers']['status-code']);
|
||||
|
||||
// Create Email
|
||||
$email = $this->client->call(Client::METHOD_POST, '/messaging/messages/email', [
|
||||
'content-type' => 'application/json',
|
||||
|
@ -749,7 +666,7 @@ trait MessagingBase
|
|||
], [
|
||||
'messageId' => ID::unique(),
|
||||
'status' => 'draft',
|
||||
'topics' => [$topic['body']['$id']],
|
||||
'topics' => [$email['body']['topics'][0]],
|
||||
'subject' => 'Khali beats Undertaker',
|
||||
'content' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
||||
]);
|
||||
|
@ -897,20 +814,6 @@ trait MessagingBase
|
|||
*/
|
||||
public function testUpdateSMS(array $sms)
|
||||
{
|
||||
if (empty(App::getEnv('_APP_MESSAGE_SMS_TEST_DSN'))) {
|
||||
$this->markTestSkipped('SMS DSN not provided');
|
||||
}
|
||||
|
||||
$smsDSN = new DSN(App::getEnv('_APP_MESSAGE_SMS_TEST_DSN'));
|
||||
$to = $smsDSN->getParam('to');
|
||||
$from = $smsDSN->getParam('from');
|
||||
$authKey = $smsDSN->getPassword();
|
||||
$senderId = $smsDSN->getUser();
|
||||
|
||||
if (empty($to) || empty($from) || empty($senderId) || empty($authKey)) {
|
||||
$this->markTestSkipped('SMS provider not configured');
|
||||
}
|
||||
|
||||
$message = $this->client->call(Client::METHOD_PATCH, '/messaging/messages/sms/' . $sms['body']['$id'], [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
|
@ -920,73 +823,6 @@ trait MessagingBase
|
|||
// Test failure as the message has already been sent.
|
||||
$this->assertEquals(400, $message['headers']['status-code']);
|
||||
|
||||
// Create provider
|
||||
$provider = $this->client->call(Client::METHOD_POST, '/messaging/providers/msg91', \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
]), [
|
||||
'providerId' => ID::unique(),
|
||||
'name' => 'Msg91-2',
|
||||
'senderId' => $senderId,
|
||||
'authKey' => $authKey,
|
||||
'from' => $from
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $provider['headers']['status-code']);
|
||||
|
||||
// Create Topic
|
||||
$topic = $this->client->call(Client::METHOD_POST, '/messaging/topics', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'topicId' => ID::unique(),
|
||||
'name' => 'topic1',
|
||||
'description' => 'Test Topic'
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $topic['headers']['status-code']);
|
||||
|
||||
// Create User
|
||||
$user = $this->client->call(Client::METHOD_POST, '/users', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'userId' => ID::unique(),
|
||||
'email' => 'random2-email@mail.org',
|
||||
'password' => 'password',
|
||||
'name' => 'Messaging User',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $user['headers']['status-code']);
|
||||
|
||||
// Create Target
|
||||
$target = $this->client->call(Client::METHOD_POST, '/users/' . $user['body']['$id'] . '/targets', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'targetId' => ID::unique(),
|
||||
'providerType' => 'sms',
|
||||
'providerId' => $provider['body']['$id'],
|
||||
'identifier' => $to,
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $target['headers']['status-code']);
|
||||
|
||||
// Create Subscriber
|
||||
$subscriber = $this->client->call(Client::METHOD_POST, '/messaging/topics/' . $topic['body']['$id'] . '/subscribers', \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'subscriberId' => ID::unique(),
|
||||
'targetId' => $target['body']['$id'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $subscriber['headers']['status-code']);
|
||||
|
||||
// Create SMS
|
||||
$sms = $this->client->call(Client::METHOD_POST, '/messaging/messages/sms', [
|
||||
'content-type' => 'application/json',
|
||||
|
@ -995,7 +831,7 @@ trait MessagingBase
|
|||
], [
|
||||
'messageId' => ID::unique(),
|
||||
'status' => 'draft',
|
||||
'topics' => [$topic['body']['$id']],
|
||||
'topics' => [$sms['body']['topics'][0]],
|
||||
'content' => '047487',
|
||||
]);
|
||||
|
||||
|
@ -1139,18 +975,6 @@ trait MessagingBase
|
|||
*/
|
||||
public function testUpdatePushNotification(array $push)
|
||||
{
|
||||
if (empty(App::getEnv('_APP_MESSAGE_PUSH_TEST_DSN'))) {
|
||||
$this->markTestSkipped('Push DSN empty');
|
||||
}
|
||||
|
||||
$pushDSN = new DSN(App::getEnv('_APP_MESSAGE_PUSH_TEST_DSN'));
|
||||
$to = $pushDSN->getParam('to');
|
||||
$serverKey = $pushDSN->getPassword();
|
||||
|
||||
if (empty($to) || empty($serverKey)) {
|
||||
$this->markTestSkipped('Push provider not configured');
|
||||
}
|
||||
|
||||
$message = $this->client->call(Client::METHOD_PATCH, '/messaging/messages/push/' . $push['body']['$id'], [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
|
@ -1160,71 +984,6 @@ trait MessagingBase
|
|||
// Test failure as the message has already been sent.
|
||||
$this->assertEquals(400, $message['headers']['status-code']);
|
||||
|
||||
// Create provider
|
||||
$provider = $this->client->call(Client::METHOD_POST, '/messaging/providers/fcm', \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
]), [
|
||||
'providerId' => ID::unique(),
|
||||
'name' => 'FCM-2',
|
||||
'serverKey' => $serverKey,
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $provider['headers']['status-code']);
|
||||
|
||||
// Create Topic
|
||||
$topic = $this->client->call(Client::METHOD_POST, '/messaging/topics', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'topicId' => ID::unique(),
|
||||
'name' => 'topic1',
|
||||
'description' => 'Test Topic'
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $topic['headers']['status-code']);
|
||||
|
||||
// Create User
|
||||
$user = $this->client->call(Client::METHOD_POST, '/users', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'userId' => ID::unique(),
|
||||
'email' => 'random4-email@mail.org',
|
||||
'password' => 'password',
|
||||
'name' => 'Messaging User',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $user['headers']['status-code']);
|
||||
|
||||
// Create Target
|
||||
$target = $this->client->call(Client::METHOD_POST, '/users/' . $user['body']['$id'] . '/targets', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'targetId' => ID::unique(),
|
||||
'providerType' => 'push',
|
||||
'providerId' => $provider['body']['$id'],
|
||||
'identifier' => $to,
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $target['headers']['status-code']);
|
||||
|
||||
// Create Subscriber
|
||||
$subscriber = $this->client->call(Client::METHOD_POST, '/messaging/topics/' . $topic['body']['$id'] . '/subscribers', \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'subscriberId' => ID::unique(),
|
||||
'targetId' => $target['body']['$id'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $subscriber['headers']['status-code']);
|
||||
|
||||
// Create push notification
|
||||
$push = $this->client->call(Client::METHOD_POST, '/messaging/messages/push', [
|
||||
'content-type' => 'application/json',
|
||||
|
@ -1233,7 +992,7 @@ trait MessagingBase
|
|||
], [
|
||||
'messageId' => ID::unique(),
|
||||
'status' => 'draft',
|
||||
'topics' => [$topic['body']['$id']],
|
||||
'topics' => [$push['body']['topics'][0]],
|
||||
'title' => 'Test-Notification',
|
||||
'body' => 'Test-Notification-Body',
|
||||
]);
|
||||
|
|
Loading…
Reference in a new issue