mohan #12
@ -280,12 +280,17 @@ public function reportFromEmployer(Request $request)
|
|||||||
*/
|
*/
|
||||||
public function getReasonsForWorker(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');
|
$query = DB::table('report_reasons')->where('status', 'Active');
|
||||||
|
|
||||||
if ($type && in_array($type, ['Chat', 'Review'])) {
|
if ($type && in_array(strtolower($type), ['chat', 'support'])) {
|
||||||
$query->whereIn('type', [$type, 'Both']);
|
$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']);
|
$reasons = $query->orderBy('id', 'asc')->get(['id', 'reason', 'type']);
|
||||||
@ -302,12 +307,17 @@ public function getReasonsForWorker(Request $request)
|
|||||||
*/
|
*/
|
||||||
public function getReasonsForEmployer(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');
|
$query = DB::table('report_reasons')->where('status', 'Active');
|
||||||
|
|
||||||
if ($type && in_array($type, ['Chat', 'Review'])) {
|
if ($type && in_array(strtolower($type), ['chat', 'support'])) {
|
||||||
$query->whereIn('type', [$type, 'Both']);
|
$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']);
|
$reasons = $query->orderBy('id', 'asc')->get(['id', 'reason', 'type']);
|
||||||
|
|||||||
@ -2696,12 +2696,14 @@
|
|||||||
"name": "type",
|
"name": "type",
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"required": false,
|
"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": {
|
"schema": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
"Chat",
|
"Chat",
|
||||||
"Review"
|
"Support",
|
||||||
|
"chat",
|
||||||
|
"support"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5134,12 +5136,14 @@
|
|||||||
"name": "type",
|
"name": "type",
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"required": false,
|
"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": {
|
"schema": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
"Chat",
|
"Chat",
|
||||||
"Review"
|
"Support",
|
||||||
|
"chat",
|
||||||
|
"support"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -276,6 +276,7 @@ public function test_get_report_reasons_filtering()
|
|||||||
['reason' => 'Review Abuse', 'status' => 'Active', 'type' => 'Review'],
|
['reason' => 'Review Abuse', 'status' => 'Active', 'type' => 'Review'],
|
||||||
['reason' => 'General Impersonation', 'status' => 'Active', 'type' => 'Both'],
|
['reason' => 'General Impersonation', 'status' => 'Active', 'type' => 'Both'],
|
||||||
['reason' => 'Inactive Reason', 'status' => 'Inactive', 'type' => 'Both'],
|
['reason' => 'Inactive Reason', 'status' => 'Inactive', 'type' => 'Both'],
|
||||||
|
['reason' => 'Billing Issue', 'status' => 'Active', 'type' => 'Support'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// 1. Worker retrieves all Active reasons
|
// 1. Worker retrieves all Active reasons
|
||||||
@ -284,33 +285,43 @@ public function test_get_report_reasons_filtering()
|
|||||||
])->getJson('/api/workers/report-reasons');
|
])->getJson('/api/workers/report-reasons');
|
||||||
|
|
||||||
$response->assertStatus(200)
|
$response->assertStatus(200)
|
||||||
->assertJsonCount(3, 'reasons')
|
->assertJsonCount(4, 'reasons')
|
||||||
->assertJsonFragment(['reason' => 'Chat Spam'])
|
->assertJsonFragment(['reason' => 'Chat Spam'])
|
||||||
->assertJsonFragment(['reason' => 'Review Abuse'])
|
->assertJsonFragment(['reason' => 'Review Abuse'])
|
||||||
->assertJsonFragment(['reason' => 'General Impersonation'])
|
->assertJsonFragment(['reason' => 'General Impersonation'])
|
||||||
|
->assertJsonFragment(['reason' => 'Billing Issue'])
|
||||||
->assertJsonMissing(['reason' => 'Inactive Reason']);
|
->assertJsonMissing(['reason' => 'Inactive Reason']);
|
||||||
|
|
||||||
// 2. Worker retrieves Chat reasons only
|
// 2. Worker retrieves Chat reasons only (case-insensitive)
|
||||||
$responseChat = $this->withHeaders([
|
$responseChat = $this->withHeaders([
|
||||||
'Authorization' => 'Bearer ' . $this->workerToken,
|
'Authorization' => 'Bearer ' . $this->workerToken,
|
||||||
])->getJson('/api/workers/report-reasons?type=Chat');
|
])->getJson('/api/workers/report-reasons?type=chat');
|
||||||
|
|
||||||
$responseChat->assertStatus(200)
|
$responseChat->assertStatus(200)
|
||||||
->assertJsonCount(2, 'reasons')
|
->assertJsonCount(2, 'reasons')
|
||||||
->assertJsonFragment(['reason' => 'Chat Spam'])
|
->assertJsonFragment(['reason' => 'Chat Spam'])
|
||||||
->assertJsonFragment(['reason' => 'General Impersonation'])
|
->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([
|
$responseReview = $this->withHeaders([
|
||||||
'Authorization' => 'Bearer ' . $this->workerToken,
|
'Authorization' => 'Bearer ' . $this->workerToken,
|
||||||
])->getJson('/api/workers/report-reasons?type=Review');
|
])->getJson('/api/workers/report-reasons?type=Review');
|
||||||
|
|
||||||
$responseReview->assertStatus(200)
|
$responseReview->assertStatus(200)
|
||||||
->assertJsonCount(2, 'reasons')
|
->assertJsonCount(4, 'reasons');
|
||||||
->assertJsonFragment(['reason' => 'Review Abuse'])
|
|
||||||
->assertJsonFragment(['reason' => 'General Impersonation'])
|
// 4. Worker retrieves Support reasons only (case-insensitive)
|
||||||
->assertJsonMissing(['reason' => 'Chat Spam']);
|
$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']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user