test pdf uploads
This commit is contained in:
parent
97ecbebb9e
commit
1fbe198d8c
3 changed files with 312 additions and 0 deletions
|
|
@ -269,6 +269,81 @@ class ElementsEndpointTest extends TestCase
|
|||
Storage::disk('public')->assertExists($updatedIconImageUrl);
|
||||
}
|
||||
|
||||
public function testPdfUploadRequiresAuthentication(): void
|
||||
{
|
||||
$setRepository = app(SetRepository::class);
|
||||
$elementRepository = app(ElementRepository::class);
|
||||
$set = $setRepository->create(new CreateSetDto(
|
||||
name: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||
));
|
||||
$element = $elementRepository->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>A structured path for growth</p>',
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElement: null,
|
||||
));
|
||||
|
||||
$response = $this->post(
|
||||
"/api/elements/{$element->getId()}/pdf",
|
||||
['pdf' => $this->pdfUpload()],
|
||||
);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
$response->assertExactJson([
|
||||
'error' => 'unauthenticated',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testAuthenticatedPdfUploadReturnsElementPayload(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
$setRepository = app(SetRepository::class);
|
||||
$elementRepository = app(ElementRepository::class);
|
||||
$set = $setRepository->create(new CreateSetDto(
|
||||
name: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||
));
|
||||
$element = $elementRepository->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>A structured path for growth</p>',
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElement: null,
|
||||
));
|
||||
$this->createSession('valid-token');
|
||||
|
||||
$response = $this->withCredentials()
|
||||
->withUnencryptedCookie('auth_token', 'valid-token')
|
||||
->post(
|
||||
"/api/elements/{$element->getId()}/pdf",
|
||||
['pdf' => $this->pdfUpload()],
|
||||
);
|
||||
|
||||
$response->assertOk();
|
||||
$body = $response->json();
|
||||
$this->assertSame($element->getId(), $body['element']['id']);
|
||||
$this->assertStringContainsString(
|
||||
'/storage/element-pdfs/',
|
||||
$body['element']['pdfPath'],
|
||||
);
|
||||
$updatedElement = $elementRepository->find($element->getId());
|
||||
$this->assertNotNull($updatedElement);
|
||||
$updatedPdfPath = $updatedElement->getPdfPath();
|
||||
$this->assertIsString($updatedPdfPath);
|
||||
$this->assertStringStartsWith('element-pdfs/', $updatedPdfPath);
|
||||
Storage::disk('public')->assertExists($updatedPdfPath);
|
||||
}
|
||||
|
||||
private function createSession(string $token): void
|
||||
{
|
||||
$userRepository = app(UserRepository::class);
|
||||
|
|
@ -306,4 +381,19 @@ class ElementsEndpointTest extends TestCase
|
|||
true,
|
||||
);
|
||||
}
|
||||
|
||||
private function pdfUpload(): UploadedFile
|
||||
{
|
||||
$fixturePath = __DIR__
|
||||
. '/../../../frontend/rabbi_gerzi/public/assets/pdfs/'
|
||||
. 'baderech.pdf';
|
||||
|
||||
return new UploadedFile(
|
||||
$fixturePath,
|
||||
'baderech.pdf',
|
||||
'application/pdf',
|
||||
null,
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue