test set deletion

This commit is contained in:
Yisroel Baum 2026-07-02 17:11:50 +03:00
parent 53d4120e83
commit ae48bdf93b
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
2 changed files with 205 additions and 0 deletions

View file

@ -222,6 +222,71 @@ class SetsEndpointTest extends TestCase
);
}
public function testDeleteSetRequiresAuthentication(): void
{
$setRepository = app(SetRepository::class);
$set = $setRepository->create(new CreateSetDto(
name: 'Set to delete',
description: 'Set deletion description',
iconImageUrl: '/assets/delete-icon.png',
));
$response = $this->deleteJson("/api/sets/{$set->getId()}");
$response->assertUnauthorized();
$response->assertExactJson([
'error' => 'unauthenticated',
]);
}
public function testAuthenticatedDeleteSetRemovesSetAndElements(): void
{
$setRepository = app(SetRepository::class);
$elementRepository = app(ElementRepository::class);
$this->createSession('valid-token');
$set = $setRepository->create(new CreateSetDto(
name: 'Set to delete',
description: 'Set deletion description',
iconImageUrl: 'set-icons/delete-icon.png',
));
$rootElement = $elementRepository->create(new CreateElementDto(
set: $set,
title: 'Root to delete',
description: 'Root deletion description',
iconImageUrl: 'set-icons/delete-icon.png',
richText: '',
shortPdfPath: null,
longPdfPath: null,
youtubeUrl: null,
parentElement: null,
));
$childElement = $elementRepository->create(new CreateElementDto(
set: $set,
title: 'Child to delete',
description: 'Child deletion description',
iconImageUrl: 'element-icons/delete-child.png',
richText: '',
shortPdfPath: 'element-pdfs/short/delete-child.pdf',
longPdfPath: 'element-pdfs/long/delete-child.pdf',
youtubeUrl: null,
parentElement: $rootElement,
));
$response = $this->withCredentials()
->withUnencryptedCookie('auth_token', 'valid-token')
->deleteJson("/api/sets/{$set->getId()}");
$response->assertNoContent();
$this->assertNull($setRepository->find($set->getId()));
$this->assertNull($elementRepository->find($rootElement->getId()));
$this->assertNull($elementRepository->find($childElement->getId()));
$setsResponse = $this->getJson('/api/sets');
$setsResponse->assertOk();
$setsResponse->assertJsonMissing([
'id' => $set->getId(),
]);
}
public function testCreateSetRequiresIconImage(): void
{
$this->createSession('valid-token');