Skip to content

Commit 5fe6172

Browse files
committed
testing profile controller
1 parent 173a293 commit 5fe6172

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

tests/Feature/ProfileTest.php.php

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
3+
4+
use Tests\TestCase;
5+
use App\Models\User;
6+
use App\Models\UserProfile;
7+
use Illuminate\Foundation\Testing\RefreshDatabase;
8+
9+
class ProfileControllerTest extends TestCase
10+
{
11+
use RefreshDatabase;
12+
13+
public function testUpdateProfile()
14+
{
15+
16+
$user = User::factory()->create();
17+
$userData = [
18+
'name' => 'John Doe',
19+
'track' => 'IT',
20+
'bio' => 'Lorem ipsum dolor sit amet.',
21+
];
22+
23+
24+
$response = $this->actingAs($user)
25+
->put('/api/individuals/profile/'.$user->id, $userData); // افتراضيًا يتم استدعاء الوظيفة updateProfile()
26+
27+
28+
$response->assertStatus(200);
29+
$response->assertJson([
30+
'result' => true,
31+
'message' => 'Profile updated successfully',
32+
'data' => [
33+
'user' => [
34+
'id' => $user->id,
35+
'name' => $userData['name'],
36+
'email' => $user->email,
37+
'imageUrl' => $user->imageUrl,
38+
'track' => $userData['track'],
39+
'bio' => $userData['bio'],
40+
],
41+
],
42+
]);
43+
44+
45+
$this->assertDatabaseHas('users', [
46+
'id' => $user->id,
47+
'name' => $userData['name'],
48+
'track' => $userData['track'],
49+
'bio' => $userData['bio'],
50+
]);
51+
}
52+
53+
public function testUpdatePersonalInfo()
54+
{
55+
56+
$user = User::factory()->create();
57+
$userProfile = UserProfile::factory()->create(['user_id' => $user->id]);
58+
$profileData = [
59+
'governate' => 'Cairo',
60+
'university' => 'Cairo University',
61+
'faculty' => 'Computer Science',
62+
'birthDate' => '1990-01-01',
63+
'emailProfile' => '[email protected]',
64+
'phoneNumber' => '123456789',
65+
'projects' => 'Project 1, Project 2',
66+
'progLanguages' => 'PHP, JavaScript',
67+
'cvUrl' => 'http://example.com/cv',
68+
'githubUrl' => 'http://github.com/username',
69+
'linkedinUrl' => 'http://linkedin.com/username',
70+
'behanceUrl' => 'http://behance.com/username',
71+
'twitterUrl' => 'http://twitter.com/username',
72+
'facebookUrl' => 'http://facebook.com/username',
73+
];
74+
75+
76+
$response = $this->actingAs($user)
77+
->put('/api/individuals/profile/personal-info/'.$user->id, $profileData); // افتراضيًا يتم استدعاء الوظيفة updatePersonalInfo()
78+
79+
80+
$response->assertStatus(200);
81+
$response->assertJson([
82+
'result' => true,
83+
'message' => 'Pesonal information updated successfully',
84+
'data' => [
85+
'user' => [
86+
'id' => $userProfile->id,
87+
'governate' => $profileData['governate'],
88+
'university' => $profileData['university'],
89+
'faculty' => $profileData['faculty'],
90+
'birthDate' => $profileData['birthDate'],
91+
'emailProfile' => $profileData['emailProfile'],
92+
'phoneNumber' => $profileData['phoneNumber'],
93+
'projects' => $profileData['projects'],
94+
'progLanguages' => $profileData['progLanguages'],
95+
'cvUrl' => $profileData['cvUrl'],
96+
'githubUrl' => $profileData['githubUrl'],
97+
'linkedinUrl' => $profileData['linkedinUrl'],
98+
'behanceUrl' => $profileData['behanceUrl'],
99+
'twitterUrl' => $profileData['twitterUrl'],
100+
'facebookUrl' => $profileData['facebookUrl'],
101+
],
102+
],
103+
]);
104+
105+
106+
$this->assertDatabaseHas('user_profiles', [
107+
'id' => $userProfile->id,
108+
'governate' => $profileData['governate'],
109+
'university' => $profileData['university'],
110+
'faculty' => $profileData['faculty'],
111+
'birth_date' => $profileData['birthDate'],
112+
'email_profile' => $profileData['emailProfile'],
113+
'phone_number' => $profileData['phoneNumber'],
114+
'projects' => $profileData['projects'],
115+
'prog_languages' => $profileData['progLanguages'],
116+
'cv_url' => $profileData['cvUrl'],
117+
'github_url' => $profileData['githubUrl'],
118+
'linkedin_url' => $profileData['linkedinUrl'],
119+
'behance_url' => $profileData['behanceUrl'],
120+
'twitter_url' => $profileData['twitterUrl'],
121+
'facebook_url' => $profileData['facebookUrl'],
122+
]);
123+
}
124+
}

0 commit comments

Comments
 (0)