Skip to content

Commit

Permalink
Retire more dead API code, add more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
edwh committed Mar 3, 2022
1 parent 840dff5 commit eecf919
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 40 deletions.
34 changes: 0 additions & 34 deletions app/Http/Controllers/API/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,38 +87,4 @@ protected static function mapUserAndAuditToUserChange($user, $audit)

return $userChange;
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$authenticatedUser = Auth::user();
if (! $authenticatedUser->hasRole('Administrator')) {
return abort(403, 'The authenticated user is not authorized to update this resource');
}

$user = User::find($id);
if ($user === null) {
abort(404, 'Resource not found');
}

$changesMade = false;

if ($request->has('username')) {
$user->username = $request->input('username');
$changesMade = true;
}

if ($changesMade) {
$user->save();
}

// Zapier seems to require some response body.
return response()->json(['success' => 'success'], 200);
}
}
7 changes: 3 additions & 4 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
|
*/

Route::get('/homepage_data', function () {
Route::get('/homepage_data', function () { // Used from DeviceController.
return App\Http\Controllers\ApiController::homepage_data();
});

Expand All @@ -31,13 +31,12 @@

Route::group(['middleware' => 'auth:api'], function () {
Route::get('/users/me', 'ApiController@getUserInfo'); // Not used but worth keeping and tested.
Route::get('/users', 'ApiController@getUserList');
Route::get('/users', 'ApiController@getUserList'); // Not used but worth keeping and tested.
Route::get('/users/changes', 'API\UserController@changes'); // Used by Zapier
Route::put('/users/{id}', 'API\UserController@update');

Route::get('/networks/{network}/stats/', 'API\NetworkController@stats'); // Used by Repair Together.

Route::get('/groups', 'API\GroupController@getGroupList');
Route::get('/groups', 'API\GroupController@getGroupList'); // Not used but worth keeping and tested.
Route::get('/groups/changes', 'API\GroupController@getGroupChanges'); // Used by Zapier

Route::get('/groups/network/', 'API\GroupController@getGroupsByUsersNetworks'); // Used by Repair Together.
Expand Down
17 changes: 15 additions & 2 deletions tests/Feature/Groups/GroupCreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,21 @@ class GroupCreateTest extends TestCase
{
public function testCreate()
{
$this->loginAsTestUser(Role::ADMINISTRATOR);
$this->assertNotNull($this->createGroup());
$user = factory(User::class)->states('Administrator')->create([
'api_token' => '1234',
]);
$this->actingAs($user);

$idgroups = $this->createGroup();
$this->assertNotNull($idgroups);
$group = Group::find($idgroups);

$response = $this->get('/api/groups?api_token=1234');
$response->assertSuccessful();
$ret = json_decode($response->getContent(), TRUE);
self::assertEquals(1, count($ret));
self::assertEquals($idgroups, $ret[0]['idgroups']);
self::assertEquals($group->name, $ret[0]['name']);
}

public function testCreateBadLocation()
Expand Down

0 comments on commit eecf919

Please sign in to comment.