How to do integration tests for multiple umbrella applications?

I have an app composed of multiple umbrella subapplications: multiple domain applications that have their own database and ecto, one service app where the business logic is located and one plain phoenix app that calls the service methods.
They are tested individually by mocking any external dependency. Recently I realised that when I integrate them all the things start crashing. So I want to also do some round of integration tests. I added one inside the phoenix umbrella because it uses all the others.
I do not know how to make it work though :frowning:.

I have a test that goes like this:

setup_all do
IO.puts("~~~~~~~Changing mock to real implementations:")
Application.put_env(:carts_api, :carts_service, Carts.Service)
Application.put_env(:carts_service, :shopping_domain, Shopping.Domain)
Application.put_env(:carts_service, :restaurants_domain, Restaurants.Domain.Service)
Application.put_env(:carts_service, :users_domain, Users.Domain)

Sandbox.mode(UsersRepo, :manual)
Sandbox.mode(RestaurantsRepo, :manual)
Sandbox.mode(ShoppingRepo, :manual)

on_exit(fn ->
  IO.puts("~~~~~~~Changing back to mock injection:")
  Application.put_env(:carts_api, :carts_service, Carts.ApiWeb.CartsServiceMock)
  Application.put_env(:carts_service, :shopping_domain, Carts.ShoppingDomainMock)
  Application.put_env(:carts_service, :restaurants_domain, Carts.RestaurantsDomainMock)
  Application.put_env(:carts_service, :users_domain, Carts.UsersDomainMock)
end)

end

What I am trying to do here basically is to replace all test versions of the dependencies with real ones and at the end to put them back.
Everything works fine locally since I have the test databases created but fails on CI:

13:15:58.921 [error] Postgrex.Protocol (#PID<0.949.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name): database "users-test" does not exist

So what I am trying to do is to create all test databases in setup block.

Does anyone knows how I can do it? Of is this the right approach to integration testing?

1 Like