Skip to content

FOUR-18935 Ecobank - ERROR 404 ON SECURITY LOGS SWAGGER #7768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ProcessMaker/Http/Controllers/Api/SecurityLogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,16 @@ public function index(Request $request)
$query->pmql($pmql);
}

// Get total
$totalCount = $query->count();

// Always paginate using query object instead "ApiCollection" class
$query->paginate($request->input('per_page', 10));

// Get records
$response = $query->get();

return new ApiCollection($response);
return new ApiCollection($response, $totalCount);
}

/**
Expand Down
54 changes: 54 additions & 0 deletions tests/Feature/Api/SecurityLogControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Tests\Feature\Api;

use ProcessMaker\Models\SecurityLog;
use ProcessMaker\Models\User;
use Tests\Feature\Shared\RequestHelper;
use Tests\TestCase;

class SecurityLogControllerTest extends TestCase
{
use RequestHelper;

public function test_index(): void
{
$user = User::factory()->create([
'status' => 'ACTIVE',
'is_administrator' => true,
]);

// Create 20 records
SecurityLog::factory()->count(20)->create([
'event' => 'login',
'user_id' => $user->id,
'meta' => [
'os' => [
'name' => 'OS X',
],
'browser' => [
'name' => 'Firefox',
],
],
]);

// Get 10 items (default per page)
$response = $this->apiCall('GET', route('api.security-logs.index'));
$response->assertStatus(200);
$response->assertJsonCount(10, 'data');

// Get 2 items, page 1
$response = $this->apiCall('GET', route('api.security-logs.index'), ['per_page' => 2]);
$response->assertStatus(200);
$response->assertJsonCount(2, 'data');
$response->assertJsonFragment(['total_pages' => 10]);
$response->assertJsonFragment(['current_page' => 1]);

// Get 2 items, page 2
$response = $this->apiCall('GET', route('api.security-logs.index'), ['per_page' => 2, 'page' => 2]);
$response->assertStatus(200);
$response->assertJsonCount(2, 'data');
$response->assertJsonFragment(['total_pages' => 10]);
$response->assertJsonFragment(['current_page' => 2]);
}
}
Loading