Skip to content

Commit

Permalink
CI: Fix test for message with attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Jun 11, 2024
1 parent 1576694 commit 602d1ac
Showing 1 changed file with 44 additions and 30 deletions.
74 changes: 44 additions & 30 deletions tests/CoreBundle/Repository/MessageRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,35 @@ public function testCreateMessageWithAttachment(): void

$client = $this->createClientWithCredentials($user1Token);

$responseMessage = $client->request(
$file = $this->getUploadedFile();

$resourceFile = $client->request(
'POST',
'/api/resource_files',
[
'headers' => [
'Content-Type' => 'multipart/form-data',
],
'extra' => [
'files' => [
'file' => $file,
],
],
]
);

$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains(
[
'@context' => '/api/contexts/ResourceFile',
'@type' => 'http://schema.org/MediaObject',
]
);

$resourceFileId = $resourceFile->toArray()['@id'];

$client->request(
'POST',
'/api/messages',
[
Expand All @@ -283,6 +311,11 @@ public function testCreateMessageWithAttachment(): void
],
],
'sender' => "/api/users/{$user1->getId()}",
'attachments' => [
[
'resourceFileToAttach' => $resourceFileId,
]
]
],
]
);
Expand All @@ -308,39 +341,20 @@ public function testCreateMessageWithAttachment(): void
'msgType' => Message::MESSAGE_TYPE_INBOX,
'title' => 'Message title',
'content' => 'Message content',
]
);

$messageId = $responseMessage->toArray()['id'];

$file = $this->getUploadedFile();

$responseAttachment = $client->request(
'POST',
'/api/message_attachments',
[
'headers' => [
'Content-Type' => 'multipart/form-data',
],
'extra' => [
'files' => [
'file' => $file,
],
'parameters' => [
'messageId' => $messageId,
'attachments' => [
[
'@type' => 'http://schema.org/MediaObject',
'resourceNode' => [
'@type' => 'ResourceNode',
'resourceFile' => [
'@type' => 'http://schema.org/MediaObject',
'@id' => $resourceFileId,
],
],
],
],
]
);

$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains(
[
'@context' => '/api/contexts/MessageAttachment',
'@type' => 'http://schema.org/MediaObject',
]
);
}

public function testDeleteMessage(): void
Expand Down

0 comments on commit 602d1ac

Please sign in to comment.