test media removal

This commit is contained in:
Yisroel Baum 2026-06-02 16:58:00 +03:00
parent d0810ba4b3
commit 4b432d9b99
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
4 changed files with 177 additions and 4 deletions

View file

@ -193,6 +193,60 @@ class ElementsEndpointTest extends TestCase
);
}
public function testAuthenticatedUpdateClearsUploadedMedia(): void
{
Storage::fake('public');
Storage::disk('public')->put(
'element-icons/original-icon.png',
'icon bytes',
);
Storage::disk('public')->put(
'element-pdfs/original.pdf',
'pdf bytes',
);
$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: 'element-icons/original-icon.png',
richText: '<p>A structured path for growth</p>',
pdfPath: 'element-pdfs/original.pdf',
youtubeUrl: null,
parentElement: null,
));
$this->createSession('valid-token');
$response = $this->withCredentials()
->withUnencryptedCookie('auth_token', 'valid-token')
->postJson('/api/element/update', [
'elementId' => $element->getId(),
'iconImageUrl' => '',
'pdfPath' => '',
]);
$response->assertOk();
$body = $response->json();
$this->assertNull($body['element']['iconImageUrl']);
$this->assertNull($body['element']['pdfPath']);
$updatedElement = $elementRepository->find($element->getId());
$this->assertNotNull($updatedElement);
$this->assertNull($updatedElement->getIconImageUrl());
$this->assertNull($updatedElement->getPdfPath());
Storage::disk('public')->assertMissing(
'element-icons/original-icon.png',
);
Storage::disk('public')->assertMissing(
'element-pdfs/original.pdf',
);
}
public function testIconImageUploadRequiresAuthentication(): void
{
$setRepository = app(SetRepository::class);