Skip to content

Commit

Permalink
[Mobile][Test] トランザクション登録ロジックテスト追加 #327
Browse files Browse the repository at this point in the history
  • Loading branch information
wakamenod committed Jul 20, 2023
1 parent 9e6e383 commit 63f2865
Show file tree
Hide file tree
Showing 10 changed files with 1,119 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,23 @@ class SubmitExpenseScheduleController
..expenseLocationID = schedule.locationID)));

Future<void> submit(ExpenseSchedule expenseSchedule) async {
if (!expenseSchedule.isValid) return;
state = const AsyncLoading<void>();

final String timezone =
await ref.read(localTimezoneProvider.future) ?? 'UTC';

expenseSchedule.isNew
? await ref
.read(registerExpenseScheduleRepositoryProvider)
.registerExpenseSchedule(
_registerRequest(expenseSchedule, timezone))
: await ref
.read(updateExpenseScheduleRepositoryProvider)
.updateExpenseSchedule(_updateRequest(expenseSchedule, timezone));

ref.invalidate(fetchSchedulesProvider);

// state = AsyncValue.data(
// state.copyWith(submissionStatus: FormzSubmissionStatus.success));
// // } on CustomFailure catch (e) {
// // state = state.copyWith(
// // status: FormzSubmissionStatus.failure, errorMessage: e.code);
// // }

// TODO エラーハンドリング
// if (!state.hasError) {
// ref.read(itemQuantityControllerProvider.notifier).updateQuantity(1);
// }
state = await AsyncValue.guard(() async {
expenseSchedule.isNew
? await ref
.read(registerExpenseScheduleRepositoryProvider)
.registerExpenseSchedule(
_registerRequest(expenseSchedule, timezone))
: await ref
.read(updateExpenseScheduleRepositoryProvider)
.updateExpenseSchedule(_updateRequest(expenseSchedule, timezone));

ref.invalidate(fetchSchedulesProvider);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,23 @@ class SubmitIncomeScheduleController extends _$SubmitIncomeScheduleController {
..incomeTypeId = inc.incomeTypeID)));

Future<void> submit(IncomeSchedule incomeSchedule) async {
if (!incomeSchedule.isValid) return;
state = const AsyncLoading<void>();

final String timezone =
await ref.read(localTimezoneProvider.future) ?? 'UTC';

incomeSchedule.isNew
? await ref
.read(registerIncomeScheduleRepositoryProvider)
.registerIncomeSchedule(_registerRequest(incomeSchedule, timezone))
: await ref
.read(updateIncomeScheduleRepositoryProvider)
.updateIncomeSchedule(_updateRequest(incomeSchedule, timezone));

ref.invalidate(fetchSchedulesProvider);

// state = AsyncValue.data(
// state.copyWith(submissionStatus: FormzSubmissionStatus.success));
// // } on CustomFailure catch (e) {
// // state = state.copyWith(
// // status: FormzSubmissionStatus.failure, errorMessage: e.code);
// // }

// TODO エラーハンドリング
// if (!state.hasError) {
// ref.read(itemQuantityControllerProvider.notifier).updateQuantity(1);
// }
state = await AsyncValue.guard(() async {
incomeSchedule.isNew
? await ref
.read(registerIncomeScheduleRepositoryProvider)
.registerIncomeSchedule(
_registerRequest(incomeSchedule, timezone))
: await ref
.read(updateIncomeScheduleRepositoryProvider)
.updateIncomeSchedule(_updateRequest(incomeSchedule, timezone));

ref.invalidate(fetchSchedulesProvider);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RegisterExpenseRepository {
Future<ModelExpense> registerExpense(RegisterExpenseReq request) async {
final api = _openapi.getSuitoExpenseApi();
final response = await api.registerExpense(request: request);
return response.data?.newExpense ?? ModelExpense();
return response.data!.newExpense;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,19 @@ class SubmitExpenseController extends _$SubmitExpenseController {
}

Future<void> submit(Expense expense) async {
if (!expense.isValid) return;
state = const AsyncLoading<void>();

expense.isNew
? await ref
.read(registerExpenseRepositoryProvider)
.registerExpense(_registerRequest(expense))
: await ref
.read(updateExpenseRepositoryProvider)
.updateExpense(_updateRequest(expense));

ref.invalidate(fetchTransactionsProvider);

// ref.read(reloadTransactionsProvider.notifier).reload();

// state = AsyncValue.data(
// state.copyWith(submissionStatus: FormzSubmissionStatus.success));
// // } on CustomFailure catch (e) {
// // state = state.copyWith(
// // status: FormzSubmissionStatus.failure, errorMessage: e.code);
// // }

// TODO エラーハンドリング
// if (!state.hasError) {
// ref.read(itemQuantityControllerProvider.notifier).updateQuantity(1);
// }
state = await AsyncValue.guard(() async {
expense.isNew
? await ref
.read(registerExpenseRepositoryProvider)
.registerExpense(_registerRequest(expense))
: await ref
.read(updateExpenseRepositoryProvider)
.updateExpense(_updateRequest(expense));

ref.invalidate(fetchTransactionsProvider);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,19 @@ class SubmitIncomeController extends _$SubmitIncomeController {
}

Future<void> submit(Income income) async {
if (!income.isValid) return;
state = const AsyncLoading<void>();

income.isNew
? await ref
.read(registerIncomeRepositoryProvider)
.registerIncome(_registerRequest(income))
: await ref
.read(updateIncomeRepositoryProvider)
.updateIncome(_updateRequest(income));

ref.invalidate(fetchTransactionsProvider);

// ref.read(reloadTransactionsProvider.notifier).reload();

// state = AsyncValue.data(
// state.copyWith(submissionStatus: FormzSubmissionStatus.success));
// // } on CustomFailure catch (e) {
// // state = state.copyWith(
// // status: FormzSubmissionStatus.failure, errorMessage: e.code);
// // }

// TODO エラーハンドリング
// if (!state.hasError) {
// ref.read(itemQuantityControllerProvider.notifier).updateQuantity(1);
// }
state = await AsyncValue.guard(() async {
income.isNew
? await ref
.read(registerIncomeRepositoryProvider)
.registerIncome(_registerRequest(income))
: await ref
.read(updateIncomeRepositoryProvider)
.updateIncome(_updateRequest(income));

ref.invalidate(fetchTransactionsProvider);
});
}
}
Loading

0 comments on commit 63f2865

Please sign in to comment.