Skip to content

Commit

Permalink
Retire dead code, add test of device edit.
Browse files Browse the repository at this point in the history
  • Loading branch information
edwh committed Jan 4, 2022
1 parent 593149c commit d8841c1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 50 deletions.
49 changes: 0 additions & 49 deletions app/Http/Controllers/DeviceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,50 +210,6 @@ public function edit($id)
return redirect('/user/forbidden');
}

public function ajax_update($id)
{
$this->set('title', 'Edit Device');
if (hasRole($this->user, 'Administrator') || hasRole($this->user, 'Host')) {
$Categories = new Category;
$Device = $this->Device->findOne($id);

$this->set('title', 'Edit Device');
$this->set('categories', $Categories->listed());
$this->set('formdata', $Device);

event(new DeviceCreatedOrUpdated($Device));

return view('device.edit', [
'title' => 'Edit Device',
'categories' => $Categories->findAll(),
'formdata' => $Device,
]);
}
header('Location: /user/forbidden');
}

public function ajax_update_save($id)
{
if ($_SERVER['REQUEST_METHOD'] == 'POST' && ! empty($_POST) && filter_var($id, FILTER_VALIDATE_INT)) {
$data = $_POST;
$u = $this->Device->update($data, $id);

if (! $u) {
$response['response_type'] = 'danger';
$response['message'] = 'Something went wrong. Please check the data and try again.';
} else {
$response['response_type'] = 'success';
$response['message'] = 'Device updated!';
$response['data'] = $data;
$response['id'] = $id;
}

event(new DeviceCreatedOrUpdated($this->Device));

echo json_encode($response);
}
}

public function ajaxCreate(Request $request)
{
$rules = [
Expand Down Expand Up @@ -615,9 +571,4 @@ public function deleteImage($device_id, $id, $path)

return redirect()->back()->with('message', 'Sorry, but the image can\'t be deleted');
}

public function columnPreferences(Request $request)
{
$request->session()->put('column_preferences', $request->input('column_preferences'));
}
}
1 change: 0 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@
Route::get('/delete/{id}', 'DeviceController@delete');
Route::post('/image-upload/{id}', 'DeviceController@imageUpload');
Route::get('/image/delete/{iddevices}/{id}/{path}', 'DeviceController@deleteImage');
Route::post('/column-preferences', 'DeviceController@columnPreferences');
});

Route::resource('networks', 'NetworkController');
Expand Down
41 changes: 41 additions & 0 deletions tests/Feature/Devices/EditTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Tests\Feature;

use App\Device;
use App\Party;
use App\User;
use DB;
use Tests\TestCase;

class EditTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();

$this->event = factory(Party::class)->create();
$this->admin = factory(User::class)->state('Administrator')->create();
$this->device_inputs = factory(Device::class)->raw([
'event_id' => $this->event->idevents,
'quantity' => 1,
]);
$this->actingAs($this->admin);

$this->withoutExceptionHandling();
}

public function testEdit()
{
$rsp = $this->post('/device/create', $this->device_inputs);
self::assertTrue($rsp['success']);
$iddevices = $rsp['devices'][0]['iddevices'];
self::assertNotNull($iddevices);

# Edit the quantity.
$atts = $this->device_inputs;
$atts['quantity'] = 2;
$rsp = $this->post('/device/edit/' . $iddevices, $atts);
self::assertEquals('Device updated!', $rsp['success']);
}
}

0 comments on commit d8841c1

Please sign in to comment.