test set edits
This commit is contained in:
parent
f4e7f54fc0
commit
f8e1ef1397
2 changed files with 263 additions and 0 deletions
|
|
@ -140,6 +140,88 @@ class SetsEndpointTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testUpdateSetRequiresAuthentication(): void
|
||||
{
|
||||
$setRepository = app(SetRepository::class);
|
||||
$set = $setRepository->create(new CreateSetDto(
|
||||
name: 'Original Set',
|
||||
description: 'Original set description',
|
||||
iconImageUrl: '/assets/original-icon.png',
|
||||
));
|
||||
|
||||
$response = $this->postJson(
|
||||
"/api/sets/{$set->getId()}/update",
|
||||
[
|
||||
'name' => 'Updated Set',
|
||||
'description' => 'Updated set description',
|
||||
],
|
||||
);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
$response->assertExactJson([
|
||||
'error' => 'unauthenticated',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testAuthenticatedUpdateSetUpdatesMediaPayloadOnly(): void
|
||||
{
|
||||
$setRepository = app(SetRepository::class);
|
||||
$elementRepository = app(ElementRepository::class);
|
||||
$this->createSession('valid-token');
|
||||
$set = $setRepository->create(new CreateSetDto(
|
||||
name: 'Original Set',
|
||||
description: 'Original set description',
|
||||
iconImageUrl: '/assets/original-icon.png',
|
||||
));
|
||||
$rootElement = $elementRepository->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: 'Original Root',
|
||||
description: 'Original root description',
|
||||
iconImageUrl: '/assets/original-icon.png',
|
||||
richText: '',
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElement: null,
|
||||
));
|
||||
|
||||
$response = $this->withCredentials()
|
||||
->withUnencryptedCookie('auth_token', 'valid-token')
|
||||
->postJson("/api/sets/{$set->getId()}/update", [
|
||||
'name' => 'Updated Set',
|
||||
'description' => 'Updated set description',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertExactJson([
|
||||
'set' => [
|
||||
'id' => $set->getId(),
|
||||
'name' => 'Updated Set',
|
||||
'description' => 'Updated set description',
|
||||
'iconImageUrl' => '/assets/original-icon.png',
|
||||
'rootElementId' => $rootElement->getId(),
|
||||
],
|
||||
]);
|
||||
|
||||
$updatedSet = $setRepository->find($set->getId());
|
||||
$this->assertNotNull($updatedSet);
|
||||
$this->assertSame('Updated Set', $updatedSet->getName());
|
||||
$this->assertSame(
|
||||
'Updated set description',
|
||||
$updatedSet->getDescription(),
|
||||
);
|
||||
|
||||
$unchangedRootElement = $elementRepository->find(
|
||||
$rootElement->getId(),
|
||||
);
|
||||
$this->assertNotNull($unchangedRootElement);
|
||||
$this->assertSame('Original Root', $unchangedRootElement->getTitle());
|
||||
$this->assertSame(
|
||||
'Original root description',
|
||||
$unchangedRootElement->getDescription(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateSetRequiresIconImage(): void
|
||||
{
|
||||
$this->createSession('valid-token');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue