Compare commits
No commits in common. "fdffb69b5ee538668145103e89db0d3c54b7f6dd" and "25510d1b5e7ab2744455a20890fb5ee36b8a1799" have entirely different histories.
fdffb69b5e
...
25510d1b5e
@ -10,90 +10,13 @@
|
|||||||
|
|
||||||
class EmployerAnnouncementController extends Controller
|
class EmployerAnnouncementController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Get all approved announcements for employers.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
|
||||||
public function getAnnouncements(Request $request)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$page = (int)$request->input('page', 1);
|
|
||||||
$perPage = (int)$request->input('per_page', 15);
|
|
||||||
|
|
||||||
$query = Announcement::with(['employer.employerProfile', 'sponsor'])->where('status', 'approved')->latest();
|
|
||||||
$total = $query->count();
|
|
||||||
$offset = ($page - 1) * $perPage;
|
|
||||||
|
|
||||||
$announcements = $query->skip($offset)->take($perPage)->get()
|
|
||||||
->map(function ($announcement) {
|
|
||||||
$postedBy = 'System';
|
|
||||||
$organization = 'Migrant Support';
|
|
||||||
|
|
||||||
if ($announcement->sponsor_id) {
|
|
||||||
$postedBy = $announcement->sponsor->full_name;
|
|
||||||
$organization = $announcement->sponsor->organization_name;
|
|
||||||
} elseif ($announcement->employer_id) {
|
|
||||||
$postedBy = $announcement->employer->name;
|
|
||||||
$organization = $announcement->employer->employerProfile->company_name ?? 'Employer';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode charity details if they exist in json
|
|
||||||
$charityDetails = null;
|
|
||||||
$content = $announcement->body;
|
|
||||||
if (strpos($announcement->body, '{"type":"Charity"') === 0) {
|
|
||||||
$decoded = json_decode($announcement->body, true);
|
|
||||||
if ($decoded) {
|
|
||||||
$charityDetails = $decoded;
|
|
||||||
$content = $decoded['content'] ?? $announcement->body;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'id' => $announcement->id,
|
|
||||||
'title' => $announcement->title,
|
|
||||||
'body' => $content,
|
|
||||||
'type' => $announcement->type,
|
|
||||||
'employer_name' => $postedBy,
|
|
||||||
'company_name' => $organization,
|
|
||||||
'created_at' => $announcement->created_at->toISOString(),
|
|
||||||
'time_ago' => $announcement->created_at->diffForHumans(),
|
|
||||||
'charity_details' => $charityDetails,
|
|
||||||
];
|
|
||||||
});
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'success' => true,
|
|
||||||
'data' => [
|
|
||||||
'announcements' => $announcements,
|
|
||||||
'pagination' => [
|
|
||||||
'total' => $total,
|
|
||||||
'per_page' => $perPage,
|
|
||||||
'current_page' => $page,
|
|
||||||
'last_page' => max(1, (int)ceil($total / $perPage)),
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], 200);
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
logger()->error('Mobile Employer Get All Announcements Failure: ' . $e->getMessage());
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'An error occurred while fetching announcements.',
|
|
||||||
'error' => app()->environment('local') ? $e->getMessage() : 'Internal Server Error'
|
|
||||||
], 500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all announcements posted by this employer.
|
* Get all announcements posted by this employer.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\Http\JsonResponse
|
* @return \Illuminate\Http\JsonResponse
|
||||||
*/
|
*/
|
||||||
public function getMyAnnouncements(Request $request)
|
public function getAnnouncements(Request $request)
|
||||||
{
|
{
|
||||||
/** @var User $employer */
|
/** @var User $employer */
|
||||||
$employer = $request->attributes->get('employer');
|
$employer = $request->attributes->get('employer');
|
||||||
@ -134,7 +57,7 @@ public function getMyAnnouncements(Request $request)
|
|||||||
], 200);
|
], 200);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
logger()->error('Mobile Employer Get My Announcements Failure: ' . $e->getMessage());
|
logger()->error('Mobile Employer Get Announcements Failure: ' . $e->getMessage());
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
|
|||||||
@ -396,70 +396,4 @@ public function getDashboard(Request $request)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Change employer's password.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
|
||||||
public function changePassword(Request $request)
|
|
||||||
{
|
|
||||||
/** @var User $employer */
|
|
||||||
$employer = $request->attributes->get('employer');
|
|
||||||
|
|
||||||
$validator = Validator::make($request->all(), [
|
|
||||||
'current_password' => 'required|string',
|
|
||||||
'new_password' => 'required|string|min:8|confirmed',
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($validator->fails()) {
|
|
||||||
return response()->json([
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'Validation error.',
|
|
||||||
'errors' => $validator->errors()
|
|
||||||
], 422);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Hash::check($request->current_password, $employer->password)) {
|
|
||||||
return response()->json([
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'Validation error.',
|
|
||||||
'errors' => [
|
|
||||||
'current_password' => ['The current password is incorrect.']
|
|
||||||
]
|
|
||||||
], 422);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$hashedPassword = Hash::make($request->new_password);
|
|
||||||
|
|
||||||
// Update user table
|
|
||||||
$employer->update([
|
|
||||||
'password' => $hashedPassword
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Sync with corresponding sponsor record if found
|
|
||||||
$matchingSponsor = \App\Models\Sponsor::where('email', $employer->email)->first();
|
|
||||||
if ($matchingSponsor) {
|
|
||||||
$matchingSponsor->update([
|
|
||||||
'password' => $hashedPassword
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'success' => true,
|
|
||||||
'message' => 'Password changed successfully.'
|
|
||||||
], 200);
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
logger()->error('Mobile Employer Change Password Failure: ' . $e->getMessage());
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'An error occurred while changing password.',
|
|
||||||
'error' => app()->environment('local') ? $e->getMessage() : 'Internal Server Error'
|
|
||||||
], 500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -326,72 +326,4 @@ public function getProfile(Request $request)
|
|||||||
]
|
]
|
||||||
], 200);
|
], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Change sponsor's password.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
|
||||||
public function changePassword(Request $request)
|
|
||||||
{
|
|
||||||
/** @var Sponsor $sponsor */
|
|
||||||
$sponsor = $request->attributes->get('sponsor');
|
|
||||||
|
|
||||||
$validator = \Illuminate\Support\Facades\Validator::make($request->all(), [
|
|
||||||
'current_password' => 'required|string',
|
|
||||||
'new_password' => 'required|string|min:8|confirmed',
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($validator->fails()) {
|
|
||||||
return response()->json([
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'Validation error.',
|
|
||||||
'errors' => $validator->errors()
|
|
||||||
], 422);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!\Illuminate\Support\Facades\Hash::check($request->current_password, $sponsor->password)) {
|
|
||||||
return response()->json([
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'Validation error.',
|
|
||||||
'errors' => [
|
|
||||||
'current_password' => ['The current password is incorrect.']
|
|
||||||
]
|
|
||||||
], 422);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$hashedPassword = \Illuminate\Support\Facades\Hash::make($request->new_password);
|
|
||||||
|
|
||||||
// Update sponsor table
|
|
||||||
$sponsor->update([
|
|
||||||
'password' => $hashedPassword
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Sync with corresponding employer user record if found
|
|
||||||
$matchingEmployer = \App\Models\User::where('email', $sponsor->email)
|
|
||||||
->where('role', 'employer')
|
|
||||||
->first();
|
|
||||||
if ($matchingEmployer) {
|
|
||||||
$matchingEmployer->update([
|
|
||||||
'password' => $hashedPassword
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'success' => true,
|
|
||||||
'message' => 'Password changed successfully.'
|
|
||||||
], 200);
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
logger()->error('Mobile Sponsor Change Password Failure: ' . $e->getMessage());
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'An error occurred while changing password.',
|
|
||||||
'error' => app()->environment('local') ? $e->getMessage() : 'Internal Server Error'
|
|
||||||
], 500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -669,61 +669,6 @@ public function getDashboard(Request $request)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Change worker's password.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
|
||||||
public function changePassword(Request $request)
|
|
||||||
{
|
|
||||||
/** @var Worker $worker */
|
|
||||||
$worker = $request->attributes->get('worker');
|
|
||||||
|
|
||||||
$validator = Validator::make($request->all(), [
|
|
||||||
'current_password' => 'required|string',
|
|
||||||
'new_password' => 'required|string|min:8|confirmed',
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($validator->fails()) {
|
|
||||||
return response()->json([
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'Validation error.',
|
|
||||||
'errors' => $validator->errors()
|
|
||||||
], 422);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!\Illuminate\Support\Facades\Hash::check($request->current_password, $worker->password)) {
|
|
||||||
return response()->json([
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'Validation error.',
|
|
||||||
'errors' => [
|
|
||||||
'current_password' => ['The current password is incorrect.']
|
|
||||||
]
|
|
||||||
], 422);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$worker->update([
|
|
||||||
'password' => \Illuminate\Support\Facades\Hash::make($request->new_password)
|
|
||||||
]);
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'success' => true,
|
|
||||||
'message' => 'Password changed successfully.'
|
|
||||||
], 200);
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
logger()->error('Mobile Worker Change Password Failure: ' . $e->getMessage());
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'An error occurred while changing password.',
|
|
||||||
'error' => app()->environment('local') ? $e->getMessage() : 'Internal Server Error'
|
|
||||||
], 500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* E.g. "14/05/1990" -> "1990-05-14"
|
* E.g. "14/05/1990" -> "1990-05-14"
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -3527,91 +3527,7 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "List of posted charity events retrieved successfully.",
|
"description": "List of posted charity events retrieved successfully."
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"success": {
|
|
||||||
"type": "boolean",
|
|
||||||
"example": true
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"announcements": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"id": {
|
|
||||||
"type": "integer",
|
|
||||||
"example": 1
|
|
||||||
},
|
|
||||||
"title": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "Holiday Notice"
|
|
||||||
},
|
|
||||||
"body": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "Office will be closed tomorrow."
|
|
||||||
},
|
|
||||||
"type": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "info"
|
|
||||||
},
|
|
||||||
"employer_name": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "Employer One"
|
|
||||||
},
|
|
||||||
"company_name": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "Elite Services"
|
|
||||||
},
|
|
||||||
"created_at": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "date-time",
|
|
||||||
"example": "2026-06-23T10:13:17.000000Z"
|
|
||||||
},
|
|
||||||
"time_ago": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "2 hours ago"
|
|
||||||
},
|
|
||||||
"charity_details": {
|
|
||||||
"type": "object",
|
|
||||||
"nullable": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"pagination": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"total": {
|
|
||||||
"type": "integer",
|
|
||||||
"example": 1
|
|
||||||
},
|
|
||||||
"per_page": {
|
|
||||||
"type": "integer",
|
|
||||||
"example": 15
|
|
||||||
},
|
|
||||||
"current_page": {
|
|
||||||
"type": "integer",
|
|
||||||
"example": 1
|
|
||||||
},
|
|
||||||
"last_page": {
|
|
||||||
"type": "integer",
|
|
||||||
"example": 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -3712,85 +3628,7 @@
|
|||||||
"description": "Retrieves stats including contacted workers count, total hired workers, saved candidates, current plan details, and recent announcements or events.",
|
"description": "Retrieves stats including contacted workers count, total hired workers, saved candidates, current plan details, and recent announcements or events.",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Employer dashboard stats retrieved successfully.",
|
"description": "Employer dashboard stats retrieved successfully."
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"success": {
|
|
||||||
"type": "boolean",
|
|
||||||
"example": true
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"stats": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"contacted_workers_count": {
|
|
||||||
"type": "integer",
|
|
||||||
"example": 0
|
|
||||||
},
|
|
||||||
"total_hired_workers": {
|
|
||||||
"type": "integer",
|
|
||||||
"example": 0
|
|
||||||
},
|
|
||||||
"saved_candidates": {
|
|
||||||
"type": "integer",
|
|
||||||
"example": 0
|
|
||||||
},
|
|
||||||
"total_workers": {
|
|
||||||
"type": "integer",
|
|
||||||
"example": 15
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"current_plan": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"plan_id": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "premium"
|
|
||||||
},
|
|
||||||
"name": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "Premium Pass"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "active"
|
|
||||||
},
|
|
||||||
"starts_at": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "date",
|
|
||||||
"example": "2026-06-23"
|
|
||||||
},
|
|
||||||
"expires_at": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "date",
|
|
||||||
"example": "2026-07-23"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"recent_announcements": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "object"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"recent_events": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "object"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5677,422 +5515,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"/employers/my-announcements": {
|
|
||||||
"get": {
|
|
||||||
"tags": [
|
|
||||||
"Employer/CharityEvents"
|
|
||||||
],
|
|
||||||
"summary": "Get My Posted Announcements/Charity Events (Employer)",
|
|
||||||
"description": "Retrieves the list of announcements and charity events posted specifically by the logged-in employer.",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "page",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"description": "Page number.",
|
|
||||||
"schema": {
|
|
||||||
"type": "integer",
|
|
||||||
"default": 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "per_page",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"description": "Number of items per page.",
|
|
||||||
"schema": {
|
|
||||||
"type": "integer",
|
|
||||||
"default": 15
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "List of my posted announcements retrieved successfully.",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"success": {
|
|
||||||
"type": "boolean",
|
|
||||||
"example": true
|
|
||||||
},
|
|
||||||
"data": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"announcements": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"id": {
|
|
||||||
"type": "integer",
|
|
||||||
"example": 1
|
|
||||||
},
|
|
||||||
"title": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "Holiday Notice"
|
|
||||||
},
|
|
||||||
"body": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "Office will be closed tomorrow."
|
|
||||||
},
|
|
||||||
"type": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "info"
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "pending"
|
|
||||||
},
|
|
||||||
"remarks": {
|
|
||||||
"type": "string",
|
|
||||||
"nullable": true
|
|
||||||
},
|
|
||||||
"created_at": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "date-time",
|
|
||||||
"example": "2026-06-23T10:13:17.000000Z"
|
|
||||||
},
|
|
||||||
"time_ago": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "2 hours ago"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"pagination": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"total": {
|
|
||||||
"type": "integer",
|
|
||||||
"example": 1
|
|
||||||
},
|
|
||||||
"per_page": {
|
|
||||||
"type": "integer",
|
|
||||||
"example": 15
|
|
||||||
},
|
|
||||||
"current_page": {
|
|
||||||
"type": "integer",
|
|
||||||
"example": 1
|
|
||||||
},
|
|
||||||
"last_page": {
|
|
||||||
"type": "integer",
|
|
||||||
"example": 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/workers/change-password": {
|
|
||||||
"post": {
|
|
||||||
"tags": [
|
|
||||||
"Worker/Profile"
|
|
||||||
],
|
|
||||||
"summary": "Change Password",
|
|
||||||
"description": "Securely changes the user's password by validating the current password and confirming the new password.",
|
|
||||||
"requestBody": {
|
|
||||||
"required": true,
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"current_password",
|
|
||||||
"new_password",
|
|
||||||
"new_password_confirmation"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"current_password": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "password",
|
|
||||||
"description": "The current login password. (REQUIRED)",
|
|
||||||
"example": "OldPassword@123"
|
|
||||||
},
|
|
||||||
"new_password": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "password",
|
|
||||||
"description": "The new secure password (minimum 8 characters). (REQUIRED)",
|
|
||||||
"example": "NewPassword@123"
|
|
||||||
},
|
|
||||||
"new_password_confirmation": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "password",
|
|
||||||
"description": "Confirmation of the new password. (REQUIRED)",
|
|
||||||
"example": "NewPassword@123"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "Password changed successfully.",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"success": {
|
|
||||||
"type": "boolean",
|
|
||||||
"example": true
|
|
||||||
},
|
|
||||||
"message": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "Password changed successfully."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"422": {
|
|
||||||
"description": "Validation error (e.g. invalid current password, password too short, or mismatch).",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"success": {
|
|
||||||
"type": "boolean",
|
|
||||||
"example": false
|
|
||||||
},
|
|
||||||
"message": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "Validation error."
|
|
||||||
},
|
|
||||||
"errors": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"current_password": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"example": [
|
|
||||||
"The current password is incorrect."
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/employers/change-password": {
|
|
||||||
"post": {
|
|
||||||
"tags": [
|
|
||||||
"Employer/Profile"
|
|
||||||
],
|
|
||||||
"summary": "Change Password",
|
|
||||||
"description": "Securely changes the user's password by validating the current password and confirming the new password.",
|
|
||||||
"requestBody": {
|
|
||||||
"required": true,
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"current_password",
|
|
||||||
"new_password",
|
|
||||||
"new_password_confirmation"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"current_password": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "password",
|
|
||||||
"description": "The current login password. (REQUIRED)",
|
|
||||||
"example": "OldPassword@123"
|
|
||||||
},
|
|
||||||
"new_password": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "password",
|
|
||||||
"description": "The new secure password (minimum 8 characters). (REQUIRED)",
|
|
||||||
"example": "NewPassword@123"
|
|
||||||
},
|
|
||||||
"new_password_confirmation": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "password",
|
|
||||||
"description": "Confirmation of the new password. (REQUIRED)",
|
|
||||||
"example": "NewPassword@123"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "Password changed successfully.",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"success": {
|
|
||||||
"type": "boolean",
|
|
||||||
"example": true
|
|
||||||
},
|
|
||||||
"message": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "Password changed successfully."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"422": {
|
|
||||||
"description": "Validation error (e.g. invalid current password, password too short, or mismatch).",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"success": {
|
|
||||||
"type": "boolean",
|
|
||||||
"example": false
|
|
||||||
},
|
|
||||||
"message": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "Validation error."
|
|
||||||
},
|
|
||||||
"errors": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"current_password": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"example": [
|
|
||||||
"The current password is incorrect."
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/sponsors/change-password": {
|
|
||||||
"post": {
|
|
||||||
"tags": [
|
|
||||||
"Sponsor"
|
|
||||||
],
|
|
||||||
"summary": "Change Password",
|
|
||||||
"description": "Securely changes the user's password by validating the current password and confirming the new password.",
|
|
||||||
"requestBody": {
|
|
||||||
"required": true,
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"current_password",
|
|
||||||
"new_password",
|
|
||||||
"new_password_confirmation"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"current_password": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "password",
|
|
||||||
"description": "The current login password. (REQUIRED)",
|
|
||||||
"example": "OldPassword@123"
|
|
||||||
},
|
|
||||||
"new_password": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "password",
|
|
||||||
"description": "The new secure password (minimum 8 characters). (REQUIRED)",
|
|
||||||
"example": "NewPassword@123"
|
|
||||||
},
|
|
||||||
"new_password_confirmation": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "password",
|
|
||||||
"description": "Confirmation of the new password. (REQUIRED)",
|
|
||||||
"example": "NewPassword@123"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "Password changed successfully.",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"success": {
|
|
||||||
"type": "boolean",
|
|
||||||
"example": true
|
|
||||||
},
|
|
||||||
"message": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "Password changed successfully."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"422": {
|
|
||||||
"description": "Validation error (e.g. invalid current password, password too short, or mismatch).",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"success": {
|
|
||||||
"type": "boolean",
|
|
||||||
"example": false
|
|
||||||
},
|
|
||||||
"message": {
|
|
||||||
"type": "string",
|
|
||||||
"example": "Validation error."
|
|
||||||
},
|
|
||||||
"errors": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"current_password": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"example": [
|
|
||||||
"The current password is incorrect."
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
|
|||||||
@ -75,7 +75,6 @@
|
|||||||
Route::post('/workers/profile/mark-hired', [WorkerProfileController::class, 'markHired']);
|
Route::post('/workers/profile/mark-hired', [WorkerProfileController::class, 'markHired']);
|
||||||
Route::get('/workers/dashboard/views', [WorkerProfileController::class, 'getProfileViews']);
|
Route::get('/workers/dashboard/views', [WorkerProfileController::class, 'getProfileViews']);
|
||||||
Route::get('/workers/dashboard', [WorkerProfileController::class, 'getDashboard']);
|
Route::get('/workers/dashboard', [WorkerProfileController::class, 'getDashboard']);
|
||||||
Route::post('/workers/change-password', [WorkerProfileController::class, 'changePassword']);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -111,7 +110,6 @@
|
|||||||
Route::get('/employers/profile', [EmployerProfileController::class, 'getProfile']);
|
Route::get('/employers/profile', [EmployerProfileController::class, 'getProfile']);
|
||||||
Route::post('/employers/profile/update', [EmployerProfileController::class, 'updateProfile']);
|
Route::post('/employers/profile/update', [EmployerProfileController::class, 'updateProfile']);
|
||||||
Route::get('/employers/dashboard', [EmployerProfileController::class, 'getDashboard']);
|
Route::get('/employers/dashboard', [EmployerProfileController::class, 'getDashboard']);
|
||||||
Route::post('/employers/change-password', [EmployerProfileController::class, 'changePassword']);
|
|
||||||
|
|
||||||
// Messaging Management
|
// Messaging Management
|
||||||
Route::get('/employers/conversations', [EmployerMessageController::class, 'getConversations']);
|
Route::get('/employers/conversations', [EmployerMessageController::class, 'getConversations']);
|
||||||
@ -121,7 +119,6 @@
|
|||||||
|
|
||||||
// Announcement Management
|
// Announcement Management
|
||||||
Route::get('/employers/announcements', [EmployerAnnouncementController::class, 'getAnnouncements']);
|
Route::get('/employers/announcements', [EmployerAnnouncementController::class, 'getAnnouncements']);
|
||||||
Route::get('/employers/my-announcements', [EmployerAnnouncementController::class, 'getMyAnnouncements']);
|
|
||||||
Route::post('/employers/announcements', [EmployerAnnouncementController::class, 'createAnnouncement']);
|
Route::post('/employers/announcements', [EmployerAnnouncementController::class, 'createAnnouncement']);
|
||||||
Route::delete('/employers/announcements/{id}', [EmployerAnnouncementController::class, 'deleteAnnouncement']);
|
Route::delete('/employers/announcements/{id}', [EmployerAnnouncementController::class, 'deleteAnnouncement']);
|
||||||
|
|
||||||
@ -162,5 +159,4 @@
|
|||||||
Route::get('/sponsors/dashboard', [SponsorController::class, 'getDashboard']);
|
Route::get('/sponsors/dashboard', [SponsorController::class, 'getDashboard']);
|
||||||
Route::get('/sponsors/charity-events', [SponsorController::class, 'getCharityEvents']);
|
Route::get('/sponsors/charity-events', [SponsorController::class, 'getCharityEvents']);
|
||||||
Route::post('/sponsors/charity-events', [SponsorController::class, 'postCharityEvent']);
|
Route::post('/sponsors/charity-events', [SponsorController::class, 'postCharityEvent']);
|
||||||
Route::post('/sponsors/change-password', [SponsorController::class, 'changePassword']);
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -103,9 +103,9 @@ public function test_worker_can_get_announcements()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test employer can get only their posted announcements via my-announcements.
|
* Test employer can get only their posted announcements.
|
||||||
*/
|
*/
|
||||||
public function test_employer_can_get_my_announcements()
|
public function test_employer_can_get_posted_announcements()
|
||||||
{
|
{
|
||||||
// Announcement by this employer
|
// Announcement by this employer
|
||||||
Announcement::create([
|
Announcement::create([
|
||||||
@ -131,66 +131,13 @@ public function test_employer_can_get_my_announcements()
|
|||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'Authorization' => 'Bearer ' . $this->employerToken,
|
'Authorization' => 'Bearer ' . $this->employerToken,
|
||||||
])->getJson('/api/employers/my-announcements');
|
])->getJson('/api/employers/announcements');
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
$this->assertCount(1, $response->json('data.announcements'));
|
$this->assertCount(1, $response->json('data.announcements'));
|
||||||
$this->assertEquals('Employer Ann', $response->json('data.announcements.0.title'));
|
$this->assertEquals('Employer Ann', $response->json('data.announcements.0.title'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test employer can get all approved announcements.
|
|
||||||
*/
|
|
||||||
public function test_employer_can_get_all_approved_announcements()
|
|
||||||
{
|
|
||||||
// Approved announcement by this employer
|
|
||||||
Announcement::create([
|
|
||||||
'title' => 'Approved Ann 1',
|
|
||||||
'body' => 'Message 1',
|
|
||||||
'type' => 'info',
|
|
||||||
'employer_id' => $this->employer->id,
|
|
||||||
'status' => 'approved',
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Pending announcement by this employer
|
|
||||||
Announcement::create([
|
|
||||||
'title' => 'Pending Ann 1',
|
|
||||||
'body' => 'Message 2',
|
|
||||||
'type' => 'info',
|
|
||||||
'employer_id' => $this->employer->id,
|
|
||||||
'status' => 'pending',
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Approved announcement by another sponsor
|
|
||||||
$sponsor = \App\Models\Sponsor::create([
|
|
||||||
'full_name' => 'Sponsor Name',
|
|
||||||
'email' => 'sponsor@example.com',
|
|
||||||
'mobile' => '+971501112233',
|
|
||||||
'organization_name' => 'Charity Org',
|
|
||||||
'address' => 'Dubai',
|
|
||||||
'role' => 'sponsor',
|
|
||||||
'password' => bcrypt('password'),
|
|
||||||
]);
|
|
||||||
Announcement::create([
|
|
||||||
'title' => 'Approved Ann 2',
|
|
||||||
'body' => 'Message 3',
|
|
||||||
'type' => 'info',
|
|
||||||
'sponsor_id' => $sponsor->id,
|
|
||||||
'status' => 'approved',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
|
||||||
'Authorization' => 'Bearer ' . $this->employerToken,
|
|
||||||
])->getJson('/api/employers/announcements');
|
|
||||||
|
|
||||||
$response->assertStatus(200);
|
|
||||||
$this->assertCount(2, $response->json('data.announcements'));
|
|
||||||
$titles = collect($response->json('data.announcements'))->pluck('title');
|
|
||||||
$this->assertTrue($titles->contains('Approved Ann 1'));
|
|
||||||
$this->assertTrue($titles->contains('Approved Ann 2'));
|
|
||||||
$this->assertFalse($titles->contains('Pending Ann 1'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test employer can create a new announcement.
|
* Test employer can create a new announcement.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -288,57 +288,4 @@ public function test_employer_dashboard_returns_total_workers_active()
|
|||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
$this->assertEquals(3, $response->json('data.stats.total_workers'));
|
$this->assertEquals(3, $response->json('data.stats.total_workers'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test employer can change password successfully.
|
|
||||||
*/
|
|
||||||
public function test_employer_can_change_password()
|
|
||||||
{
|
|
||||||
// 1. Create a matching sponsor
|
|
||||||
$sponsor = \App\Models\Sponsor::create([
|
|
||||||
'full_name' => 'Employer One',
|
|
||||||
'email' => $this->employer->email,
|
|
||||||
'mobile' => '+971509990011',
|
|
||||||
'organization_name' => 'Elite Services',
|
|
||||||
'address' => 'Dubai',
|
|
||||||
'role' => 'sponsor',
|
|
||||||
'password' => bcrypt('Password@123'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Verify initial password hash is set
|
|
||||||
$this->employer->update([
|
|
||||||
'password' => bcrypt('Password@123')
|
|
||||||
]);
|
|
||||||
|
|
||||||
// 2. Try with wrong current password
|
|
||||||
$response = $this->withHeaders([
|
|
||||||
'Authorization' => 'Bearer ' . $this->token,
|
|
||||||
])->postJson('/api/employers/change-password', [
|
|
||||||
'current_password' => 'WrongPassword',
|
|
||||||
'new_password' => 'NewPassword@123',
|
|
||||||
'new_password_confirmation' => 'NewPassword@123',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertStatus(422)
|
|
||||||
->assertJsonValidationErrors(['current_password']);
|
|
||||||
|
|
||||||
// 3. Try with correct current password
|
|
||||||
$response = $this->withHeaders([
|
|
||||||
'Authorization' => 'Bearer ' . $this->token,
|
|
||||||
])->postJson('/api/employers/change-password', [
|
|
||||||
'current_password' => 'Password@123',
|
|
||||||
'new_password' => 'NewPassword@123',
|
|
||||||
'new_password_confirmation' => 'NewPassword@123',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertStatus(200)
|
|
||||||
->assertJson([
|
|
||||||
'success' => true,
|
|
||||||
'message' => 'Password changed successfully.'
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Verify password is updated for both User and Sponsor
|
|
||||||
$this->assertTrue(\Illuminate\Support\Facades\Hash::check('NewPassword@123', $this->employer->fresh()->password));
|
|
||||||
$this->assertTrue(\Illuminate\Support\Facades\Hash::check('NewPassword@123', $sponsor->fresh()->password));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -603,58 +603,4 @@ public function test_sponsor_forgot_password_user_not_found()
|
|||||||
'message' => 'user not found this email id',
|
'message' => 'user not found this email id',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test sponsor can change password successfully.
|
|
||||||
*/
|
|
||||||
public function test_sponsor_can_change_password()
|
|
||||||
{
|
|
||||||
$sponsor = Sponsor::create([
|
|
||||||
'full_name' => 'Sponsor Changer',
|
|
||||||
'email' => 'changer.sponsor@example.com',
|
|
||||||
'mobile' => '+971509997788',
|
|
||||||
'password' => Hash::make('Password@123'),
|
|
||||||
'api_token' => 'sponsor-changer-token',
|
|
||||||
'status' => 'active',
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Sync with corresponding employer user record to test sync
|
|
||||||
$user = User::create([
|
|
||||||
'name' => 'Sponsor Changer',
|
|
||||||
'email' => 'changer.sponsor@example.com',
|
|
||||||
'password' => Hash::make('Password@123'),
|
|
||||||
'role' => 'employer',
|
|
||||||
]);
|
|
||||||
|
|
||||||
// 1. Try with wrong current password
|
|
||||||
$response = $this->withHeaders([
|
|
||||||
'Authorization' => 'Bearer sponsor-changer-token',
|
|
||||||
])->postJson('/api/sponsors/change-password', [
|
|
||||||
'current_password' => 'WrongPassword',
|
|
||||||
'new_password' => 'NewPassword@123',
|
|
||||||
'new_password_confirmation' => 'NewPassword@123',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertStatus(422)
|
|
||||||
->assertJsonValidationErrors(['current_password']);
|
|
||||||
|
|
||||||
// 2. Try with correct current password
|
|
||||||
$response = $this->withHeaders([
|
|
||||||
'Authorization' => 'Bearer sponsor-changer-token',
|
|
||||||
])->postJson('/api/sponsors/change-password', [
|
|
||||||
'current_password' => 'Password@123',
|
|
||||||
'new_password' => 'NewPassword@123',
|
|
||||||
'new_password_confirmation' => 'NewPassword@123',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertStatus(200)
|
|
||||||
->assertJson([
|
|
||||||
'success' => true,
|
|
||||||
'message' => 'Password changed successfully.'
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Verify password is updated for both Sponsor and User
|
|
||||||
$this->assertTrue(Hash::check('NewPassword@123', $sponsor->fresh()->password));
|
|
||||||
$this->assertTrue(Hash::check('NewPassword@123', $user->fresh()->password));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1540,55 +1540,4 @@ public function test_profile_response_does_not_contain_deprecated_fields()
|
|||||||
$this->assertArrayNotHasKey('city', $json);
|
$this->assertArrayNotHasKey('city', $json);
|
||||||
$this->assertArrayNotHasKey('area', $json);
|
$this->assertArrayNotHasKey('area', $json);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test worker can change password successfully.
|
|
||||||
*/
|
|
||||||
public function test_worker_can_change_password()
|
|
||||||
{
|
|
||||||
$worker = Worker::create([
|
|
||||||
'name' => 'Password Changer',
|
|
||||||
'email' => 'changer@example.com',
|
|
||||||
'phone' => '+971509990099',
|
|
||||||
'language' => 'HI',
|
|
||||||
'password' => bcrypt('OldPassword@123'),
|
|
||||||
'nationality' => 'Indian',
|
|
||||||
'age' => 25,
|
|
||||||
'salary' => 1500,
|
|
||||||
'availability' => 'Immediate',
|
|
||||||
'experience' => 'None',
|
|
||||||
'religion' => 'Christian',
|
|
||||||
'bio' => 'Some Bio',
|
|
||||||
'api_token' => 'changer-token',
|
|
||||||
]);
|
|
||||||
|
|
||||||
// 1. Invalid current password
|
|
||||||
$response = $this->withHeaders([
|
|
||||||
'Authorization' => 'Bearer changer-token',
|
|
||||||
])->postJson('/api/workers/change-password', [
|
|
||||||
'current_password' => 'WrongPassword',
|
|
||||||
'new_password' => 'NewPassword@123',
|
|
||||||
'new_password_confirmation' => 'NewPassword@123',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertStatus(422)
|
|
||||||
->assertJsonValidationErrors(['current_password']);
|
|
||||||
|
|
||||||
// 2. Successful change
|
|
||||||
$response = $this->withHeaders([
|
|
||||||
'Authorization' => 'Bearer changer-token',
|
|
||||||
])->postJson('/api/workers/change-password', [
|
|
||||||
'current_password' => 'OldPassword@123',
|
|
||||||
'new_password' => 'NewPassword@123',
|
|
||||||
'new_password_confirmation' => 'NewPassword@123',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertStatus(200)
|
|
||||||
->assertJson([
|
|
||||||
'success' => true,
|
|
||||||
'message' => 'Password changed successfully.'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->assertTrue(\Illuminate\Support\Facades\Hash::check('NewPassword@123', $worker->fresh()->password));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user