Skip to content

Commit

Permalink
Can't create multiple devices with a barrier to entry.
Browse files Browse the repository at this point in the history
  • Loading branch information
edwh committed Dec 11, 2023
1 parent 8ef4cdb commit 3e231c5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
12 changes: 6 additions & 6 deletions app/Http/Controllers/DeviceController.php
Expand Up @@ -169,10 +169,10 @@ public function ajaxCreate(Request $request)
event(new DeviceCreatedOrUpdated($device[$i]));

// Update barriers
if (isset($barrier) && ! empty($barrier) && $repair_status == 3) { // Only sync when repair status is end-of-life
if (isset($barrier) && ! empty($barrier) && $repair_status == Device::REPAIR_STATUS_ENDOFLIFE) {
Device::find($device[$i]->iddevices)->barriers()->sync($barrier);
} else {
Device::find($device[$i]->iddevices)->barriers()->sync([]);
Device::find($device[$i]->iddevices)->barriers()->sync([]);
}

// If the number of devices exceeds set amount then show the following message
Expand All @@ -194,8 +194,8 @@ public function ajaxCreate(Request $request)

$barriers = [];

foreach ($device[$i]->barriers as $barrier) {
$barriers[] = $barrier->id;
foreach ($device[$i]->barriers as $b) {
$barriers[] = $b->id;
}

$device[$i]->barrier = $barriers;
Expand Down Expand Up @@ -339,8 +339,8 @@ public function ajaxEdit(Request $request, $id)

$barriers = [];

foreach ($device->barriers as $barrier) {
$barriers[] = $barrier->id;
foreach ($device->barriers as $b) {
$barriers[] = $b->id;
}

$device->barrier = $barriers;
Expand Down
17 changes: 17 additions & 0 deletions tests/Feature/Devices/EditTest.php
Expand Up @@ -35,6 +35,10 @@ public function testEdit()
$iddevices = $rsp['devices'][0]['iddevices'];
self::assertNotNull($iddevices);

# Add a barrier to repair - there was a bug in this case with quantity > 1.
$this->device_inputs['repair_status'] = Device::REPAIR_STATUS_ENDOFLIFE;
$this->device_inputs['barrier'] = [1];

# Edit the quantity.
$atts = $this->device_inputs;
$atts['quantity'] = 2;
Expand Down Expand Up @@ -256,4 +260,17 @@ public function testNextSteps() {
self::assertEquals(1, $device->do_it_yourself);
self::assertEquals(0, $device->more_time_needed);
}

public function testBarrierMultiple()
{
$atts = $this->device_inputs;
$atts['quantity'] = 2;
$atts['repair_status'] = Device::REPAIR_STATUS_ENDOFLIFE;
$atts['barrier'] = [1];

$rsp = $this->post('/device/create', $atts);
self::assertTrue($rsp['success']);
$iddevices = $rsp['devices'][0]['iddevices'];
self::assertNotNull($iddevices);
}
}
2 changes: 0 additions & 2 deletions tests/TestCase.php
Expand Up @@ -94,8 +94,6 @@ protected function setUp(): void
$network->name = 'Restarters';
$network->shortname = 'restarters';
$network->save();
} else {
error_log("Got network");
}

$this->withoutExceptionHandling();
Expand Down

0 comments on commit 3e231c5

Please sign in to comment.