test persisted set ordering
This commit is contained in:
parent
7579c3c1b3
commit
fde12ad561
2 changed files with 227 additions and 0 deletions
|
|
@ -73,6 +73,98 @@ class SetsEndpointTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function testReorderSetsRequiresAuthentication(): void
|
||||
{
|
||||
$response = $this->putJson('/api/sets/order', [
|
||||
'setIds' => [1, 2],
|
||||
]);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
$response->assertExactJson([
|
||||
'error' => 'unauthenticated',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testAuthenticatedReorderSetsPersistsPublicOrder(): void
|
||||
{
|
||||
$setRepository = app(SetRepository::class);
|
||||
$firstSet = $setRepository->create(new CreateSetDto(
|
||||
name: 'First Set',
|
||||
description: 'First set description',
|
||||
iconImageUrl: '/assets/first.png',
|
||||
));
|
||||
$secondSet = $setRepository->create(new CreateSetDto(
|
||||
name: 'Second Set',
|
||||
description: 'Second set description',
|
||||
iconImageUrl: '/assets/second.png',
|
||||
));
|
||||
$thirdSet = $setRepository->create(new CreateSetDto(
|
||||
name: 'Third Set',
|
||||
description: 'Third set description',
|
||||
iconImageUrl: '/assets/third.png',
|
||||
));
|
||||
$this->createSession('valid-token');
|
||||
|
||||
$response = $this->withCredentials()
|
||||
->withUnencryptedCookie('auth_token', 'valid-token')
|
||||
->putJson('/api/sets/order', [
|
||||
'setIds' => [
|
||||
$thirdSet->getId(),
|
||||
$firstSet->getId(),
|
||||
$secondSet->getId(),
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonCount(3, 'sets');
|
||||
$response->assertJsonPath('sets.0.id', $thirdSet->getId());
|
||||
$response->assertJsonPath('sets.1.id', $firstSet->getId());
|
||||
$response->assertJsonPath('sets.2.id', $secondSet->getId());
|
||||
|
||||
$publicResponse = $this->getJson('/api/sets');
|
||||
$publicResponse->assertOk();
|
||||
$publicResponse->assertJsonPath('sets.0.id', $thirdSet->getId());
|
||||
$publicResponse->assertJsonPath('sets.1.id', $firstSet->getId());
|
||||
$publicResponse->assertJsonPath('sets.2.id', $secondSet->getId());
|
||||
}
|
||||
|
||||
public function testCreatedSetAppendsToSavedOrder(): void
|
||||
{
|
||||
$setRepository = app(SetRepository::class);
|
||||
$firstSet = $setRepository->create(new CreateSetDto(
|
||||
name: 'First Set',
|
||||
description: 'First set description',
|
||||
iconImageUrl: '/assets/first.png',
|
||||
));
|
||||
$secondSet = $setRepository->create(new CreateSetDto(
|
||||
name: 'Second Set',
|
||||
description: 'Second set description',
|
||||
iconImageUrl: '/assets/second.png',
|
||||
));
|
||||
$this->createSession('valid-token');
|
||||
$this->withCredentials()
|
||||
->withUnencryptedCookie('auth_token', 'valid-token')
|
||||
->putJson('/api/sets/order', [
|
||||
'setIds' => [
|
||||
$secondSet->getId(),
|
||||
$firstSet->getId(),
|
||||
],
|
||||
])
|
||||
->assertOk();
|
||||
|
||||
$thirdSet = $setRepository->create(new CreateSetDto(
|
||||
name: 'Third Set',
|
||||
description: 'Third set description',
|
||||
iconImageUrl: '/assets/third.png',
|
||||
));
|
||||
|
||||
$publicResponse = $this->getJson('/api/sets');
|
||||
$publicResponse->assertOk();
|
||||
$publicResponse->assertJsonPath('sets.0.id', $secondSet->getId());
|
||||
$publicResponse->assertJsonPath('sets.1.id', $firstSet->getId());
|
||||
$publicResponse->assertJsonPath('sets.2.id', $thirdSet->getId());
|
||||
}
|
||||
|
||||
public function testCreateSetRequiresAuthentication(): void
|
||||
{
|
||||
$response = $this->postJson('/api/sets', [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue