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