From 67dbcd053d40f45db84d7caf2d7ea5e4d527d68c Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen <sebastiaan.de.schaetzen@gmail.com> Date: Sun, 25 May 2025 14:53:31 +0200 Subject: [PATCH] Set default total allowance to 10 --- backend/allowance_planner.db3.backup.1 | Bin 0 -> 20480 bytes backend/api_test.go | 35 ++++++++++++++++++ .../migrations/3_change_weight_default.sql | 4 ++ 3 files changed, 39 insertions(+) create mode 100644 backend/allowance_planner.db3.backup.1 create mode 100644 backend/migrations/3_change_weight_default.sql diff --git a/backend/allowance_planner.db3.backup.1 b/backend/allowance_planner.db3.backup.1 new file mode 100644 index 0000000000000000000000000000000000000000..dd398a849eec729f19198521e2947c096cc29947 GIT binary patch literal 20480 zcmeI%L2KJE6bEqGjY*b~Wzd5eVerDBG%!k`hh5u^j2*he*4~HOyrd$sT_l+_$9Ax9 zu@AAYv@fu)Fxg4tnQjfcwc-CjvXEl@-cP!SoP0V~j%l2kL^?VU&qWxDLn0wW=v(C5 zZ8ZF#XtxpgLDBAuQ0#phbo?(Gou25vfA+oe!w(P;fB*y_009U<00Izz00bVE!1Z>c z8OL#O6FGUN*-1OKWf#5sJUlub(&^FL;~|w(?cFx{P$N>Q;|UwOG%As1PE(%0F4t0- zFgd<*lxDu=S}*1e&!nl|t1n7x)g<NBa(i&CwwiIjAAEgTW+k=GW->izTa6mE{Hpmi zNj}Lfn=gNqP*3Gw`8#PQ>{fNxUpkYzNbb%mjd(0`?P!02Fk>~jaAa8O6_2lVCv3*O zUU2iOto1@!mznwUu~n;bIk~39Vvp{x(y4^~E+>~XlKx&?uSO<Wp586hC;BE>9F>n{ zqQxg{*@d+v%c&|we_sCgu>8%bvfNv0u2*jl$U39WU2!)LyFW$um+ue|fB*y_009U< z00Izz00bZa0SG)&fu~_4UbI>t^6^-6H;6>P)jDCe%n9phasT&!`Xe9!0SG_<0uX=z z1Rwwb2tWV=5ZGV=-2XRtb5R-uAOHafKmY;|fB*y_009U<U@3t6KaK(fAOHafKmY;| QfB*y_009U<VDklj13k+CwEzGB literal 0 HcmV?d00001 diff --git a/backend/api_test.go b/backend/api_test.go index 06d4628..d0fe142 100644 --- a/backend/api_test.go +++ b/backend/api_test.go @@ -605,6 +605,36 @@ func TestCompleteTask(t *testing.T) { } } +func TestCompleteTaskWithNoWeights(t *testing.T) { + e := startServer(t) + taskId := createTestTaskWithAmount(e, 101) + + e.GET("/tasks").Expect().Status(200).JSON().Array().Length().IsEqual(1) + + // Ensure main allowance has no weight + e.PUT("/user/1/allowance/0").WithJSON(UpdateAllowanceRequest{ + Weight: 0, + }).Expect().Status(200) + + // Complete the task + e.POST("/task/" + strconv.Itoa(taskId) + "/complete").Expect().Status(200) + + // Verify the task is marked as completed + e.GET("/task/" + strconv.Itoa(taskId)).Expect().Status(404) + + // Verify the allowances are updated for user 1 + allowances := e.GET("/user/1/allowance").Expect().Status(200).JSON().Array() + allowances.Length().IsEqual(1) + allowances.Value(0).Object().Value("id").Number().IsEqual(0) + allowances.Value(0).Object().Value("progress").Number().InDelta(101.00, 0.01) + + // And also for user 2 + allowances = e.GET("/user/2/allowance").Expect().Status(200).JSON().Array() + allowances.Length().IsEqual(1) + allowances.Value(0).Object().Value("id").Number().IsEqual(0) + allowances.Value(0).Object().Value("progress").Number().InDelta(101.00, 0.01) +} + func TestCompleteTaskAllowanceWeightsSumTo0(t *testing.T) { e := startServer(t) taskId := createTestTaskWithAmount(e, 101) @@ -643,6 +673,11 @@ func TestCompleteAllowance(t *testing.T) { createTestTaskWithAmount(e, 100) createTestAllowance(e, "Test Allowance 1", 100, 50) + // Update base allowance + e.PUT("/user/1/allowance/0").WithJSON(UpdateAllowanceRequest{ + Weight: 0, + }).Expect().Status(200) + // Complete the task e.POST("/task/1/complete").Expect().Status(200) diff --git a/backend/migrations/3_change_weight_default.sql b/backend/migrations/3_change_weight_default.sql new file mode 100644 index 0000000..aa5d336 --- /dev/null +++ b/backend/migrations/3_change_weight_default.sql @@ -0,0 +1,4 @@ +alter table users rename column weight to weight_old; +alter table users add column weight real not null default 10.0; +update users set weight = weight_old; +alter table users drop column weight_old;