use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
-use Tests\Uploads\UsesImages;
class BooksApiTest extends TestCase
{
use TestsApi;
- use UsesImages;
protected string $baseEndpoint = '/api/books';
public function test_create_endpoint()
{
$this->actingAsApiEditor();
+ $templatePage = $this->entities->templatePage();
$details = [
'name' => 'My API book',
'description' => 'A book created via the API',
+ 'default_template_id' => $templatePage->id,
];
$resp = $this->postJson($this->baseEndpoint, $details);
$resp->assertStatus(200);
+
$newItem = Book::query()->orderByDesc('id')->where('name', '=', $details['name'])->first();
$resp->assertJson(array_merge($details, ['id' => $newItem->id, 'slug' => $newItem->slug]));
$this->assertActivityExists('book_create', $newItem);
'owned_by' => [
'name' => $book->ownedBy->name,
],
+ 'default_template_id' => null,
]);
}
{
$this->actingAsApiEditor();
$book = $this->entities->book();
+ $templatePage = $this->entities->templatePage();
$details = [
'name' => 'My updated API book',
'description' => 'A book created via the API',
+ 'default_template_id' => $templatePage->id,
];
$resp = $this->putJson($this->baseEndpoint . "/{$book->id}", $details);
/** @var Book $book */
$book = $this->entities->book();
$this->assertNull($book->cover);
- $file = $this->getTestImage('image.png');
+ $file = $this->files->uploadedImage('image.png');
// Ensure cover image can be set via API
$resp = $this->call('PUT', $this->baseEndpoint . "/{$book->id}", [