mohan #12

Merged
mohanmd merged 4 commits from mohan into master 2026-06-23 13:43:57 +00:00
3 changed files with 44 additions and 19 deletions
Showing only changes of commit 9b729e714f - Show all commits

View File

@ -280,12 +280,17 @@ public function reportFromEmployer(Request $request)
*/
public function getReasonsForWorker(Request $request)
{
$type = $request->query('type'); // Chat or Review
$type = $request->query('type'); // Chat or Support
$query = DB::table('report_reasons')->where('status', 'Active');
if ($type && in_array($type, ['Chat', 'Review'])) {
$query->whereIn('type', [$type, 'Both']);
if ($type && in_array(strtolower($type), ['chat', 'support'])) {
$mappedType = ucfirst(strtolower($type));
if ($mappedType === 'Support') {
$query->where('type', 'Support');
} else {
$query->whereIn('type', [$mappedType, 'Both']);
}
}
$reasons = $query->orderBy('id', 'asc')->get(['id', 'reason', 'type']);
@ -302,12 +307,17 @@ public function getReasonsForWorker(Request $request)
*/
public function getReasonsForEmployer(Request $request)
{
$type = $request->query('type'); // Chat or Review
$type = $request->query('type'); // Chat or Support
$query = DB::table('report_reasons')->where('status', 'Active');
if ($type && in_array($type, ['Chat', 'Review'])) {
$query->whereIn('type', [$type, 'Both']);
if ($type && in_array(strtolower($type), ['chat', 'support'])) {
$mappedType = ucfirst(strtolower($type));
if ($mappedType === 'Support') {
$query->where('type', 'Support');
} else {
$query->whereIn('type', [$mappedType, 'Both']);
}
}
$reasons = $query->orderBy('id', 'asc')->get(['id', 'reason', 'type']);

View File

@ -2696,12 +2696,14 @@
"name": "type",
"in": "query",
"required": false,
"description": "Optional type to filter reasons (Chat or Review). If not provided, returns all active reasons.",
"description": "Optional type to filter reasons (Chat or Support). Case-insensitive.",
"schema": {
"type": "string",
"enum": [
"Chat",
"Review"
"Support",
"chat",
"support"
]
}
}
@ -5134,12 +5136,14 @@
"name": "type",
"in": "query",
"required": false,
"description": "Optional type to filter reasons (Chat or Review). If not provided, returns all active reasons.",
"description": "Optional type to filter reasons (Chat or Support). Case-insensitive.",
"schema": {
"type": "string",
"enum": [
"Chat",
"Review"
"Support",
"chat",
"support"
]
}
}

View File

@ -276,6 +276,7 @@ public function test_get_report_reasons_filtering()
['reason' => 'Review Abuse', 'status' => 'Active', 'type' => 'Review'],
['reason' => 'General Impersonation', 'status' => 'Active', 'type' => 'Both'],
['reason' => 'Inactive Reason', 'status' => 'Inactive', 'type' => 'Both'],
['reason' => 'Billing Issue', 'status' => 'Active', 'type' => 'Support'],
]);
// 1. Worker retrieves all Active reasons
@ -284,33 +285,43 @@ public function test_get_report_reasons_filtering()
])->getJson('/api/workers/report-reasons');
$response->assertStatus(200)
->assertJsonCount(3, 'reasons')
->assertJsonCount(4, 'reasons')
->assertJsonFragment(['reason' => 'Chat Spam'])
->assertJsonFragment(['reason' => 'Review Abuse'])
->assertJsonFragment(['reason' => 'General Impersonation'])
->assertJsonFragment(['reason' => 'Billing Issue'])
->assertJsonMissing(['reason' => 'Inactive Reason']);
// 2. Worker retrieves Chat reasons only
// 2. Worker retrieves Chat reasons only (case-insensitive)
$responseChat = $this->withHeaders([
'Authorization' => 'Bearer ' . $this->workerToken,
])->getJson('/api/workers/report-reasons?type=Chat');
])->getJson('/api/workers/report-reasons?type=chat');
$responseChat->assertStatus(200)
->assertJsonCount(2, 'reasons')
->assertJsonFragment(['reason' => 'Chat Spam'])
->assertJsonFragment(['reason' => 'General Impersonation'])
->assertJsonMissing(['reason' => 'Review Abuse']);
->assertJsonMissing(['reason' => 'Review Abuse'])
->assertJsonMissing(['reason' => 'Billing Issue']);
// 3. Worker retrieves Review reasons only
// 3. Worker retrieves Review reasons (unsupported type, ignored)
$responseReview = $this->withHeaders([
'Authorization' => 'Bearer ' . $this->workerToken,
])->getJson('/api/workers/report-reasons?type=Review');
$responseReview->assertStatus(200)
->assertJsonCount(2, 'reasons')
->assertJsonFragment(['reason' => 'Review Abuse'])
->assertJsonFragment(['reason' => 'General Impersonation'])
->assertJsonMissing(['reason' => 'Chat Spam']);
->assertJsonCount(4, 'reasons');
// 4. Worker retrieves Support reasons only (case-insensitive)
$responseSupport = $this->withHeaders([
'Authorization' => 'Bearer ' . $this->workerToken,
])->getJson('/api/workers/report-reasons?type=support');
$responseSupport->assertStatus(200)
->assertJsonCount(1, 'reasons')
->assertJsonFragment(['reason' => 'Billing Issue'])
->assertJsonMissing(['reason' => 'Chat Spam'])
->assertJsonMissing(['reason' => 'General Impersonation']);
}
}