add tests for priority
This commit is contained in:
		
							parent
							
								
									4d399f6ba7
								
							
						
					
					
						commit
						3a36d3c847
					
				| 
						 | 
					@ -5,5 +5,7 @@
 | 
				
			||||||
  "tags": [
 | 
					  "tags": [
 | 
				
			||||||
    {"name": "Category", "value": "Top Content"},
 | 
					    {"name": "Category", "value": "Top Content"},
 | 
				
			||||||
    {"name": "Rating", "value": "Highest"}
 | 
					    {"name": "Rating", "value": "Highest"}
 | 
				
			||||||
  ]
 | 
					  ],
 | 
				
			||||||
 | 
					  "priority": 15
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -5,5 +5,6 @@
 | 
				
			||||||
  "tags": [
 | 
					  "tags": [
 | 
				
			||||||
    {"name": "Category", "value": "Kinda Good Content"},
 | 
					    {"name": "Category", "value": "Kinda Good Content"},
 | 
				
			||||||
    {"name": "Rating", "value": "Medium"}
 | 
					    {"name": "Rating", "value": "Medium"}
 | 
				
			||||||
  ]
 | 
					  ],
 | 
				
			||||||
 | 
					  "priority": 15
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -5,5 +5,6 @@
 | 
				
			||||||
	"tags": [
 | 
						"tags": [
 | 
				
			||||||
		{"name": "Category", "value": "Not Bad Content"},
 | 
							{"name": "Category", "value": "Not Bad Content"},
 | 
				
			||||||
		{"name": "Rating", "value": "Average"}
 | 
							{"name": "Rating", "value": "Average"}
 | 
				
			||||||
	]
 | 
						],
 | 
				
			||||||
 | 
						"priority": 15
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -5,5 +5,6 @@
 | 
				
			||||||
	"tags": [
 | 
						"tags": [
 | 
				
			||||||
		{"name": "Category", "value": "API Examples"},
 | 
							{"name": "Category", "value": "API Examples"},
 | 
				
			||||||
		{"name": "Rating", "value": "Alright"}
 | 
							{"name": "Rating", "value": "Alright"}
 | 
				
			||||||
	]
 | 
						],
 | 
				
			||||||
 | 
						"priority": 15
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -61,6 +61,37 @@ class ChaptersApiTest extends TestCase
 | 
				
			||||||
        $this->assertActivityExists('chapter_create', $newItem);
 | 
					        $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()
 | 
					    public function test_chapter_name_needed_to_create()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->actingAsApiEditor();
 | 
					        $this->actingAsApiEditor();
 | 
				
			||||||
| 
						 | 
					@ -137,6 +168,7 @@ class ChaptersApiTest extends TestCase
 | 
				
			||||||
                    'value' => 'freshtagval',
 | 
					                    'value' => 'freshtagval',
 | 
				
			||||||
                ],
 | 
					                ],
 | 
				
			||||||
            ],
 | 
					            ],
 | 
				
			||||||
 | 
					            'priority'    => 15,
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $resp = $this->putJson($this->baseEndpoint . "/{$chapter->id}", $details);
 | 
					        $resp = $this->putJson($this->baseEndpoint . "/{$chapter->id}", $details);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,6 +63,39 @@ class PagesApiTest extends TestCase
 | 
				
			||||||
        $this->assertActivityExists('page_create', $newItem);
 | 
					        $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()
 | 
					    public function test_page_name_needed_to_create()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->actingAsApiEditor();
 | 
					        $this->actingAsApiEditor();
 | 
				
			||||||
| 
						 | 
					@ -207,6 +240,7 @@ class PagesApiTest extends TestCase
 | 
				
			||||||
                    'value' => 'freshtagval',
 | 
					                    'value' => 'freshtagval',
 | 
				
			||||||
                ],
 | 
					                ],
 | 
				
			||||||
            ],
 | 
					            ],
 | 
				
			||||||
 | 
					            'priority' => 15,
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $resp = $this->putJson($this->baseEndpoint . "/{$page->id}", $details);
 | 
					        $resp = $this->putJson($this->baseEndpoint . "/{$page->id}", $details);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue