Skip to content

Commit 2edaac2

Browse files
author
Evan Sims
authored
Ensure ?include_totals are handled on GET /users and GET /roles requests for Management API (#476)
1 parent 25b3d2b commit 2edaac2

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

src/API/Management/Roles.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ class Roles extends GenericResource
2828
*/
2929
public function getAll(array $params = [])
3030
{
31+
$params = $this->normalizePagination( $params );
32+
$params = $this->normalizeIncludeTotals( $params );
33+
3134
return $this->apiClient->method('get')
32-
->withDictParams($this->normalizePagination( $params ))
35+
->withDictParams($params)
3336
->addPath('roles')
3437
->call();
3538
}

src/API/Management/Users.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public function getAll(array $params = [], $fields = null, $include_fields = nul
142142
}
143143

144144
$params = $this->normalizePagination( $params, $page, $per_page );
145+
$params = $this->normalizeIncludeTotals( $params );
145146

146147
return $this->apiClient->method('get')
147148
->addPath('users')

tests/unit/API/Management/RolesMockedTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,10 @@ public function testThatGetUsersRequestWithEmptyRoleIdThrowsException()
529529
*/
530530
public function testThatGetUsersRequestIsFormattedProperly()
531531
{
532-
$api = new MockManagementApi( [ new Response( 200, self::$headers ) ] );
532+
$api = new MockManagementApi( [
533+
new Response( 200, self::$headers ),
534+
new Response( 200, self::$headers )
535+
] );
533536

534537
$api->call()->roles()->getUsers( '__test_role_id__', [ 'per_page' => 6, 'include_totals' => 1 ] );
535538

@@ -543,9 +546,15 @@ public function testThatGetUsersRequestIsFormattedProperly()
543546
$this->assertEquals( 'Bearer __api_token__', $headers['Authorization'][0] );
544547
$this->assertEquals( self::$expectedTelemetry, $headers['Auth0-Client'][0] );
545548

546-
$query = $api->getHistoryQuery();
547-
$this->assertStringContainsString( 'page=6', $query );
548-
$this->assertStringContainsString( 'include_totals=true', $query );
549+
$query = '&' . $api->getHistoryQuery();
550+
$this->assertStringContainsString( '&per_page=6', $query );
551+
$this->assertStringContainsString( '&include_totals=true', $query );
552+
553+
$api->call()->roles()->getUsers( '__test_role_id__', [ 'per_page' => 12 ] );
554+
555+
$query = '&' . $api->getHistoryQuery();
556+
$this->assertStringContainsString( '&per_page=12', $query );
557+
$this->assertStringContainsString( '&include_totals=false', $query );
549558
}
550559

551560
/**

tests/unit/API/Management/UsersMockedTest.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,10 @@ public function testThatGetAllUsersRequestIsFormattedProperly()
205205
$api->call()->users()->getAll();
206206

207207
$this->assertEquals( 'GET', $api->getHistoryMethod() );
208-
$this->assertEquals( 'https://api.test.local/api/v2/users', $api->getHistoryUrl() );
208+
$this->assertStringStartsWith( 'https://api.test.local/api/v2/users', $api->getHistoryUrl() );
209+
210+
$query = '&'.$api->getHistoryQuery();
211+
$this->assertStringContainsString( '&include_totals=false', $query );
209212

210213
$headers = $api->getHistoryHeaders();
211214
$this->assertEquals( 'Bearer __api_token__', $headers['Authorization'][0] );
@@ -225,8 +228,8 @@ public function testThatGetAllUsersAdditionalParamsAreSent()
225228

226229
$api->call()->users()->getAll( [ '__test_parameter__' => '__test_value__' ] );
227230

228-
$query = $api->getHistoryQuery();
229-
$this->assertEquals( '__test_parameter__=__test_value__', $query );
231+
$query = '&'.$api->getHistoryQuery();
232+
$this->assertStringContainsString( '&__test_parameter__=__test_value__', $query );
230233
}
231234

232235
/**
@@ -242,8 +245,8 @@ public function testThatGetAllUsersFieldsParamDoesNotOverwrite()
242245

243246
$api->call()->users()->getAll( [ 'fields' => 'field1,field2' ], 'field3' );
244247

245-
$query = $api->getHistoryQuery();
246-
$this->assertEquals( 'fields=field1,field2', $query );
248+
$query = '&'.$api->getHistoryQuery();
249+
$this->assertStringContainsString( '&fields=field1,field2', $query );
247250
}
248251

249252
/**
@@ -262,13 +265,13 @@ public function testThatGetAllUsersFieldsAreFormattedCorrectly()
262265

263266
$api->call()->users()->getAll( [ 'fields' => 'field1,field2' ] );
264267

265-
$query = $api->getHistoryQuery();
266-
$this->assertEquals( 'fields=field1,field2', $query );
268+
$query = '&'.$api->getHistoryQuery();
269+
$this->assertStringContainsString( '&fields=field1,field2', $query );
267270

268271
$api->call()->users()->getAll( [ 'fields' => [ 'field1', 'field2' ] ] );
269272

270-
$query = $api->getHistoryQuery();
271-
$this->assertEquals( 'fields=field1,field2', $query );
273+
$query = '&'.$api->getHistoryQuery();
274+
$this->assertStringContainsString( '&fields=field1,field2', $query );
272275
}
273276

274277
/**

0 commit comments

Comments
 (0)