fix(test): self-provision the fixture user in ai_credits_reaper.rs
Some checks failed
build-and-release / build (cron) (push) Successful in 1m0s
build-and-release / build (catering-services) (push) Successful in 1m29s
build-and-release / build (companies) (push) Successful in 1m52s
build-and-release / build (customers) (push) Successful in 2m13s
build-and-release / build (employees) (push) Successful in 2m20s
build-and-release / build (gateway) (push) Successful in 1m1s
build-and-release / build (developers) (push) Successful in 3m9s
build-and-release / build (fitness-trainers) (push) Successful in 2m50s
build-and-release / build (job-seekers) (push) Successful in 1m54s
build-and-release / build (jobs) (push) Successful in 1m55s
build-and-release / build (graphic-designers) (push) Successful in 2m38s
build-and-release / build (makeup-artists) (push) Successful in 2m59s
build-and-release / build (photographers) (push) Successful in 1m52s
build-and-release / build (payments) (push) Successful in 2m45s
backend-integration-tests / ai-credits (push) Failing after 51s
build-and-release / build (social-media-managers) (push) Successful in 2m40s
build-and-release / build (tutors) (push) Successful in 2m51s
build-and-release / build (ugc-content-creators) (push) Successful in 2m53s
build-and-release / build (video-editors) (push) Has been cancelled
build-and-release / build (users) (push) Has been cancelled

expired_hold_is_swept_and_credits_return_to_available used a hardcoded
UUID assuming a matching users row already existed in whatever
database it ran against, but user_ai_subscriptions.user_id has a FK to
users(id) - against a fresh database (like CI's nxtgauge_test) this
failed with a foreign key violation before the actual sweep/release
logic under test ever ran. Provision it inline instead, matching
ai_credits.rs's make_user() pattern.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Ashwin Kumar Sivakumar 2026-08-13 21:52:54 +05:30
parent 1af10420ce
commit b48a1dd204

View file

@ -23,6 +23,17 @@ async fn expired_hold_is_swept_and_credits_return_to_available() {
let pool = pool().await;
let user_id = Uuid::parse_str("33333333-3333-3333-3333-333333333333").unwrap();
// user_ai_subscriptions.user_id has a FK to users(id) - this fixed UUID
// isn't a real seeded user in every environment this test might run
// against (e.g. a fresh CI database), so provision it here rather than
// assuming it pre-exists. Matches ai_credits.rs's make_user() pattern.
sqlx::query("INSERT INTO users (id, email, password_hash) VALUES ($1, $2, 'x') ON CONFLICT (id) DO NOTHING")
.bind(user_id)
.bind(format!("{user_id}@test.local"))
.execute(&pool)
.await
.unwrap();
AiCreditsRepository::ensure_wallet(&pool, user_id).await.unwrap();
let hold = AiCreditsRepository::try_reserve_credits(&pool, user_id, "help_answer", 4, None, None)