require user arg in bulk node test helper
This commit is contained in:
parent
5d6c9f7ec9
commit
cebed26cde
1 changed files with 89 additions and 60 deletions
|
|
@ -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([
|
||||
'textId' => 0,
|
||||
'parentNodeId' => 0,
|
||||
'titlePrefix' => 'Page',
|
||||
'count' => 3,
|
||||
]),
|
||||
$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([
|
||||
'textId' => 0,
|
||||
'parentNodeId' => 0,
|
||||
'titlePrefix' => 'Page',
|
||||
'count' => 10,
|
||||
]),
|
||||
$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([
|
||||
'textId' => 0,
|
||||
'parentNodeId' => 0,
|
||||
'titlePrefix' => 'Chapter',
|
||||
'count' => 3,
|
||||
]),
|
||||
$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([
|
||||
'textId' => 0,
|
||||
'parentNodeId' => 0,
|
||||
'titlePrefix' => 'Page',
|
||||
'count' => 2,
|
||||
]),
|
||||
$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([
|
||||
'textId' => 0,
|
||||
'parentNodeId' => 0,
|
||||
'count' => 5,
|
||||
]),
|
||||
$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([
|
||||
'textId' => 0,
|
||||
'parentNodeId' => 0,
|
||||
'titlePrefix' => 'Page',
|
||||
'count' => 0,
|
||||
]),
|
||||
$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([
|
||||
'textId' => 0,
|
||||
'parentNodeId' => 0,
|
||||
'titlePrefix' => 'Page',
|
||||
]),
|
||||
$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([
|
||||
'textId' => 0,
|
||||
'titlePrefix' => 'Page',
|
||||
'count' => 5,
|
||||
]),
|
||||
$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([
|
||||
'textId' => 99,
|
||||
'parentNodeId' => 0,
|
||||
'titlePrefix' => 'Page',
|
||||
'count' => 5,
|
||||
]),
|
||||
$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([
|
||||
'textId' => 0,
|
||||
'parentNodeId' => 99,
|
||||
'titlePrefix' => 'Page',
|
||||
'count' => 5,
|
||||
]),
|
||||
$this->makeRequest(
|
||||
[
|
||||
'textId' => 0,
|
||||
'parentNodeId' => 99,
|
||||
'titlePrefix' => 'Page',
|
||||
'count' => 5,
|
||||
],
|
||||
$this->user,
|
||||
),
|
||||
new Response(),
|
||||
$this->useCase,
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue