]> BookStack Code Mirror - bookstack/commitdiff
add tests for priority 4313/head
authorJean-René ROUET <redacted>
Tue, 11 Jul 2023 12:11:13 +0000 (14:11 +0200)
committerJean-René ROUET <redacted>
Tue, 11 Jul 2023 12:11:13 +0000 (14:11 +0200)
dev/api/requests/chapters-create.json
dev/api/requests/chapters-update.json
dev/api/requests/pages-create.json
dev/api/requests/pages-update.json
tests/Api/ChaptersApiTest.php
tests/Api/PagesApiTest.php

index ca06fc29859bdb0b82f7b6330326535d2f7133c6..afd3c71f19577a01a5af1e0324e02dcf269d2d7e 100644 (file)
@@ -5,5 +5,7 @@
   "tags": [
     {"name": "Category", "value": "Top Content"},
     {"name": "Rating", "value": "Highest"}
-  ]
-}
\ No newline at end of file
+  ],
+  "priority": 15
+}
+}
index 6bd3a3e5c092ac8d8c95faf5ddfdb4e491e00531..f62d63d1e9cd35ef36966efea27f8deb58ed6e48 100644 (file)
@@ -5,5 +5,6 @@
   "tags": [
     {"name": "Category", "value": "Kinda Good Content"},
     {"name": "Rating", "value": "Medium"}
-  ]
-}
\ No newline at end of file
+  ],
+  "priority": 15
+}
index 1f53b42d48901a3b532fb8413f29f0931e7df0ef..5a21a80c75363696c9d14e7440d5088f624d6941 100644 (file)
@@ -5,5 +5,6 @@
        "tags": [
                {"name": "Category", "value": "Not Bad Content"},
                {"name": "Rating", "value": "Average"}
-       ]
-}
\ No newline at end of file
+       ],
+       "priority": 15
+}
index b9bfeb630decbf8d98cb8323bd0fd7f9218ddae4..fc8c73c0c395c750e4ab444afd7841c93c737fd2 100644 (file)
@@ -5,5 +5,6 @@
        "tags": [
                {"name": "Category", "value": "API Examples"},
                {"name": "Rating", "value": "Alright"}
-       ]
-}
\ No newline at end of file
+       ],
+       "priority": 15
+}
index 713d8bba4bab6156b1c5b326ec5df2cc7efe26b6..a99a85af8167b9009e01718ea086b5b92408102d 100644 (file)
@@ -61,6 +61,37 @@ class ChaptersApiTest extends TestCase
         $this->assertActivityExists('chapter_create', $newItem);
     }
 
+    public function test_create_applies_correct_priority()
+    {
+        $this->actingAsApiEditor();
+        $book = $this->entities->book();
+        $details = [
+            'name'        => 'My API chapter',
+            'description' => 'A chapter created via the API',
+            'book_id'     => $book->id,
+            'tags'        => [
+                [
+                    'name'  => 'tagname',
+                    'value' => 'tagvalue',
+                ],
+            ],
+            'priority'     => 15,
+        ];
+
+        $resp = $this->postJson($this->baseEndpoint, $details);
+        $resp->assertStatus(200);
+        $newItem = Chapter::query()->orderByDesc('id')->where('name', '=', $details['name'])->first();
+        $resp->assertJson(array_merge($details, ['id' => $newItem->id, 'slug' => $newItem->slug]));
+        $this->assertDatabaseHas('tags', [
+            'entity_id'   => $newItem->id,
+            'entity_type' => $newItem->getMorphClass(),
+            'name'        => 'tagname',
+            'value'       => 'tagvalue',
+        ]);
+        $resp->assertJsonMissing(['pages' => []]);
+        $this->assertActivityExists('chapter_create', $newItem);
+    }
+
     public function test_chapter_name_needed_to_create()
     {
         $this->actingAsApiEditor();
@@ -137,6 +168,7 @@ class ChaptersApiTest extends TestCase
                     'value' => 'freshtagval',
                 ],
             ],
+            'priority'    => 15,
         ];
 
         $resp = $this->putJson($this->baseEndpoint . "/{$chapter->id}", $details);
index 4a81f738bbdb092f12ce922331a7011600331b71..a1f65692f05822482047af88878c9d139746f0af 100644 (file)
@@ -63,6 +63,39 @@ class PagesApiTest extends TestCase
         $this->assertActivityExists('page_create', $newItem);
     }
 
+    public function test_create_applies_correct_priority()
+    {
+        $this->actingAsApiEditor();
+        $book = $this->entities->book();
+        $details = [
+            'name'    => 'My API page',
+            'book_id' => $book->id,
+            'html'    => '<p>My new page content</p>',
+            'tags'    => [
+                [
+                    'name'  => 'tagname',
+                    'value' => 'tagvalue',
+                ],
+            ],
+            'priority' => 15,
+        ];
+
+        $resp = $this->postJson($this->baseEndpoint, $details);
+        unset($details['html']);
+        $resp->assertStatus(200);
+        $newItem = Page::query()->orderByDesc('id')->where('name', '=', $details['name'])->first();
+        $resp->assertJson(array_merge($details, ['id' => $newItem->id, 'slug' => $newItem->slug]));
+        $this->assertDatabaseHas('tags', [
+            'entity_id'   => $newItem->id,
+            'entity_type' => $newItem->getMorphClass(),
+            'name'        => 'tagname',
+            'value'       => 'tagvalue',
+        ]);
+        $resp->assertSeeText('My new page content');
+        $resp->assertJsonMissing(['book' => []]);
+        $this->assertActivityExists('page_create', $newItem);
+    }
+
     public function test_page_name_needed_to_create()
     {
         $this->actingAsApiEditor();
@@ -207,6 +240,7 @@ class PagesApiTest extends TestCase
                     'value' => 'freshtagval',
                 ],
             ],
+            'priority' => 15,
         ];
 
         $resp = $this->putJson($this->baseEndpoint . "/{$page->id}", $details);