Skip to content

Commit 8ff91b6

Browse files
committed
FIN-349 fix any testing issues after budget changes.
1 parent 50de3d6 commit 8ff91b6

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

bpmn-process/src/main/java/com/jongsoft/finance/bpmn/delegate/user/ParseUserConfigurationDelegate.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,16 @@ public void execute(DelegateExecution execution) throws Exception {
5353
execution.setVariableLocal("ruleStorageToken", null);
5454
}
5555

56-
var sortedBudgets = profileJson.getBudgetPeriods().stream()
57-
.sorted(Comparator.comparing(BudgetJson::getStart))
58-
.toList();
56+
if (profileJson.getBudgetPeriods() != null) {
57+
var sortedBudgets = profileJson.getBudgetPeriods().stream()
58+
.sorted(Comparator.comparing(BudgetJson::getStart))
59+
.toList();
60+
execution.setVariableLocal("budgetPeriods", serialize(sortedBudgets));
61+
} else {
62+
execution.setVariableLocal("budgetPeriods", List.of());
63+
}
5964

6065
execution.setVariableLocal("accounts", serialize(profileJson.getAccounts()));
61-
execution.setVariableLocal("budgetPeriods", serialize(sortedBudgets));
6266
execution.setVariableLocal("contracts", serialize(profileJson.getContracts()));
6367
execution.setVariableLocal("categories", serialize(profileJson.getCategories()));
6468
execution.setVariableLocal("tags", Control.Option(profileJson.getTags()).getOrSupply(List::of));

bpmn-process/src/test/java/com/jongsoft/finance/bpmn/delegate/budget/ProcessBudgetCreateDelegateTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import com.jongsoft.finance.domain.user.Role;
66
import com.jongsoft.finance.domain.user.UserAccount;
77
import com.jongsoft.finance.messaging.EventBus;
8+
import com.jongsoft.finance.messaging.commands.budget.CloseBudgetCommand;
89
import com.jongsoft.finance.messaging.commands.budget.CreateBudgetCommand;
910
import com.jongsoft.finance.messaging.commands.budget.CreateExpenseCommand;
11+
import com.jongsoft.finance.messaging.commands.budget.UpdateExpenseCommand;
1012
import com.jongsoft.finance.providers.BudgetProvider;
1113
import com.jongsoft.finance.security.CurrentUserProvider;
1214
import com.jongsoft.finance.serialized.BudgetJson;
@@ -67,7 +69,13 @@ void setup() {
6769

6870
@Test
6971
void execute_initial() {
70-
Mockito.when(budgetProvider.lookup(2019, 1)).thenReturn(Control.Option());
72+
Mockito.when(budgetProvider.lookup(2019, 1))
73+
.thenReturn(Control.Option())
74+
.thenReturn(Control.Option(Budget.builder()
75+
.id(1L)
76+
.expectedIncome(1200)
77+
.expenses(Collections.List())
78+
.build()));
7179

7280
subject.execute(execution);
7381

@@ -95,9 +103,10 @@ void execute_indexation() {
95103

96104
subject.execute(execution);
97105

106+
Mockito.verify(eventPublisher).publishEvent(Mockito.any(CloseBudgetCommand.class));
98107
Mockito.verify(eventPublisher).publishEvent(Mockito.any(CreateBudgetCommand.class));
99-
Mockito.verify(initial).indexBudget(LocalDate.of(2019, 1, 1), 1200);
100108
Mockito.verify(eventPublisher).publishEvent(Mockito.any(CreateExpenseCommand.class));
109+
Mockito.verify(eventPublisher).publishEvent(Mockito.any(UpdateExpenseCommand.class));
101110
}
102111

103112
}

jpa-repository/src/main/java/com/jongsoft/finance/jpa/budget/BudgetProviderJpa.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public Optional<Budget> lookup(int year, int month) {
4747
select b from BudgetJpa b
4848
where b.user.username = :username
4949
and b.from <= :start
50-
and (b.until is null or b.until > :end)""";
50+
and (b.until is null or b.until >= :end)""";
5151

5252
return reactiveEntityManager.<BudgetJpa>blocking()
5353
.hql(hql)

jpa-repository/src/test/java/com/jongsoft/finance/jpa/budget/BudgetProviderJpaIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ void lookup() throws IOException {
3838

3939
@Test
4040
void lookup_201901() throws IOException {
41-
var check = budgetProvider.lookup(2019, 1).get();
41+
var check = budgetProvider.lookup(2019, 1)
42+
.get();
4243

4344
Assertions.assertThat(check.getExpenses()).hasSize(2);
4445
Assertions.assertThat(check.getExpectedIncome()).isEqualTo(2500);

jpa-repository/src/test/resources/sql/user/budget-provider.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ values (1, 'Groceries', 1),
55

66
insert into budget (id, expected_income, user_id, b_from, b_until)
77
values (1, 2500, 1, '2019-01-01', '2019-02-01'),
8-
(2, 2800, 1, '2019-02-01', null),
9-
(3, 3000, 2, '2019-01-01', null);
8+
(2, 2800, 1, '2019-02-01', null);
109

1110
insert into budget_period (id, bp_lower_bound, bp_upper_bound, expense_id, budget_id)
1211
values (1, 200, 300, 1, 1),

0 commit comments

Comments
 (0)