+ public function test_shelves_create_sets_cover_image()
+ {
+ $shelfInfo = [
+ 'name' => 'My test book' . Str::random(4),
+ 'description' => 'Test book description ' . Str::random(10)
+ ];
+
+ $imageFile = $this->getTestImage('shelf-test.png');
+ $resp = $this->asEditor()->call('POST', '/shelves', $shelfInfo, [], ['image' => $imageFile]);
+ $resp->assertRedirect();
+
+ $lastImage = Image::query()->orderByDesc('id')->firstOrFail();
+ $shelf = Bookshelf::query()->where('name', '=', $shelfInfo['name'])->first();
+ $this->assertDatabaseHas('bookshelves', [
+ 'id' => $shelf,
+ 'image_id' => $lastImage->id,
+ ]);
+ $this->assertEquals($lastImage->id, $shelf->cover->id);
+ }
+