1
0
Fork 0
mirror of synced 2024-05-09 23:32:38 +12:00

Fix tests

This commit is contained in:
Jake Barnby 2024-03-08 12:42:15 +01:00
parent 9c9de046c4
commit 6a795f4d7a
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
2 changed files with 30 additions and 21 deletions

View file

@ -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) {
$targetId = $targetId == 'unique()' ? ID::unique() : $targetId;
$provider = new Document();
if ($providerType === MESSAGE_TYPE_PUSH) {
$provider = $dbForProject->getDocument('providers', $providerId);
if ($provider->isEmpty()) {
throw new Exception(Exception::PROVIDER_NOT_FOUND);
}
}
$provider = $dbForProject->getDocument('providers', $providerId);
switch ($providerType) {
case 'email':
@ -520,7 +512,7 @@ App::post('/v1/users/:userId/targets')
Permission::update(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(),
'providerType' => $providerType,
'userId' => $userId,

View file

@ -884,7 +884,7 @@ trait MessagingBase
public function testCreateDraftPushWithImage()
{
// Create User 1
$response = $this->client->call(Client::METHOD_POST, '/users', [
$user = $this->client->call(Client::METHOD_POST, '/users', [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
@ -895,12 +895,22 @@ trait MessagingBase
'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']));
$targetId1 = $user1['targets'][0]['$id'];
$targetId = $target['body']['$id'];
// Create bucket
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
@ -921,14 +931,18 @@ trait MessagingBase
],
]);
$this->assertEquals(201, $response['headers']['status-code']);
$bucketId = $response['body']['$id'];
$this->assertEquals(201, $bucket['headers']['status-code']);
$bucketId = $bucket['body']['$id'];
\sleep(1);
// 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',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'x-appwrite-key' => $this->getProject()['apiKey'],
], [
'fileId' => ID::unique(),
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'),
'permissions' => [
@ -947,7 +961,7 @@ trait MessagingBase
'x-appwrite-key' => $this->getProject()['apiKey'],
], [
'messageId' => ID::unique(),
'targets' => [$targetId1],
'targets' => [$targetId],
'title' => 'New blog post',
'body' => 'Check out the new blog post at http://localhost',
'image' => "{$bucketId}:{$fileId}",
@ -962,7 +976,10 @@ trait MessagingBase
$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']);