-
Notifications
You must be signed in to change notification settings - Fork 215
Add tests, docblocks for Logs endpoints #270
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
Changes from all commits
83079ef
a472085
696e178
4e19efc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| <?php | ||
|
|
||
| namespace Auth0\Tests\API; | ||
|
|
||
| use Auth0\SDK\API\Management; | ||
|
|
||
| /** | ||
| * Class LogsTest. | ||
| * Tests the Auth0\SDK\API\Management\Logs class. | ||
| * | ||
| * @package Auth0\Tests\API | ||
| */ | ||
| class LogsTest extends ApiTests | ||
| { | ||
|
|
||
| /** | ||
| * Logs API client. | ||
| * | ||
| * @var mixed | ||
| */ | ||
| protected static $api; | ||
|
|
||
| /** | ||
| * Sets up API client for entire testing class. | ||
| * | ||
| * @return void | ||
| */ | ||
| public static function setUpBeforeClass() | ||
| { | ||
| $env = self::getEnvStatic(); | ||
| $token = self::getTokenStatic($env, [ 'logs' => [ 'actions' => ['read'] ] ]); | ||
| $api = new Management($token, $env['DOMAIN'], ['timeout' => 30]); | ||
|
|
||
| self::$api = $api->logs; | ||
| } | ||
|
|
||
| /** | ||
| * Test a general search. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function testLogSearchAndGetById() | ||
| { | ||
| $search_results = self::$api->search([ | ||
| 'fields' => '_id,log_id,date', | ||
| 'include_fields' => true, | ||
| ]); | ||
| $this->assertNotEmpty($search_results); | ||
| $this->assertNotEmpty($search_results[0]['_id']); | ||
| $this->assertNotEmpty($search_results[0]['log_id']); | ||
| $this->assertNotEmpty($search_results[0]['date']); | ||
| $this->assertCount(3, $search_results[0]); | ||
|
|
||
| // Test getting a single log result with a valid ID from above. | ||
| $one_log = self::$api->get($search_results[0]['log_id']); | ||
| $this->assertNotEmpty($one_log); | ||
| $this->assertEquals($search_results[0]['log_id'], $one_log['log_id']); | ||
| } | ||
|
|
||
| /** | ||
| * Test pagination parameters. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function testLogSearchPagination() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand how this one is "testing pagination". It only does a request and asserts that the response size is 10 items (per_page). Is not like other tests you've made before where you first ask for the first page of 2 items, and then ask for the second page of 1 items and compare that |
||
| { | ||
| $expected_count = 5; | ||
| $search_results= self::$api->search([ | ||
| // Fields here to speed up API call. | ||
| 'fields' => '_id,log_id', | ||
| 'include_fields' => true, | ||
|
|
||
| // Second page of 5 results. | ||
| 'page' => 1, | ||
| 'per_page' => $expected_count, | ||
|
|
||
| // Include totals to check pagination. | ||
| 'include_totals' => true, | ||
| ]); | ||
|
|
||
| $this->assertCount($expected_count, $search_results['logs']); | ||
| $this->assertEquals($expected_count, $search_results['length']); | ||
|
|
||
| // Starting on 2nd page so starting result should be equal to the number per page. | ||
| $this->assertEquals($expected_count, $search_results['start']); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the
arrayword doing here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type hinting, will throw an error if an array is not passed in.