require user arg in bulk node test helper

This commit is contained in:
Yisroel Baum 2026-05-02 22:22:21 +03:00
parent 5d6c9f7ec9
commit cebed26cde
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -70,26 +70,28 @@ class BulkCreateNodesControllerTest extends TestCase
private function makeRequest(
array $data,
?User $user = null,
User $user,
): ServerRequestInterface {
$body = new StreamFactory()->createStream(json_encode($data));
$request = new ServerRequestFactory()
->createServerRequest('POST', 'http://localhost/api/nodes/bulk')
->withHeader('Content-Type', 'application/json')
->withBody($body);
$sessionUser = $user ?? $this->user;
return $request->withAttribute('user', $sessionUser);
return $request->withAttribute('user', $user);
}
public function test_bulk_create_nodes_returns_201_with_created_nodes(): void
{
$response = $this->controller->bulkCreateNodes(
$this->makeRequest([
$this->makeRequest(
[
'textId' => 0,
'parentNodeId' => 0,
'titlePrefix' => 'Page',
'count' => 3,
]),
],
$this->user,
),
new Response(),
$this->useCase,
);
@ -102,12 +104,15 @@ class BulkCreateNodesControllerTest extends TestCase
public function test_bulk_create_nodes_returns_correct_count(): void
{
$response = $this->controller->bulkCreateNodes(
$this->makeRequest([
$this->makeRequest(
[
'textId' => 0,
'parentNodeId' => 0,
'titlePrefix' => 'Page',
'count' => 10,
]),
],
$this->user,
),
new Response(),
$this->useCase,
);
@ -119,12 +124,15 @@ class BulkCreateNodesControllerTest extends TestCase
public function test_bulk_create_nodes_returns_correct_titles(): void
{
$response = $this->controller->bulkCreateNodes(
$this->makeRequest([
$this->makeRequest(
[
'textId' => 0,
'parentNodeId' => 0,
'titlePrefix' => 'Chapter',
'count' => 3,
]),
],
$this->user,
),
new Response(),
$this->useCase,
);
@ -138,12 +146,15 @@ class BulkCreateNodesControllerTest extends TestCase
public function test_bulk_create_nodes_response_includes_id_and_parent_node_id(): void
{
$response = $this->controller->bulkCreateNodes(
$this->makeRequest([
$this->makeRequest(
[
'textId' => 0,
'parentNodeId' => 0,
'titlePrefix' => 'Page',
'count' => 2,
]),
],
$this->user,
),
new Response(),
$this->useCase,
);
@ -156,11 +167,14 @@ class BulkCreateNodesControllerTest extends TestCase
public function test_bulk_create_nodes_returns_400_when_title_prefix_missing(): void
{
$response = $this->controller->bulkCreateNodes(
$this->makeRequest([
$this->makeRequest(
[
'textId' => 0,
'parentNodeId' => 0,
'count' => 5,
]),
],
$this->user,
),
new Response(),
$this->useCase,
);
@ -171,12 +185,15 @@ class BulkCreateNodesControllerTest extends TestCase
public function test_bulk_create_nodes_returns_400_when_count_is_zero(): void
{
$response = $this->controller->bulkCreateNodes(
$this->makeRequest([
$this->makeRequest(
[
'textId' => 0,
'parentNodeId' => 0,
'titlePrefix' => 'Page',
'count' => 0,
]),
],
$this->user,
),
new Response(),
$this->useCase,
);
@ -187,11 +204,14 @@ class BulkCreateNodesControllerTest extends TestCase
public function test_bulk_create_nodes_returns_400_when_count_is_missing(): void
{
$response = $this->controller->bulkCreateNodes(
$this->makeRequest([
$this->makeRequest(
[
'textId' => 0,
'parentNodeId' => 0,
'titlePrefix' => 'Page',
]),
],
$this->user,
),
new Response(),
$this->useCase,
);
@ -202,11 +222,14 @@ class BulkCreateNodesControllerTest extends TestCase
public function test_bulk_create_nodes_returns_400_when_parent_node_id_missing(): void
{
$response = $this->controller->bulkCreateNodes(
$this->makeRequest([
$this->makeRequest(
[
'textId' => 0,
'titlePrefix' => 'Page',
'count' => 5,
]),
],
$this->user,
),
new Response(),
$this->useCase,
);
@ -217,12 +240,15 @@ class BulkCreateNodesControllerTest extends TestCase
public function test_bulk_create_nodes_returns_404_when_text_not_found(): void
{
$response = $this->controller->bulkCreateNodes(
$this->makeRequest([
$this->makeRequest(
[
'textId' => 99,
'parentNodeId' => 0,
'titlePrefix' => 'Page',
'count' => 5,
]),
],
$this->user,
),
new Response(),
$this->useCase,
);
@ -233,12 +259,15 @@ class BulkCreateNodesControllerTest extends TestCase
public function test_bulk_create_nodes_returns_404_when_parent_node_not_found(): void
{
$response = $this->controller->bulkCreateNodes(
$this->makeRequest([
$this->makeRequest(
[
'textId' => 0,
'parentNodeId' => 99,
'titlePrefix' => 'Page',
'count' => 5,
]),
],
$this->user,
),
new Response(),
$this->useCase,
);