diff --git a/app/Http/Controllers/Dashboard/ApiController.php b/app/Http/Controllers/Dashboard/ApiController.php index 7c92b2c8d339..3781b808468b 100644 --- a/app/Http/Controllers/Dashboard/ApiController.php +++ b/app/Http/Controllers/Dashboard/ApiController.php @@ -68,18 +68,8 @@ public function postUpdateComponentOrder() try { $component = Component::find($componentId); - execute(new UpdateComponentCommand( - $component, - $component->name, - $component->description, - $component->status, - $component->link, - $order + 1, - $component->group_id, - $component->enabled, - $component->meta, - true - )); + $component->order = $order + 1; + $component->save(); } catch (QueryException $e) { throw new BadRequestHttpException(); } diff --git a/tests/Dashboard/ApiTest.php b/tests/Dashboard/ApiTest.php new file mode 100644 index 000000000000..8f258112356a --- /dev/null +++ b/tests/Dashboard/ApiTest.php @@ -0,0 +1,70 @@ +beUser(); + + $components = array(); + $components[] = factory(Component::class)->create(['id' => 1]); + $components[] = factory(Component::class)->create(['id' => 2]); + $components[] = factory(Component::class)->create(['id' => 3]); + + + $response = $this->json('POST', '/dashboard/api/components/order', [ + 'ids' => [ + 0 => "3", + 1 => "1", + 2 => "2" + ] + ]); + + $this->assertEquals(2, Component::find(1)->order); + $this->assertEquals(3, Component::find(2)->order); + $this->assertEquals(1, Component::find(3)->order); + } + + public function test_reordering_components_retains_tags() + { + $this->beUser(); + + $components = array(); + $components[] = factory(Component::class)->create(['id' => 1]); + $components[] = factory(Component::class)->create(['id' => 2]); + $components[0]->attachTags(['Internal']); + $components[1]->attachTags(['Foo', 'Bar']); + + + $response = $this->json('POST', '/dashboard/api/components/order', [ + 'ids' => [ + 0 => "2", + 1 => "1", + ] + ]); + + $this->assertEquals("Internal", Component::find(1)->tags[0]->name); + $this->assertEquals(2, Component::find(1)->order); + } +}