refactor: use sql_sandbox config instead of env for sync/async

- Replace Application.get_env(:mv, :env) with :sql_sandbox config
- Remove redundant :env config from test.exs
- More explicit and less error-prone for test environment detection
This commit is contained in:
Moritz 2025-12-12 16:05:39 +01:00
parent 162d06da21
commit 7e4d3e0a60
2 changed files with 3 additions and 5 deletions

View file

@ -47,7 +47,5 @@ config :mv, :session_identifier, :unsafe
config :mv, :require_token_presence_for_authentication, false
# Enable SQL Sandbox for async LiveView tests
# This flag controls sync vs async behavior in CycleGenerator after_action hooks
config :mv, :sql_sandbox, true
# Mark test environment for conditional behavior (e.g., sync vs async operations)
config :mv, :env, :test

View file

@ -112,7 +112,7 @@ defmodule Mv.Membership.Member do
# but in test environment it runs synchronously for DB sandbox compatibility
change after_action(fn _changeset, member, _context ->
if member.membership_fee_type_id && member.join_date do
if Application.get_env(:mv, :env) == :test do
if Application.get_env(:mv, :sql_sandbox, false) do
# Run synchronously in test environment for DB sandbox compatibility
Mv.MembershipFees.CycleGenerator.generate_cycles_for_member(member.id)
else
@ -180,7 +180,7 @@ defmodule Mv.Membership.Member do
Ash.Changeset.changing_attribute?(changeset, :membership_fee_type_id)
if fee_type_changed && member.membership_fee_type_id && member.join_date do
if Application.get_env(:mv, :env) == :test do
if Application.get_env(:mv, :sql_sandbox, false) do
# Run synchronously in test environment for DB sandbox compatibility
Mv.MembershipFees.CycleGenerator.generate_cycles_for_member(member.id)
else