From 2ce88c2f0faf0051fc37cbd7a0bd9312bd30a5b3 Mon Sep 17 00:00:00 2001 From: Seb Dangerfield <1449113+sedan07@users.noreply.github.com> Date: Thu, 21 Jan 2021 18:43:42 +0000 Subject: [PATCH] (#4) Don't overwrite tags with "1" when reordering components --- .../Controllers/Dashboard/ApiController.php | 14 +--- tests/Dashboard/ApiTest.php | 70 +++++++++++++++++++ 2 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 tests/Dashboard/ApiTest.php 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); + } +}