Extract DB queries from MaintenanceLive into context

This commit is contained in:
Claudio Ortolina
2026-03-05 18:01:50 +00:00
parent 4b1f6bb245
commit d4376e5fa0
4 changed files with 75 additions and 22 deletions
+26
View File
@@ -0,0 +1,26 @@
defmodule MusicLibrary.MaintenanceTest do
use MusicLibrary.DataCase
alias MusicLibrary.Maintenance
describe "vacuum/0" do
test "delegates to Repo.vacuum/0" do
# VACUUM cannot run inside the Ecto sandbox transaction,
# so we verify it attempts the operation and returns the expected tuple shape.
assert {:error, %Exqlite.Error{message: "cannot VACUUM from within a transaction"}} =
Maintenance.vacuum()
end
end
describe "optimize/0" do
test "returns {:ok, _}" do
assert {:ok, _} = Maintenance.optimize()
end
end
describe "count_active_jobs/1" do
test "returns 0 for a worker with no jobs" do
assert Maintenance.count_active_jobs("MusicLibrary.Worker.NonExistent") == 0
end
end
end