Skip to content

Firefly III: a personal finances manager

Go from get to post.

James Colea3f33ae88858
diff --git a/public/v1/js/ff/budgets/index.js b/public/v1/js/ff/budgets/index.js
index fb962528d4..bc7ad2387d 100644
--- a/public/v1/js/ff/budgets/index.js
+++ b/public/v1/js/ff/budgets/index.js
@@ -108,38 +108,7 @@ function sortStop(event, ui) {
page: page,
_token: token
};
- // var thisDate = current.data('date');
- // var originalBG = current.css('backgroundColor');
- //
- //
- // if (current.prev().data('date') !== thisDate && current.next().data('date') !== thisDate) {
- // // animate something with color:
- // current.animate({backgroundColor: "#d9534f"}, 200, function () {
- // $(this).animate({backgroundColor: originalBG}, 200);
- // return undefined;
- // });
- //
- // return false;
- // }
- //
- // // do update
- // var list = $('tr[data-date="' + thisDate + '"]');
- // var submit = [];
- // $.each(list, function (i, v) {
- // var row = $(v);
- // var id = row.data('id');
- // submit.push(id);
- // });
- //
- // // do extra animation when done?
- $.get('budgets/reorder', arr);
- //
- // current.animate({backgroundColor: "#5cb85c"}, 200, function () {
- // $(this).animate({backgroundColor: originalBG}, 200);
- // return undefined;
- // });
- // return undefined;
- //alert('drop!');
+ $.post('budgets/reorder', arr);
}
diff --git a/routes/web.php b/routes/web.php
index de25defb50..fe38fa3dab 100755
--- a/routes/web.php
+++ b/routes/web.php
@@ -215,7 +215,7 @@ Route::group(
Route::get('list/no-budget/{start_date?}/{end_date?}', ['uses' => 'Budget\ShowController@noBudget', 'as' => 'no-budget']);
// reorder budgets
- Route::get('reorder', ['uses' => 'Budget\IndexController@reorder', 'as' => 'reorder']);
+ Route::post('reorder', ['uses' => 'Budget\IndexController@reorder', 'as' => 'reorder']);
// index
Route::get('{start_date?}/{end_date?}', ['uses' => 'Budget\IndexController@index', 'as' => 'index']);
diff --git a/tests/Feature/Controllers/Budget/IndexControllerTest.php b/tests/Feature/Controllers/Budget/IndexControllerTest.php
index 24396a67d0..3af6d544a1 100644
--- a/tests/Feature/Controllers/Budget/IndexControllerTest.php
+++ b/tests/Feature/Controllers/Budget/IndexControllerTest.php
@@ -131,8 +131,8 @@ class IndexControllerTest extends TestCase
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
+ $fiscalHelper = $this->mock(FiscalHelperInterface::class);
+ $date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
@@ -186,8 +186,8 @@ class IndexControllerTest extends TestCase
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
+ $fiscalHelper = $this->mock(FiscalHelperInterface::class);
+ $date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
@@ -239,8 +239,8 @@ class IndexControllerTest extends TestCase
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
+ $fiscalHelper = $this->mock(FiscalHelperInterface::class);
+ $date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
@@ -254,4 +254,25 @@ class IndexControllerTest extends TestCase
$response = $this->get(route('budgets.index', ['Hello-there']));
$response->assertStatus(404);
}
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\Budget\IndexController
+ */
+ public function testReorder(): void
+ {
+ $repository = $this->mock(BudgetRepositoryInterface::class);
+ $data = [
+ 'budgetIds' => [1,2],
+ 'page' => 1,
+ ];
+
+ $repository->shouldReceive('cleanupBudgets')->atLeast()->once();
+ $repository->shouldReceive('findNull')->atLeast()->once()->andReturn(new Budget);
+ $repository->shouldReceive('setBudgetOrder')->atLeast()->once();
+
+ $this->be($this->user());
+ $response = $this->post(route('budgets.reorder', $data));
+ $response->assertStatus(200);
+
+ }
}