Fix tests
This commit is contained in:
parent
9c9de046c4
commit
6a795f4d7a
|
@ -471,15 +471,7 @@ App::post('/v1/users/:userId/targets')
|
||||||
->action(function (string $targetId, string $userId, string $providerType, string $identifier, string $providerId, string $name, Event $queueForEvents, Response $response, Database $dbForProject) {
|
->action(function (string $targetId, string $userId, string $providerType, string $identifier, string $providerId, string $name, Event $queueForEvents, Response $response, Database $dbForProject) {
|
||||||
$targetId = $targetId == 'unique()' ? ID::unique() : $targetId;
|
$targetId = $targetId == 'unique()' ? ID::unique() : $targetId;
|
||||||
|
|
||||||
$provider = new Document();
|
$provider = $dbForProject->getDocument('providers', $providerId);
|
||||||
|
|
||||||
if ($providerType === MESSAGE_TYPE_PUSH) {
|
|
||||||
$provider = $dbForProject->getDocument('providers', $providerId);
|
|
||||||
|
|
||||||
if ($provider->isEmpty()) {
|
|
||||||
throw new Exception(Exception::PROVIDER_NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($providerType) {
|
switch ($providerType) {
|
||||||
case 'email':
|
case 'email':
|
||||||
|
@ -520,7 +512,7 @@ App::post('/v1/users/:userId/targets')
|
||||||
Permission::update(Role::user($user->getId())),
|
Permission::update(Role::user($user->getId())),
|
||||||
Permission::delete(Role::user($user->getId())),
|
Permission::delete(Role::user($user->getId())),
|
||||||
],
|
],
|
||||||
'providerId' => $providerId ?? null,
|
'providerId' => empty($provider->getId()) ? null : $provider->getId(),
|
||||||
'providerInternalId' => $provider->isEmpty() ? null : $provider->getInternalId(),
|
'providerInternalId' => $provider->isEmpty() ? null : $provider->getInternalId(),
|
||||||
'providerType' => $providerType,
|
'providerType' => $providerType,
|
||||||
'userId' => $userId,
|
'userId' => $userId,
|
||||||
|
|
|
@ -884,7 +884,7 @@ trait MessagingBase
|
||||||
public function testCreateDraftPushWithImage()
|
public function testCreateDraftPushWithImage()
|
||||||
{
|
{
|
||||||
// Create User 1
|
// Create User 1
|
||||||
$response = $this->client->call(Client::METHOD_POST, '/users', [
|
$user = $this->client->call(Client::METHOD_POST, '/users', [
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||||
|
@ -895,12 +895,22 @@ trait MessagingBase
|
||||||
'name' => 'Messaging User 1',
|
'name' => 'Messaging User 1',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(201, $response['headers']['status-code'], "Error creating user: " . var_export($response['body'], true));
|
$this->assertEquals(201, $user['headers']['status-code'], "Error creating user: " . var_export($user['body'], true));
|
||||||
|
$this->assertEquals(1, \count($user['body']['targets']));
|
||||||
|
|
||||||
$user1 = $response['body'];
|
// Create push 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(),
|
||||||
|
'userId' => $user['body']['$id'],
|
||||||
|
'providerType' => 'push',
|
||||||
|
'identifier' => '123456',
|
||||||
|
]);
|
||||||
|
|
||||||
$this->assertEquals(1, \count($user1['targets']));
|
$targetId = $target['body']['$id'];
|
||||||
$targetId1 = $user1['targets'][0]['$id'];
|
|
||||||
|
|
||||||
// Create bucket
|
// Create bucket
|
||||||
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
|
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
|
||||||
|
@ -921,14 +931,18 @@ trait MessagingBase
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(201, $response['headers']['status-code']);
|
$this->assertEquals(201, $bucket['headers']['status-code']);
|
||||||
$bucketId = $response['body']['$id'];
|
|
||||||
|
$bucketId = $bucket['body']['$id'];
|
||||||
|
|
||||||
|
\sleep(1);
|
||||||
|
|
||||||
// Create file
|
// Create file
|
||||||
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
||||||
'content-type' => 'multipart/form-data',
|
'content-type' => 'multipart/form-data',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
], $this->getHeaders()), [
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||||
|
], [
|
||||||
'fileId' => ID::unique(),
|
'fileId' => ID::unique(),
|
||||||
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'),
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'),
|
||||||
'permissions' => [
|
'permissions' => [
|
||||||
|
@ -947,7 +961,7 @@ trait MessagingBase
|
||||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||||
], [
|
], [
|
||||||
'messageId' => ID::unique(),
|
'messageId' => ID::unique(),
|
||||||
'targets' => [$targetId1],
|
'targets' => [$targetId],
|
||||||
'title' => 'New blog post',
|
'title' => 'New blog post',
|
||||||
'body' => 'Check out the new blog post at http://localhost',
|
'body' => 'Check out the new blog post at http://localhost',
|
||||||
'image' => "{$bucketId}:{$fileId}",
|
'image' => "{$bucketId}:{$fileId}",
|
||||||
|
@ -962,7 +976,10 @@ trait MessagingBase
|
||||||
|
|
||||||
$imageUrl = $message['data']['image']['url'];
|
$imageUrl = $message['data']['image']['url'];
|
||||||
|
|
||||||
$image = $this->client->call(Client::METHOD_GET, $imageUrl);
|
$client = new Client();
|
||||||
|
$client->setEndpoint('');
|
||||||
|
|
||||||
|
$image = $client->call(Client::METHOD_GET, $imageUrl);
|
||||||
|
|
||||||
$this->assertEquals(200, $image['headers']['status-code']);
|
$this->assertEquals(200, $image['headers']['status-code']);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue