Skip to content

Commit

Permalink
fix: profile image upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AdelakunShola committed Aug 6, 2024
1 parent f20ecae commit 2851fb2
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions tests/Feature/ProfileUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,27 @@ public function it_can_update_profile()
/** @test */
public function it_can_upload_image()
{
// Mocking Cloudinary API response
Http::fake([
'https://api.cloudinary.com/v1_1/*' => Http::response([
'secure_url' => 'https://example.com/new-avatar.png'
], 200)
]);


$file = UploadedFile::fake()->image('avatar.jpg');

$response = $this->post('/api/v1/profile/upload-image', [
'file' => $file
]);

$response->assertStatus(200);
$response->assertJsonStructure(['Status', 'Message', 'Data' => ['avatar_url']]);

$response->assertJsonStructure([
'Status',
'Message',
'Data' => ['avatar_url']
]);

$uploadedFileUrl = $response->json('Data.avatar_url');

$this->assertFileExists(public_path('uploads/' . basename($uploadedFileUrl)));

$this->assertStringStartsWith(url('uploads/'), $uploadedFileUrl);
}


}

0 comments on commit 2851fb2

Please sign in to comment.