Skip to content

Commit

Permalink
fix: api test after new folder rename
Browse files Browse the repository at this point in the history
  • Loading branch information
blt950 committed Aug 2, 2024
1 parent 302e7e2 commit b137b1d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion app/Http/Controllers/API/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public function index(Calendar $calendar)
->events()
->get();

// Set the full path on the image attribute
$events->transform(function ($event) {
$event->image = asset('storage/banners/' . $event->image);
return $event;
});

return response()->json(['data' => $events->values()], 200);
}

Expand Down Expand Up @@ -67,7 +73,7 @@ public function store(Request $request)
if (!Storage::disk('public')->exists($storedPath)) {
return back()->withErrors(['image' => 'Failed to upload the image.'])->withInput();
}

}

$event = Event::create([
Expand Down
6 changes: 5 additions & 1 deletion tests/Feature/Misc/APITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\Event;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Http\UploadedFile;
use Tests\TestCase;

class APITest extends TestCase
Expand Down Expand Up @@ -61,7 +62,10 @@ public function test_events_can_be_recieved_from_the_api()
$api = ApiKey::factory()->create();

// Create test event
$event = Event::factory()->create();
$image = UploadedFile::fake()->image('test_image.jpg', $width = 1600, $height = 900);
$event = Event::factory()->create([
'image' => $image,
]);

// Send a GET request to the API endpoint with the bearer token in the headers
$response = $this->withHeaders([
Expand Down

0 comments on commit b137b1d

Please sign in to comment.