Skip to content

Add database-backed integration test infrastructure - #423

Merged
ddon merged 2 commits into
BeamLabEU:devfrom
mdon:dev
Mar 17, 2026
Merged

Add database-backed integration test infrastructure#423
ddon merged 2 commits into
BeamLabEU:devfrom
mdon:dev

Conversation

@mdon

@mdon mdon commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add embedded test repo (PhoenixKit.Test.Repo) with Ecto sandbox for library-level integration testing — no parent app required
  • Add 274 integration tests covering the user system (152 tests) and publishing module (120 tests), plus 2 DB smoke tests
  • Graceful degradation: unit tests still run when PostgreSQL is unavailable (274 tests auto-excluded with clear message)
  • Fix two production bugs in publishing db_storage.ex found by integration tests
  • Update CI to run mix test.setup before tests
  • Add review documentation for trash_post bypass and translation naming

What changed

Test infrastructure:

  • test/support/test_repo.ex — embedded Ecto repo pointing at phoenix_kit_test DB
  • test/support/postgres/migrations/ — migration wrapper calling PhoenixKit.Migrations.up()
  • config/test.exs — DB config with sandbox pool
  • test/test_helper.exs — DB detection, graceful degradation, service startup
  • test/support/data_case.ex — activated sandbox, @moduletag :integration for auto-exclusion
  • mix.exsmix test.setup / mix test.reset aliases

User system integration tests (152):

  • Registration, guest users, username/email lookups
  • Authentication via email and username, session tokens, fingerprinting
  • Email confirmation and email change workflows
  • Password update, admin reset, reset-via-token
  • Profile updates, custom fields, user status with Owner protection
  • Role CRUD (including custom roles), assign/remove, promote/demote
  • Permissions: grant/revoke/copy/set, Scope integration, permission matrix

Publishing integration tests (120):

  • Group CRUD, trash/restore, force-delete cascade
  • Post creation in timestamp and slug modes, read with version/language params
  • Version cloning, publish (archives previous), delete constraints
  • Multi-language: add/delete languages, translation status propagation
  • End-to-end workflows: create → edit → publish → read

Bug fixes:

  • db_storage.ex: FOR UPDATE cannot be combined with aggregate functions in PostgreSQL — fixed by selecting rows then computing max in Elixir
  • db_storage.ex: DateTime.utc_now() returns microseconds but insert_all into :utc_datetime columns rejects them — fixed with DateTime.truncate(:second)

Other:

  • Remove 7 dead should_regenerate_cache? tests (function was deleted)
  • Fix rate_limiter_test.exs ETS table-exists crash when backend already running
  • Update AGENTS.md with full testing documentation

mdon and others added 2 commits March 17, 2026 15:25
…naming

- Add comment explaining why trash_post uses Ecto.Changeset.change
  instead of the full changeset (avoids slug validation on nil slugs)
- Fix misleading README comment that called delete_language a hard-delete
  (it archives; clear_translation is the hard-delete)
- Add clear_translation usage example to README
- Add future refactoring note about rename: clear_translation →
  hard_delete_translation, delete_language → archive_translation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…on tests

Set up embedded test repo (PhoenixKit.Test.Repo) with Ecto sandbox for
library-level integration testing without requiring the parent app.
Tests gracefully degrade — unit tests still run when PostgreSQL is unavailable.

User system tests (152): registration, authentication, sessions, email
confirmation, email change, password management, profiles, custom fields,
roles (including custom role CRUD), permissions (including grant_all,
copy, matrix operations), and Scope integration.

Publishing module tests (120): group CRUD and lifecycle, post creation
in both timestamp and slug modes, versioning with clone/publish/archive,
multi-language translations with status propagation, and end-to-end
workflows.

Fix two production bugs found by integration tests:
- db_storage.ex: FOR UPDATE with aggregate function (PostgreSQL error)
- db_storage.ex: DateTime microseconds in insert_all for content cloning

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ddon
ddon merged commit d975ce6 into BeamLabEU:dev Mar 17, 2026
6 checks passed
ddon added a commit that referenced this pull request Mar 17, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants