diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 75ea4977..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: CI - -on: push - -jobs: - test: - name: tests - runs-on: ubuntu-latest - strategy: - fail-fast: false - steps: - - uses: earthly/actions/setup-earthly@v1 - with: - version: v0.5.10 - - uses: actions/checkout@v2 - - - name: Login to GHCR - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: Solfacil - password: ${{ secrets.REGISTRY_PERSONAL_TOKEN }} - - - name: pipeline - run: earthly -P --ci +all - diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml new file mode 100644 index 00000000..22a94252 --- /dev/null +++ b/.github/workflows/elixir.yml @@ -0,0 +1,215 @@ +name: Elixir CI + +on: push + +jobs: + deps: + runs-on: ubuntu-latest + env: + MIX_ENV: test + strategy: + matrix: + elixir: [1.13.4] + otp: [24.1.6] + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.6.0 + with: + access_token: ${{ github.token }} + + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup + uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + + - name: Retrieve Cached Dependencies + uses: actions/cache@v2 + id: mix-cache + with: + path: | + deps + _build + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }} + + - name: Install Dependencies + run: | + mix local.rebar --force + mix local.hex --force + mix deps.get + mix deps.compile + + format: + runs-on: ubuntu-latest + needs: deps + strategy: + matrix: + elixir: [1.13.4] + otp: [24.1.6] + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.6.0 + with: + access_token: ${{ github.token }} + + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup + uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + + - name: Retrieve Cached Dependencies + uses: actions/cache@v2 + id: mix-cache + with: + path: | + deps + _build + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }} + + - name: Run Formater + run: mix format --check-formatted + + static_code_analysis: + runs-on: ubuntu-latest + needs: deps + strategy: + matrix: + elixir: [1.13.4] + otp: [24.1.6] + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.6.0 + with: + access_token: ${{ github.token }} + + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup + uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + + - name: Retrieve Cached Dependencies + uses: actions/cache@v2 + id: mix-cache + with: + path: | + deps + _build + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }} + + - name: Run Credo + run: mix credo --strict + + unit_tests: + runs-on: ubuntu-latest + needs: deps + strategy: + matrix: + elixir: [1.13.4] + otp: [24.1.6] + services: + db: + env: + POSTGRES_USER: pescarte + POSTGRES_PASSWORD: pescarte + POSTGRES_DB: fuschia_test + image: postgres:13.5 + ports: ['5432:5432'] + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.6.0 + with: + access_token: ${{ github.token }} + + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup + uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + + - name: Retrieve Cached Dependencies + uses: actions/cache@v2 + id: mix-cache + with: + path: | + deps + _build + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }} + + - name: Run Unit Tests + run: mix test --only unit + + integration_tests: + runs-on: ubuntu-latest + needs: deps + strategy: + matrix: + elixir: [1.13.4] + otp: [24.1.6] + services: + db: + env: + POSTGRES_USER: pescarte + POSTGRES_PASSWORD: pescarte + POSTGRES_DB: fuschia_test + image: postgres:13.5 + ports: ['5432:5432'] + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.6.0 + with: + access_token: ${{ github.token }} + + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup + uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + + - name: Retrieve Cached Dependencies + uses: actions/cache@v2 + id: mix-cache + with: + path: | + deps + _build + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }} + + - name: Run Integration Tests + run: mix test --only integration diff --git a/lib/fuschia/accounts/accounts.ex b/lib/fuschia/accounts/accounts.ex index 9dcad72d..db685529 100644 --- a/lib/fuschia/accounts/accounts.ex +++ b/lib/fuschia/accounts/accounts.ex @@ -7,10 +7,14 @@ defmodule Fuschia.Accounts do alias Fuschia.Repo - alias Fuschia.Accounts.Logic.{UserLogic, UserTokenLogic} - alias Fuschia.Accounts.Models.{AuthLogModel, UserModel, UserTokenModel} + alias Fuschia.Accounts.Logic.User, as: UserLogic + alias Fuschia.Accounts.Logic.UserToken, as: UserTokenLogic + alias Fuschia.Accounts.Models.AuthLog + alias Fuschia.Accounts.Models.User, as: UserModel + alias Fuschia.Accounts.Models.UserToken, as: UserTokenModel alias Fuschia.Accounts.Queries - alias Fuschia.Accounts.Queries.{UserQueries, UserTokenQueries} + alias Fuschia.Accounts.Queries.User, as: UserQueries + alias Fuschia.Accounts.Queries.UserToken, as: UserTokenQueries alias Fuschia.Accounts.UserNotifier alias Fuschia.Database @@ -135,8 +139,8 @@ defmodule Fuschia.Accounts do @spec create_auth_log(map) :: :ok def create_auth_log(attrs) do - %AuthLogModel{} - |> AuthLogModel.changeset(attrs) + %AuthLog{} + |> AuthLog.changeset(attrs) |> Database.insert() :ok diff --git a/lib/fuschia/accounts/adapters/contato.ex b/lib/fuschia/accounts/adapters/contato.ex index 6e7ba6e7..a1b419e8 100644 --- a/lib/fuschia/accounts/adapters/contato.ex +++ b/lib/fuschia/accounts/adapters/contato.ex @@ -1,9 +1,9 @@ -defmodule Fuschia.Accounts.Adapters.ContatoAdapter do +defmodule Fuschia.Accounts.Adapters.Contato do @moduledoc false - alias Fuschia.Accounts.Models.ContatoModel + alias Fuschia.Accounts.Models.Contato - def to_map(%ContatoModel{} = struct) do + def to_map(%Contato{} = struct) do %{ id: struct.id, celular: struct.celular, diff --git a/lib/fuschia/accounts/adapters/user.ex b/lib/fuschia/accounts/adapters/user.ex index 234aa057..f8c677f2 100644 --- a/lib/fuschia/accounts/adapters/user.ex +++ b/lib/fuschia/accounts/adapters/user.ex @@ -1,12 +1,12 @@ -defmodule Fuschia.Accounts.Adapters.UserAdapter do +defmodule Fuschia.Accounts.Adapters.User do @moduledoc """ Define funções que convertem um usuário para outros schemas ou mapas """ - alias Fuschia.Accounts.Models.UserModel + alias Fuschia.Accounts.Models.User - def for_jwt(%UserModel{} = struct) do + def for_jwt(%User{} = struct) do %{ email: struct.contato.email, endereco: struct.contato.endereco, @@ -20,7 +20,7 @@ defmodule Fuschia.Accounts.Adapters.UserAdapter do } end - def to_map(%UserModel{} = struct) do + def to_map(%User{} = struct) do %{ nome_completo: struct.nome_completo, perfil: struct.role, diff --git a/lib/fuschia/accounts/logic/contato.ex b/lib/fuschia/accounts/logic/contato.ex index 87641740..6f5dd687 100644 --- a/lib/fuschia/accounts/logic/contato.ex +++ b/lib/fuschia/accounts/logic/contato.ex @@ -1,4 +1,4 @@ -defmodule Fuschia.Accounts.Logic.ContatoLogic do +defmodule Fuschia.Accounts.Logic.Contato do @moduledoc false import Ecto.Changeset, diff --git a/lib/fuschia/accounts/logic/user.ex b/lib/fuschia/accounts/logic/user.ex index e6a29bd3..c5b57d29 100644 --- a/lib/fuschia/accounts/logic/user.ex +++ b/lib/fuschia/accounts/logic/user.ex @@ -1,16 +1,16 @@ -defmodule Fuschia.Accounts.Logic.UserLogic do +defmodule Fuschia.Accounts.Logic.User do @moduledoc false import Ecto.Changeset, only: [add_error: 3] - alias Fuschia.Accounts.Models.UserModel + alias Fuschia.Accounts.Models.User @doc """ Verifica a senha. Se não houver usuário ou o usuário não tiver uma senha, chamamos `Bcrypt.no_user_verify/0` para evitar ataques de tempo. """ - def valid_password?(%UserModel{password_hash: password_hash}, password) + def valid_password?(%User{password_hash: password_hash}, password) when is_binary(password_hash) and byte_size(password) > 0 do Bcrypt.verify_pass(password, password_hash) end @@ -31,7 +31,7 @@ defmodule Fuschia.Accounts.Logic.UserLogic do end end - def put_permissions(%UserModel{} = user) do + def put_permissions(%User{} = user) do # TODO Map.put(user, :permissoes, nil) end diff --git a/lib/fuschia/accounts/logic/user_token.ex b/lib/fuschia/accounts/logic/user_token.ex index cae97501..8f082745 100644 --- a/lib/fuschia/accounts/logic/user_token.ex +++ b/lib/fuschia/accounts/logic/user_token.ex @@ -1,9 +1,9 @@ -defmodule Fuschia.Accounts.Logic.UserTokenLogic do +defmodule Fuschia.Accounts.Logic.UserToken do @moduledoc """ Regras de negócio para tokens de Usuário """ - alias Fuschia.Accounts.Models.UserTokenModel + alias Fuschia.Accounts.Models.UserToken @hash_algorithm :sha256 @rand_size 32 @@ -29,7 +29,7 @@ defmodule Fuschia.Accounts.Logic.UserTokenLogic do """ def build_session_token(user) do token = :crypto.strong_rand_bytes(@rand_size) - {token, %UserTokenModel{token: token, context: "session", user_cpf: user.cpf}} + {token, %UserToken{token: token, context: "session", user_cpf: user.cpf}} end @doc """ @@ -55,7 +55,7 @@ defmodule Fuschia.Accounts.Logic.UserTokenLogic do hashed_token = :crypto.hash(@hash_algorithm, token) {Base.url_encode64(token, padding: false), - %UserTokenModel{ + %UserToken{ token: hashed_token, context: context, sent_to: sent_to, diff --git a/lib/fuschia/accounts/models/api_key.ex b/lib/fuschia/accounts/models/api_key.ex index fabe241c..d08b2e81 100644 --- a/lib/fuschia/accounts/models/api_key.ex +++ b/lib/fuschia/accounts/models/api_key.ex @@ -1,4 +1,4 @@ -defmodule Fuschia.Accounts.Models.ApiKeyModel do +defmodule Fuschia.Accounts.Models.ApiKey do @moduledoc """ API Key Schema """ diff --git a/lib/fuschia/accounts/models/auth_log.ex b/lib/fuschia/accounts/models/auth_log.ex index ba74e538..9a4a4aed 100644 --- a/lib/fuschia/accounts/models/auth_log.ex +++ b/lib/fuschia/accounts/models/auth_log.ex @@ -1,4 +1,4 @@ -defmodule Fuschia.Accounts.Models.AuthLogModel do +defmodule Fuschia.Accounts.Models.AuthLog do @moduledoc """ Authentication log """ @@ -7,7 +7,7 @@ defmodule Fuschia.Accounts.Models.AuthLogModel do import Ecto.Changeset - alias Fuschia.Accounts.Models.UserModel + alias Fuschia.Accounts.Models.User alias Fuschia.Types.TrimmedString @required_fields ~w(ip user_agent user_cpf)a @@ -17,7 +17,7 @@ defmodule Fuschia.Accounts.Models.AuthLogModel do field :ip, TrimmedString field :user_agent, TrimmedString - belongs_to :user, UserModel, foreign_key: :user_cpf, references: :cpf + belongs_to :user, User, foreign_key: :user_cpf, references: :cpf timestamps(updated_at: false) end diff --git a/lib/fuschia/accounts/models/contato.ex b/lib/fuschia/accounts/models/contato.ex index 5f17cb7a..57d8705b 100644 --- a/lib/fuschia/accounts/models/contato.ex +++ b/lib/fuschia/accounts/models/contato.ex @@ -1,4 +1,4 @@ -defmodule Fuschia.Accounts.Models.ContatoModel do +defmodule Fuschia.Accounts.Models.Contato do @moduledoc """ Contato schema """ @@ -7,7 +7,7 @@ defmodule Fuschia.Accounts.Models.ContatoModel do import Ecto.Changeset - alias Fuschia.Accounts.Logic.ContatoLogic + alias Fuschia.Accounts.Logic.Contato alias Fuschia.Common.Formats @required_fields ~w(email endereco celular)a @@ -29,16 +29,16 @@ defmodule Fuschia.Accounts.Models.ContatoModel do |> cast(attrs, @required_fields) |> validate_required(@required_fields) |> validate_format(:celular, @mobile_format) - |> ContatoLogic.validate_email() + |> Contato.validate_email() end defimpl Jason.Encoder, for: __MODULE__ do - alias Fuschia.Accounts.Adapters.ContatoAdapter + alias Fuschia.Accounts.Adapters.Contato @spec encode(Contato.t(), map) :: map def encode(struct, opts) do struct - |> ContatoAdapter.to_map() + |> Contato.to_map() |> Fuschia.Encoder.encode(opts) end end diff --git a/lib/fuschia/accounts/models/user.ex b/lib/fuschia/accounts/models/user.ex index 67c79f37..e8b9dc4b 100644 --- a/lib/fuschia/accounts/models/user.ex +++ b/lib/fuschia/accounts/models/user.ex @@ -1,4 +1,4 @@ -defmodule Fuschia.Accounts.Models.UserModel do +defmodule Fuschia.Accounts.Models.User do @moduledoc """ Schema que representa um usuário do sistema. @@ -13,8 +13,8 @@ defmodule Fuschia.Accounts.Models.UserModel do import Ecto.Changeset import FuschiaWeb.Gettext - alias Fuschia.Accounts.Logic.ContatoLogic - alias Fuschia.Accounts.Models.ContatoModel + alias Fuschia.Accounts.Logic.Contato, as: ContatoLogic + alias Fuschia.Accounts.Models.Contato, as: ContatoModel alias Fuschia.Types.{CapitalizedString, TrimmedString} @required_fields ~w(nome_completo cpf data_nascimento)a @@ -183,12 +183,12 @@ defmodule Fuschia.Accounts.Models.UserModel do end defimpl Jason.Encoder, for: User do - alias Fuschia.Accounts.Adapters.UserAdapter + alias Fuschia.Accounts.Adapters.User @spec encode(User.t(), map) :: map def encode(struct, opts) do struct - |> UserAdapter.to_map() + |> User.to_map() |> Fuschia.Encoder.encode(opts) end end diff --git a/lib/fuschia/accounts/models/user_token.ex b/lib/fuschia/accounts/models/user_token.ex index 270c55f3..f14e6b4e 100644 --- a/lib/fuschia/accounts/models/user_token.ex +++ b/lib/fuschia/accounts/models/user_token.ex @@ -1,4 +1,4 @@ -defmodule Fuschia.Accounts.Models.UserTokenModel do +defmodule Fuschia.Accounts.Models.UserToken do @moduledoc """ Schema que representa tokens de usuários. @@ -10,7 +10,7 @@ defmodule Fuschia.Accounts.Models.UserTokenModel do use Fuschia.Schema - alias Fuschia.Accounts.Models.UserModel + alias Fuschia.Accounts.Models.User alias Fuschia.Types.TrimmedString schema "user_token" do @@ -18,7 +18,7 @@ defmodule Fuschia.Accounts.Models.UserTokenModel do field :context, :string field :sent_to, :string - belongs_to :user, UserModel, + belongs_to :user, User, foreign_key: :user_cpf, references: :cpf, type: TrimmedString diff --git a/lib/fuschia/accounts/queries/api_key.ex b/lib/fuschia/accounts/queries/api_key.ex index 3adbbef4..7a086b02 100644 --- a/lib/fuschia/accounts/queries/api_key.ex +++ b/lib/fuschia/accounts/queries/api_key.ex @@ -1,17 +1,17 @@ -defmodule Fuschia.Accounts.Queries.ApiKeyQueries do +defmodule Fuschia.Accounts.Queries.ApiKey do @moduledoc """ Queries para interagir com `ApiKey` """ import Ecto.Query, only: [from: 2] - alias Fuschia.Accounts.Models.ApiKeyModel + alias Fuschia.Accounts.Models.ApiKey @behaviour Fuschia.Query @impl true def query do - from a in ApiKeyModel, + from a in ApiKey, where: a.active == true end diff --git a/lib/fuschia/accounts/queries/user.ex b/lib/fuschia/accounts/queries/user.ex index b6c477b5..43d206b3 100644 --- a/lib/fuschia/accounts/queries/user.ex +++ b/lib/fuschia/accounts/queries/user.ex @@ -1,15 +1,15 @@ -defmodule Fuschia.Accounts.Queries.UserQueries do +defmodule Fuschia.Accounts.Queries.User do @moduledoc false import Ecto.Query, only: [from: 2, where: 3, order_by: 3, limit: 2] - alias Fuschia.Accounts.Models.UserModel + alias Fuschia.Accounts.Models.User @behaviour Fuschia.Query @impl true def query do - from u in UserModel, + from u in User, left_join: contato in assoc(u, :contato), order_by: [desc: u.inserted_at] end diff --git a/lib/fuschia/accounts/queries/user_token.ex b/lib/fuschia/accounts/queries/user_token.ex index edea9e4e..c7248dfa 100644 --- a/lib/fuschia/accounts/queries/user_token.ex +++ b/lib/fuschia/accounts/queries/user_token.ex @@ -1,9 +1,9 @@ -defmodule Fuschia.Accounts.Queries.UserTokenQueries do +defmodule Fuschia.Accounts.Queries.UserToken do @moduledoc false import Ecto.Query - alias Fuschia.Accounts.Models.UserTokenModel + alias Fuschia.Accounts.Models.UserToken @hash_algorithm :sha256 @@ -102,17 +102,17 @@ defmodule Fuschia.Accounts.Queries.UserTokenQueries do Retorna a estrutura de token para o valor e o contexto de token fornecidos. """ def token_and_context_query(token, context) do - from UserTokenModel, where: [token: ^token, context: ^context] + from UserToken, where: [token: ^token, context: ^context] end @doc """ Obtém todos os tokens do usuário fornecido para os contextos fornecidos. """ def user_and_contexts_query(user, :all) do - from t in UserTokenModel, where: t.user_cpf == ^user.cpf + from t in UserToken, where: t.user_cpf == ^user.cpf end def user_and_contexts_query(user, [_ | _] = contexts) do - from t in UserTokenModel, where: t.user_cpf == ^user.cpf and t.context in ^contexts + from t in UserToken, where: t.user_cpf == ^user.cpf and t.context in ^contexts end end diff --git a/lib/fuschia/database.ex b/lib/fuschia/database.ex index 313e53e5..3deff6ce 100644 --- a/lib/fuschia/database.ex +++ b/lib/fuschia/database.ex @@ -338,9 +338,9 @@ defmodule Fuschia.Database do iex> update(%Modulo{}, invalid_params) {:error, failed_operation, failed_value, changes_so_far} """ - @spec update(struct, map) :: {:ok, struct} | {:error, changeset} + @spec update(struct, map, fun) :: {:ok, struct} | {:error, changeset} def update(%mod{} = struct, attrs, change_fun \\ :changeset) do - change_fun = if change_fun == :changeset, do: &mod.changeset/3, else: change_fun + change_fun = if change_fun == :changeset, do: &mod.changeset/2, else: change_fun with %Ecto.Changeset{valid?: true} = changeset <- change_fun.(struct, attrs), @@ -385,7 +385,7 @@ defmodule Fuschia.Database do change_fun = Keyword.get(opts, :change_fun, :changeset) with {:ok, entity} <- update(struct, attrs, change_fun), - ^struct = preloaded <- + %^source{} = preloaded <- preload_all(entity, entity_query_mod.relationships()) do {:ok, preloaded} end @@ -516,8 +516,7 @@ defmodule Fuschia.Database do end defp get_queries_mod(opts, mod) do - suffix = - mod |> to_string() |> String.split(".") |> List.last() |> String.replace("Model", "Queries") + suffix = mod |> to_string() |> String.split(".") |> List.last() opts |> Keyword.get(:queries_mod) diff --git a/lib/fuschia/modulo_pesquisa/adapters/campus.ex b/lib/fuschia/modulo_pesquisa/adapters/campus.ex index ef250118..b25a7c96 100644 --- a/lib/fuschia/modulo_pesquisa/adapters/campus.ex +++ b/lib/fuschia/modulo_pesquisa/adapters/campus.ex @@ -1,9 +1,9 @@ -defmodule Fuschia.ModuloPesquisa.Adapters.CampusAdapter do +defmodule Fuschia.ModuloPesquisa.Adapters.Campus do @moduledoc false - alias Fuschia.ModuloPesquisa.Models.CampusModel + alias Fuschia.ModuloPesquisa.Models.Campus - def to_map(%CampusModel{} = struct) do + def to_map(%Campus{} = struct) do %{ id: struct.id, nome: struct.nome, diff --git a/lib/fuschia/modulo_pesquisa/adapters/cidade.ex b/lib/fuschia/modulo_pesquisa/adapters/cidade.ex index ce78c5b9..f081d101 100644 --- a/lib/fuschia/modulo_pesquisa/adapters/cidade.ex +++ b/lib/fuschia/modulo_pesquisa/adapters/cidade.ex @@ -1,9 +1,9 @@ -defmodule Fuschia.ModuloPesquisa.Adapters.CidadeAdapter do +defmodule Fuschia.ModuloPesquisa.Adapters.Cidade do @moduledoc false - alias Fuschia.ModuloPesquisa.Models.CidadeModel + alias Fuschia.ModuloPesquisa.Models.Cidade - def to_map(%CidadeModel{} = struct) do + def to_map(%Cidade{} = struct) do %{ id: struct.id, municipio: struct.municipio, diff --git a/lib/fuschia/modulo_pesquisa/adapters/linha_pesquisa.ex b/lib/fuschia/modulo_pesquisa/adapters/linha_pesquisa.ex index c013fa5d..420ca45b 100644 --- a/lib/fuschia/modulo_pesquisa/adapters/linha_pesquisa.ex +++ b/lib/fuschia/modulo_pesquisa/adapters/linha_pesquisa.ex @@ -1,9 +1,9 @@ -defmodule Fuschia.ModuloPesquisa.Adapters.LinhaPesquisaAdapter do +defmodule Fuschia.ModuloPesquisa.Adapters.LinhaPesquisa do @moduledoc false - alias Fuschia.ModuloPesquisa.Models.LinhaPesquisaModel + alias Fuschia.ModuloPesquisa.Models.LinhaPesquisa - def to_map(%LinhaPesquisaModel{} = struct) do + def to_map(%LinhaPesquisa{} = struct) do %{ id: struct.id, descricao_curta: struct.descricao_curta, diff --git a/lib/fuschia/modulo_pesquisa/adapters/midia.ex b/lib/fuschia/modulo_pesquisa/adapters/midia.ex index 9d218a0f..923ede1d 100644 --- a/lib/fuschia/modulo_pesquisa/adapters/midia.ex +++ b/lib/fuschia/modulo_pesquisa/adapters/midia.ex @@ -1,9 +1,9 @@ -defmodule Fuschia.ModuloPesquisa.Adapters.MidiaAdapter do +defmodule Fuschia.ModuloPesquisa.Adapters.Midia do @moduledoc false - alias Fuschia.ModuloPesquisa.Models.MidiaModel + alias Fuschia.ModuloPesquisa.Models.Midia - def to_map(%MidiaModel{} = struct) do + def to_map(%Midia{} = struct) do %{ id: struct.id, tipo: struct.tipo, diff --git a/lib/fuschia/modulo_pesquisa/adapters/nucleo.ex b/lib/fuschia/modulo_pesquisa/adapters/nucleo.ex index 35591f9f..2dbf8544 100644 --- a/lib/fuschia/modulo_pesquisa/adapters/nucleo.ex +++ b/lib/fuschia/modulo_pesquisa/adapters/nucleo.ex @@ -1,9 +1,9 @@ -defmodule Fuschia.ModuloPesquisa.Adapters.NucleoAdapter do +defmodule Fuschia.ModuloPesquisa.Adapters.Nucleo do @moduledoc false - alias Fuschia.ModuloPesquisa.Models.NucleoModel + alias Fuschia.ModuloPesquisa.Models.Nucleo - def to_map(%NucleoModel{} = struct) do + def to_map(%Nucleo{} = struct) do %{ id: struct.id, nome: struct.nome, diff --git a/lib/fuschia/modulo_pesquisa/adapters/pesquisador.ex b/lib/fuschia/modulo_pesquisa/adapters/pesquisador.ex index 2998ea08..527942b2 100644 --- a/lib/fuschia/modulo_pesquisa/adapters/pesquisador.ex +++ b/lib/fuschia/modulo_pesquisa/adapters/pesquisador.ex @@ -1,9 +1,9 @@ -defmodule Fuschia.ModuloPesquisa.Adapters.PesquisadorAdapter do +defmodule Fuschia.ModuloPesquisa.Adapters.Pesquisador do @moduledoc false - alias Fuschia.ModuloPesquisa.Models.PesquisadorModel + alias Fuschia.ModuloPesquisa.Models.Pesquisador - def to_map(%PesquisadorModel{} = struct) do + def to_map(%Pesquisador{} = struct) do %{ id: struct.id, cpf: struct.usuario_cpf, diff --git a/lib/fuschia/modulo_pesquisa/adapters/relatorio.ex b/lib/fuschia/modulo_pesquisa/adapters/relatorio.ex index 27dcb6ae..c96820b3 100644 --- a/lib/fuschia/modulo_pesquisa/adapters/relatorio.ex +++ b/lib/fuschia/modulo_pesquisa/adapters/relatorio.ex @@ -1,9 +1,9 @@ -defmodule Fuschia.ModuloPesquisa.Adapters.RelatorioAdapter do +defmodule Fuschia.ModuloPesquisa.Adapters.Relatorio do @moduledoc false - alias Fuschia.ModuloPesquisa.Models.RelatorioModel + alias Fuschia.ModuloPesquisa.Models.Relatorio - def to_map(%RelatorioModel{} = struct) do + def to_map(%Relatorio{} = struct) do %{ id: struct.id, ano: struct.ano, diff --git a/lib/fuschia/modulo_pesquisa/logic/relatorio.ex b/lib/fuschia/modulo_pesquisa/logic/relatorio.ex index 1950e9a0..fc19aee5 100644 --- a/lib/fuschia/modulo_pesquisa/logic/relatorio.ex +++ b/lib/fuschia/modulo_pesquisa/logic/relatorio.ex @@ -1,4 +1,4 @@ -defmodule Fuschia.ModuloPesquisa.Logic.RelatorioLogic do +defmodule Fuschia.ModuloPesquisa.Logic.Relatorio do @moduledoc false import FuschiaWeb.Gettext diff --git a/lib/fuschia/modulo_pesquisa/models/campus.ex b/lib/fuschia/modulo_pesquisa/models/campus.ex index c3ae5898..680ec1f4 100644 --- a/lib/fuschia/modulo_pesquisa/models/campus.ex +++ b/lib/fuschia/modulo_pesquisa/models/campus.ex @@ -1,4 +1,4 @@ -defmodule Fuschia.ModuloPesquisa.Models.CampusModel do +defmodule Fuschia.ModuloPesquisa.Models.Campus do @moduledoc """ Campus Schema """ @@ -6,7 +6,7 @@ defmodule Fuschia.ModuloPesquisa.Models.CampusModel do use Fuschia.Schema import Ecto.Changeset - alias Fuschia.ModuloPesquisa.Models.{CidadeModel, PesquisadorModel} + alias Fuschia.ModuloPesquisa.Models.{Cidade, Pesquisador} alias Fuschia.Types.CapitalizedString @required_fields ~w(nome)a @@ -15,13 +15,13 @@ defmodule Fuschia.ModuloPesquisa.Models.CampusModel do schema "campus" do field :id, :string - belongs_to :cidade, CidadeModel, + belongs_to :cidade, Cidade, type: :string, on_replace: :delete, references: :municipio, foreign_key: :cidade_municipio - has_many :pesquisadores, PesquisadorModel, foreign_key: :campus_nome + has_many :pesquisadores, Pesquisador, foreign_key: :campus_nome timestamps() end @@ -47,12 +47,12 @@ defmodule Fuschia.ModuloPesquisa.Models.CampusModel do end defimpl Jason.Encoder, for: __MODULE__ do - alias Fuschia.ModuloPesquisa.Adapters.CampusAdapter + alias Fuschia.ModuloPesquisa.Adapters.Campus @spec encode(Campus.t(), map) :: map def encode(struct, opts) do struct - |> CampusAdapter.to_map() + |> Campus.to_map() |> Fuschia.Encoder.encode(opts) end end diff --git a/lib/fuschia/modulo_pesquisa/models/cidade.ex b/lib/fuschia/modulo_pesquisa/models/cidade.ex index ff6051fc..4d19c5c9 100644 --- a/lib/fuschia/modulo_pesquisa/models/cidade.ex +++ b/lib/fuschia/modulo_pesquisa/models/cidade.ex @@ -1,4 +1,4 @@ -defmodule Fuschia.ModuloPesquisa.Models.CidadeModel do +defmodule Fuschia.ModuloPesquisa.Models.Cidade do @moduledoc """ Cidade schema """ @@ -6,7 +6,7 @@ defmodule Fuschia.ModuloPesquisa.Models.CidadeModel do use Fuschia.Schema import Ecto.Changeset - alias Fuschia.ModuloPesquisa.Models.CampusModel + alias Fuschia.ModuloPesquisa.Models.Campus alias Fuschia.Types.CapitalizedString @required_fields ~w(municipio)a @@ -15,7 +15,7 @@ defmodule Fuschia.ModuloPesquisa.Models.CidadeModel do schema "cidade" do field :id, :string - has_many :campi, CampusModel, on_replace: :delete, foreign_key: :cidade_municipio + has_many :campi, Campus, on_replace: :delete, foreign_key: :cidade_municipio timestamps() end @@ -30,12 +30,12 @@ defmodule Fuschia.ModuloPesquisa.Models.CidadeModel do end defimpl Jason.Encoder, for: __MODULE__ do - alias Fuschia.ModuloPesquisa.Adapters.CidadeAdapter + alias Fuschia.ModuloPesquisa.Adapters.Cidade @spec encode(Cidade.t(), map) :: map def encode(struct, opts) do struct - |> CidadeAdapter.to_map() + |> Cidade.to_map() |> Fuschia.Encoder.encode(opts) end end diff --git a/lib/fuschia/modulo_pesquisa/models/linha_pesquisa.ex b/lib/fuschia/modulo_pesquisa/models/linha_pesquisa.ex index 0404acc0..f5f96d51 100644 --- a/lib/fuschia/modulo_pesquisa/models/linha_pesquisa.ex +++ b/lib/fuschia/modulo_pesquisa/models/linha_pesquisa.ex @@ -1,11 +1,11 @@ -defmodule Fuschia.ModuloPesquisa.Models.LinhaPesquisaModel do +defmodule Fuschia.ModuloPesquisa.Models.LinhaPesquisa do @moduledoc """ LinhaPesquisa schema """ use Fuschia.Schema import Ecto.Changeset - alias Fuschia.ModuloPesquisa.Models.NucleoModel + alias Fuschia.ModuloPesquisa.Models.Nucleo alias Fuschia.Types.{CapitalizedString, TrimmedString} @required_fields ~w(descricao_curta numero nucleo_nome)a @@ -17,7 +17,7 @@ defmodule Fuschia.ModuloPesquisa.Models.LinhaPesquisaModel do field :descricao_curta, TrimmedString field :descricao_longa, TrimmedString - belongs_to :nucleo, NucleoModel, + belongs_to :nucleo, Nucleo, references: :nome, foreign_key: :nucleo_nome, type: CapitalizedString @@ -38,12 +38,12 @@ defmodule Fuschia.ModuloPesquisa.Models.LinhaPesquisaModel do end defimpl Jason.Encoder, for: __MODULE__ do - alias Fuschia.ModuloPesquisa.Adapters.LinhaPesquisaAdapter + alias Fuschia.ModuloPesquisa.Adapters.LinhaPesquisa @spec encode(LinhaPesquisa.t(), map) :: map def encode(struct, opts) do struct - |> LinhaPesquisaAdapter.to_map() + |> LinhaPesquisa.to_map() |> Fuschia.Encoder.encode(opts) end end diff --git a/lib/fuschia/modulo_pesquisa/models/midia.ex b/lib/fuschia/modulo_pesquisa/models/midia.ex index 715e04bf..126a2dfd 100644 --- a/lib/fuschia/modulo_pesquisa/models/midia.ex +++ b/lib/fuschia/modulo_pesquisa/models/midia.ex @@ -1,4 +1,4 @@ -defmodule Fuschia.ModuloPesquisa.Models.MidiaModel do +defmodule Fuschia.ModuloPesquisa.Models.Midia do @moduledoc """ Midia Schema """ @@ -6,7 +6,7 @@ defmodule Fuschia.ModuloPesquisa.Models.MidiaModel do use Fuschia.Schema import Ecto.Changeset - alias Fuschia.ModuloPesquisa.Models.PesquisadorModel + alias Fuschia.ModuloPesquisa.Models.Pesquisador alias Fuschia.Types.TrimmedString @required_fields ~w( @@ -24,7 +24,7 @@ defmodule Fuschia.ModuloPesquisa.Models.MidiaModel do field :tipo, TrimmedString field :tags, {:array, TrimmedString} - belongs_to :pesquisador, PesquisadorModel, + belongs_to :pesquisador, Pesquisador, references: :usuario_cpf, foreign_key: :pesquisador_cpf, type: TrimmedString, @@ -45,12 +45,12 @@ defmodule Fuschia.ModuloPesquisa.Models.MidiaModel do end defimpl Jason.Encoder, for: __MODULE__ do - alias Fuschia.ModuloPesquisa.Adapters.MidiaAdapter + alias Fuschia.ModuloPesquisa.Adapters.Midia @spec encode(Midia.t(), map) :: map def encode(struct, opts) do struct - |> MidiaAdapter.to_map() + |> Midia.to_map() |> Fuschia.Encoder.encode(opts) end end diff --git a/lib/fuschia/modulo_pesquisa/models/nucleo.ex b/lib/fuschia/modulo_pesquisa/models/nucleo.ex index 008117b7..53a37334 100644 --- a/lib/fuschia/modulo_pesquisa/models/nucleo.ex +++ b/lib/fuschia/modulo_pesquisa/models/nucleo.ex @@ -1,11 +1,11 @@ -defmodule Fuschia.ModuloPesquisa.Models.NucleoModel do +defmodule Fuschia.ModuloPesquisa.Models.Nucleo do @moduledoc """ Nucleo schema """ use Fuschia.Schema import Ecto.Changeset - alias Fuschia.ModuloPesquisa.Models.LinhaPesquisaModel + alias Fuschia.ModuloPesquisa.Models.LinhaPesquisa alias Fuschia.Types.CapitalizedString @required_fields ~w(nome descricao)a @@ -15,7 +15,7 @@ defmodule Fuschia.ModuloPesquisa.Models.NucleoModel do field :id, :string field :descricao, :string - has_many :linhas_pesquisa, LinhaPesquisaModel, foreign_key: :nucleo_nome + has_many :linhas_pesquisa, LinhaPesquisa, foreign_key: :nucleo_nome timestamps() end @@ -31,12 +31,12 @@ defmodule Fuschia.ModuloPesquisa.Models.NucleoModel do end defimpl Jason.Encoder, for: __MODULE__ do - alias Fuschia.ModuloPesquisa.Adapters.NucleoAdapter + alias Fuschia.ModuloPesquisa.Adapters.Nucleo @spec encode(Nucleo.t(), map) :: map def encode(struct, opts) do struct - |> NucleoAdapter.to_map() + |> Nucleo.to_map() |> Fuschia.Encoder.encode(opts) end end diff --git a/lib/fuschia/modulo_pesquisa/models/pesquisador.ex b/lib/fuschia/modulo_pesquisa/models/pesquisador.ex index 7620bd6d..78102a8f 100644 --- a/lib/fuschia/modulo_pesquisa/models/pesquisador.ex +++ b/lib/fuschia/modulo_pesquisa/models/pesquisador.ex @@ -1,4 +1,4 @@ -defmodule Fuschia.ModuloPesquisa.Models.PesquisadorModel do +defmodule Fuschia.ModuloPesquisa.Models.Pesquisador do @moduledoc """ Pesquisador Schema """ @@ -6,8 +6,8 @@ defmodule Fuschia.ModuloPesquisa.Models.PesquisadorModel do use Fuschia.Schema import Ecto.Changeset - alias Fuschia.Accounts.Models.UserModel - alias Fuschia.ModuloPesquisa.Models.{CampusModel, MidiaModel, PesquisadorModel, RelatorioModel} + alias Fuschia.Accounts.Models.User + alias Fuschia.ModuloPesquisa.Models.{Campus, Midia, Pesquisador, Relatorio} alias Fuschia.Types.{CapitalizedString, TrimmedString} @required_fields ~w( @@ -28,13 +28,11 @@ defmodule Fuschia.ModuloPesquisa.Models.PesquisadorModel do field :tipo_bolsa, TrimmedString field :link_lattes, TrimmedString - has_many :orientandos, PesquisadorModel, foreign_key: :orientador_cpf + has_many :orientandos, Pesquisador, foreign_key: :orientador_cpf + has_many :midias, Midia, foreign_key: :pesquisador_cpf + has_many :relatorios, Relatorio, foreign_key: :pesquisador_cpf - has_many :midias, MidiaModel, foreign_key: :pesquisador_cpf - - has_many :relatorios, RelatorioModel, foreign_key: :pesquisador_cpf - - belongs_to :usuario, UserModel, + belongs_to :usuario, User, references: :cpf, foreign_key: :usuario_cpf, type: TrimmedString, @@ -42,12 +40,12 @@ defmodule Fuschia.ModuloPesquisa.Models.PesquisadorModel do define_field: false, on_replace: :update - belongs_to :campus, CampusModel, + belongs_to :campus, Campus, foreign_key: :campus_nome, references: :nome, type: CapitalizedString - belongs_to :orientador, PesquisadorModel, + belongs_to :orientador, Pesquisador, references: :usuario_cpf, foreign_key: :orientador_cpf, type: TrimmedString, @@ -64,7 +62,7 @@ defmodule Fuschia.ModuloPesquisa.Models.PesquisadorModel do |> validate_required(@required_fields) |> validate_length(:minibiografia, max: 280) |> validate_inclusion(:tipo_bolsa, @tipos_bolsa) - |> cast_assoc(:usuario, required: true, with: &UserModel.registration_changeset/2) + |> cast_assoc(:usuario, required: true, with: &User.registration_changeset/2) |> foreign_key_constraint(:orientador_cpf) |> foreign_key_constraint(:campus_nome) |> put_change(:id, Nanoid.generate()) @@ -83,12 +81,12 @@ defmodule Fuschia.ModuloPesquisa.Models.PesquisadorModel do end defimpl Jason.Encoder, for: __MODULE__ do - alias Fuschia.ModuloPesquisa.Adapters.PesquisadorAdapter + alias Fuschia.ModuloPesquisa.Adapters.Pesquisador @spec encode(Pesquisador.t(), map) :: map def encode(struct, opts) do struct - |> PesquisadorAdapter.to_map() + |> Pesquisador.to_map() |> Fuschia.Encoder.encode(opts) end end diff --git a/lib/fuschia/modulo_pesquisa/models/relatorio.ex b/lib/fuschia/modulo_pesquisa/models/relatorio.ex index 42d2f97c..2ed6690e 100644 --- a/lib/fuschia/modulo_pesquisa/models/relatorio.ex +++ b/lib/fuschia/modulo_pesquisa/models/relatorio.ex @@ -1,4 +1,4 @@ -defmodule Fuschia.ModuloPesquisa.Models.RelatorioModel do +defmodule Fuschia.ModuloPesquisa.Models.Relatorio do @moduledoc """ Relatorio Schema """ @@ -6,9 +6,9 @@ defmodule Fuschia.ModuloPesquisa.Models.RelatorioModel do use Fuschia.Schema import Ecto.Changeset - import Fuschia.ModuloPesquisa.Logic.RelatorioLogic + import Fuschia.ModuloPesquisa.Logic.Relatorio - alias Fuschia.ModuloPesquisa.Models.PesquisadorModel + alias Fuschia.ModuloPesquisa.Models.Pesquisador alias Fuschia.Types.TrimmedString @required_fields ~w( @@ -30,7 +30,7 @@ defmodule Fuschia.ModuloPesquisa.Models.RelatorioModel do field :tipo, TrimmedString field :link, TrimmedString - belongs_to :pesquisador, PesquisadorModel, + belongs_to :pesquisador, Pesquisador, references: :usuario_cpf, foreign_key: :pesquisador_cpf, type: TrimmedString, @@ -52,12 +52,12 @@ defmodule Fuschia.ModuloPesquisa.Models.RelatorioModel do end defimpl Jason.Encoder, for: __MODULE__ do - alias Fuschia.ModuloPesquisa.Adapters.RelatorioAdapter + alias Fuschia.ModuloPesquisa.Adapters.Relatorio @spec encode(Relatorio.t(), map) :: map def encode(struct, opts) do struct - |> RelatorioAdapter.to_map() + |> Relatorio.to_map() |> Fuschia.Encoder.encode(opts) end end diff --git a/lib/fuschia/modulo_pesquisa/modulo_pesquisa.ex b/lib/fuschia/modulo_pesquisa/modulo_pesquisa.ex index 27b4e049..119acaa8 100644 --- a/lib/fuschia/modulo_pesquisa/modulo_pesquisa.ex +++ b/lib/fuschia/modulo_pesquisa/modulo_pesquisa.ex @@ -5,16 +5,22 @@ defmodule Fuschia.ModuloPesquisa do """ import Fuschia.Database, - only: [create_and_preload: 3, list_entity: 2, get_entity: 3, update_and_preload: 3] + only: [ + create_and_preload: 3, + list_entity: 2, + get_entity: 3, + get_entity_by: 3, + update_and_preload: 3 + ] alias __MODULE__.Models.{ - CampusModel, - CidadeModel, - LinhaPesquisaModel, - MidiaModel, - NucleoModel, - PesquisadorModel, - RelatorioModel + Campus, + Cidade, + LinhaPesquisa, + Midia, + Nucleo, + Pesquisador, + Relatorio } alias __MODULE__.Queries @@ -23,111 +29,111 @@ defmodule Fuschia.ModuloPesquisa do # Database # ---------------------------# - def create_campus(attrs) do - with_queries_mod(&create_and_preload/3, [CampusModel, attrs]) + def create_campus(attrs, opts \\ []) do + with_queries_mod(&create_and_preload/3, [Campus, attrs], opts) end def list_campus do - with_queries_mod(&list_entity/2, [CampusModel]) + with_queries_mod(&list_entity/2, [Campus]) end def get_campus(id) do - with_queries_mod(&get_entity/3, [CampusModel, id]) + with_queries_mod(&get_entity/3, [Campus, id]) end ## Cidade def create_cidade(attrs) do - with_queries_mod(&create_and_preload/3, [CidadeModel, attrs]) + with_queries_mod(&create_and_preload/3, [Cidade, attrs]) end def get_cidade(id) do - with_queries_mod(&get_entity/3, [CidadeModel, id]) + with_queries_mod(&get_entity/3, [Cidade, id]) end ## LinhaPesquisa def create_linha_pesquisa(attrs) do - with_queries_mod(&create_and_preload/3, [LinhaPesquisaModel, attrs]) + with_queries_mod(&create_and_preload/3, [LinhaPesquisa, attrs]) end def list_linha_pesquisa do - with_queries_mod(&list_entity/2, [LinhaPesquisaModel]) + with_queries_mod(&list_entity/2, [LinhaPesquisa]) end def list_linha_pesquisa_by_nucleo(nucleo_id) do - with_queries_mod(&list_entity/2, [LinhaPesquisaModel], + with_queries_mod(&list_entity/2, [LinhaPesquisa], query_fun: :query_by_nucleo, query_args: nucleo_id ) end def get_linha_pesquisa(id) do - with_queries_mod(&get_entity/3, [LinhaPesquisaModel, id]) + with_queries_mod(&get_entity/3, [LinhaPesquisa, id]) end ## Midia def create_midia(attrs) do - with_queries_mod(&create_and_preload/3, [MidiaModel, attrs]) + with_queries_mod(&create_and_preload/3, [Midia, attrs]) end def list_midia do - with_queries_mod(&list_entity/2, [MidiaModel]) + with_queries_mod(&list_entity/2, [Midia]) end def get_midia(id) do - with_queries_mod(&get_entity/3, [MidiaModel, id]) + with_queries_mod(&get_entity/3, [Midia, id]) end - def update_midia(%MidiaModel{} = midia, attrs, change_fun \\ :changeset) do - with_queries_mod(&update_and_preload/3, [midia, attrs, change_fun: change_fun]) + def update_midia(%Midia{} = midia, attrs, change_fun \\ :changeset) do + with_queries_mod(&update_and_preload/3, [midia, attrs], change_fun: change_fun) end ## Nucleo def create_nucleo(attrs) do - with_queries_mod(&create_and_preload/3, [NucleoModel, attrs]) + with_queries_mod(&create_and_preload/3, [Nucleo, attrs]) end def list_nucleo do - with_queries_mod(&list_entity/2, [NucleoModel]) + with_queries_mod(&list_entity/2, [Nucleo]) end def get_nucleo(id) do - with_queries_mod(&get_entity/3, [NucleoModel, id]) + with_queries_mod(&get_entity/3, [Nucleo, id]) end - def update_nucleo(%NucleoModel{} = nucleo, attrs, change_fun \\ :changeset) do - with_queries_mod(&update_and_preload/3, [nucleo, attrs, change_fun: change_fun]) + def update_nucleo(%Nucleo{} = nucleo, attrs, change_fun \\ :changeset) do + with_queries_mod(&update_and_preload/3, [nucleo, attrs], change_fun: change_fun) end ## Pesquisador def create_pesquisador(attrs) do - with_queries_mod(&create_and_preload/3, [PesquisadorModel, attrs]) + with_queries_mod(&create_and_preload/3, [Pesquisador, attrs]) end def list_pesquisador do - with_queries_mod(&list_entity/2, [PesquisadorModel]) + with_queries_mod(&list_entity/2, [Pesquisador]) end def get_pesquisador(id) do - with_queries_mod(&get_entity/3, [PesquisadorModel, id]) + with_queries_mod(&get_entity/3, [Pesquisador, id]) end ## Relatorio def create_relatorio(attrs) do - with_queries_mod(&create_and_preload/3, [RelatorioModel, attrs]) + with_queries_mod(&create_and_preload/3, [Relatorio, attrs]) end def list_relatorio do - with_queries_mod(&list_entity/2, [RelatorioModel]) + with_queries_mod(&list_entity/2, [Relatorio]) end - def get_relatorio(id) do - with_queries_mod(&get_entity/3, [RelatorioModel, id]) + def get_relatorio(ano, mes) do + with_queries_mod(&get_entity_by/3, [Relatorio, [ano: ano, mes: mes]]) end ## Generic diff --git a/lib/fuschia/modulo_pesquisa/queries/campus.ex b/lib/fuschia/modulo_pesquisa/queries/campus.ex index 8140484d..3c9b1a26 100644 --- a/lib/fuschia/modulo_pesquisa/queries/campus.ex +++ b/lib/fuschia/modulo_pesquisa/queries/campus.ex @@ -1,24 +1,24 @@ -defmodule Fuschia.ModuloPesquisa.Queries.CampusQueries do +defmodule Fuschia.ModuloPesquisa.Queries.Campus do @moduledoc """ Queries para interagir com `Campus` """ import Ecto.Query, only: [from: 2, join: 5, where: 3] - alias Fuschia.ModuloPesquisa.Models.{CampusModel, CidadeModel} + alias Fuschia.ModuloPesquisa.Models.{Campus, Cidade} @behaviour Fuschia.Query @impl true def query do - from campus in CampusModel, + from campus in Campus, order_by: [desc: campus.inserted_at] end @spec query_by_municipio(binary) :: Ecto.Query.t() def query_by_municipio(municipio) do query() - |> join(:inner, [campus], c in CidadeModel, on: campus.cidade_municipio == c.municipio) + |> join(:inner, [campus], c in Cidade, on: campus.cidade_municipio == c.municipio) |> where([campus], campus.cidade_municipio == ^municipio) end diff --git a/lib/fuschia/modulo_pesquisa/queries/cidade.ex b/lib/fuschia/modulo_pesquisa/queries/cidade.ex index 8b6e8258..865f8d1b 100644 --- a/lib/fuschia/modulo_pesquisa/queries/cidade.ex +++ b/lib/fuschia/modulo_pesquisa/queries/cidade.ex @@ -1,17 +1,17 @@ -defmodule Fuschia.ModuloPesquisa.Queries.CidadeQueries do +defmodule Fuschia.ModuloPesquisa.Queries.Cidade do @moduledoc """ Queries para interagir com `Cidade` """ import Ecto.Query, only: [from: 2] - alias Fuschia.ModuloPesquisa.Models.CidadeModel + alias Fuschia.ModuloPesquisa.Models.Cidade @behaviour Fuschia.Query @impl true def query do - from c in CidadeModel, + from c in Cidade, order_by: [desc: c.inserted_at] end diff --git a/lib/fuschia/modulo_pesquisa/queries/linha_pesquisa.ex b/lib/fuschia/modulo_pesquisa/queries/linha_pesquisa.ex index 4fb80364..635a824f 100644 --- a/lib/fuschia/modulo_pesquisa/queries/linha_pesquisa.ex +++ b/lib/fuschia/modulo_pesquisa/queries/linha_pesquisa.ex @@ -1,24 +1,24 @@ -defmodule Fuschia.ModuloPesquisa.Queries.LinhaPesquisaQueries do +defmodule Fuschia.ModuloPesquisa.Queries.LinhaPesquisa do @moduledoc """ Queries para interagir com `LinhaPesquisa` """ import Ecto.Query, only: [from: 2, join: 5, where: 3] - alias Fuschia.ModuloPesquisa.Models.{LinhaPesquisaModel, NucleoModel} + alias Fuschia.ModuloPesquisa.Models.{LinhaPesquisa, Nucleo} @behaviour Fuschia.Query @impl true def query do - from l in LinhaPesquisaModel, + from l in LinhaPesquisa, order_by: [desc: l.inserted_at] end @spec query_by_nucleo(binary) :: Ecto.Query.t() def query_by_nucleo(nome_nucleo) do query() - |> join(:inner, [l], n in NucleoModel, on: l.nucleo_nome == n.nome) + |> join(:inner, [l], n in Nucleo, on: l.nucleo_nome == n.nome) |> where([l], l.nucleo_nome == ^nome_nucleo) end diff --git a/lib/fuschia/modulo_pesquisa/queries/midia.ex b/lib/fuschia/modulo_pesquisa/queries/midia.ex index 6ad868e9..86d57de0 100644 --- a/lib/fuschia/modulo_pesquisa/queries/midia.ex +++ b/lib/fuschia/modulo_pesquisa/queries/midia.ex @@ -1,17 +1,17 @@ -defmodule Fuschia.ModuloPesquisa.Queries.MidiaQueries do +defmodule Fuschia.ModuloPesquisa.Queries.Midia do @moduledoc """ Queries para interagir com `Midia` """ import Ecto.Query, only: [from: 2, join: 4, where: 3] - alias Fuschia.ModuloPesquisa.Models.MidiaModel + alias Fuschia.ModuloPesquisa.Models.Midia @behaviour Fuschia.Query @impl true def query do - from midia in MidiaModel, + from midia in Midia, order_by: [desc: midia.inserted_at] end diff --git a/lib/fuschia/modulo_pesquisa/queries/nucleo.ex b/lib/fuschia/modulo_pesquisa/queries/nucleo.ex index 4932d326..e379e9e5 100644 --- a/lib/fuschia/modulo_pesquisa/queries/nucleo.ex +++ b/lib/fuschia/modulo_pesquisa/queries/nucleo.ex @@ -1,17 +1,17 @@ -defmodule Fuschia.ModuloPesquisa.Queries.NucleoQueries do +defmodule Fuschia.ModuloPesquisa.Queries.Nucleo do @moduledoc """ Queries para interagir com `Nucleo` """ import Ecto.Query, only: [from: 2] - alias Fuschia.ModuloPesquisa.Models.NucleoModel + alias Fuschia.ModuloPesquisa.Models.Nucleo @behaviour Fuschia.Query @impl true def query do - from n in NucleoModel, + from n in Nucleo, order_by: [desc: n.inserted_at] end diff --git a/lib/fuschia/modulo_pesquisa/queries/pesquisador.ex b/lib/fuschia/modulo_pesquisa/queries/pesquisador.ex index 5557066b..b26a8993 100644 --- a/lib/fuschia/modulo_pesquisa/queries/pesquisador.ex +++ b/lib/fuschia/modulo_pesquisa/queries/pesquisador.ex @@ -1,17 +1,17 @@ -defmodule Fuschia.ModuloPesquisa.Queries.PesquisadorQueries do +defmodule Fuschia.ModuloPesquisa.Queries.Pesquisador do @moduledoc """ Queries para interagir com `Pesquisadore` """ import Ecto.Query, only: [from: 2, where: 3, order_by: 3] - alias Fuschia.ModuloPesquisa.Models.PesquisadorModel + alias Fuschia.ModuloPesquisa.Models.Pesquisador @behaviour Fuschia.Query @impl true def query do - from p in PesquisadorModel, + from p in Pesquisador, left_join: campus in assoc(p, :campus), left_join: orientador in assoc(p, :orientador), order_by: [desc: p.inserted_at] diff --git a/lib/fuschia/modulo_pesquisa/queries/relatorios.ex b/lib/fuschia/modulo_pesquisa/queries/relatorios.ex index e45bb303..9d89fc6f 100644 --- a/lib/fuschia/modulo_pesquisa/queries/relatorios.ex +++ b/lib/fuschia/modulo_pesquisa/queries/relatorios.ex @@ -1,17 +1,17 @@ -defmodule Fuschia.ModuloPesquisa.Queries.RelatorioQueries do +defmodule Fuschia.ModuloPesquisa.Queries.Relatorio do @moduledoc """ Queries para interagir com `Relatorio` """ import Ecto.Query, only: [from: 2, join: 4, where: 3] - alias Fuschia.ModuloPesquisa.Models.RelatorioModel + alias Fuschia.ModuloPesquisa.Models.Relatorio @behaviour Fuschia.Query @impl true def query do - from relatorio in RelatorioModel, + from relatorio in Relatorio, order_by: [desc: relatorio.inserted_at] end diff --git a/lib/fuschia_web/auth/guardian.ex b/lib/fuschia_web/auth/guardian.ex index e0de2260..81f83590 100644 --- a/lib/fuschia_web/auth/guardian.ex +++ b/lib/fuschia_web/auth/guardian.ex @@ -6,8 +6,8 @@ defmodule FuschiaWeb.Auth.Guardian do use Guardian, otp_app: :fuschia alias Fuschia.Accounts - alias Fuschia.Accounts.Adapters.UserAdapter - alias Fuschia.Accounts.Models.UserModel + alias Fuschia.Accounts.Adapters.User, as: UserAdapter + alias Fuschia.Accounts.Models.User, as: UserModel @spec subject_for_token(User.t(), map) :: {:ok, String.t()} def subject_for_token(user, _claims) do diff --git a/lib/fuschia_web/controllers/api/campus_controller.ex b/lib/fuschia_web/controllers/api/campus_controller.ex index efd4ab69..fc12060d 100644 --- a/lib/fuschia_web/controllers/api/campus_controller.ex +++ b/lib/fuschia_web/controllers/api/campus_controller.ex @@ -5,7 +5,7 @@ defmodule FuschiaWeb.CampusController do use OpenApiSpex.ControllerSpecs alias Fuschia.ModuloPesquisa - alias Fuschia.ModuloPesquisa.Models.CampusModel + alias Fuschia.ModuloPesquisa.Models.Campus alias FuschiaWeb.Swagger.{CampusSchemas, Response, Security} alias OpenApiSpex.Schema @@ -57,7 +57,7 @@ defmodule FuschiaWeb.CampusController do @spec delete(Plug.Conn.t(), map) :: Plug.Conn.t() def delete(conn, %{"campus_id" => campus_id}) do - with %CampusModel{} = campus <- ModuloPesquisa.get_campus(campus_id), + with %Campus{} = campus <- ModuloPesquisa.get_campus(campus_id), {:ok, _campus} <- ModuloPesquisa.delete(campus) do render_response(campus, conn) end diff --git a/lib/fuschia_web/controllers/browser/user_auth.ex b/lib/fuschia_web/controllers/browser/user_auth.ex index 2575806f..9eb70f29 100644 --- a/lib/fuschia_web/controllers/browser/user_auth.ex +++ b/lib/fuschia_web/controllers/browser/user_auth.ex @@ -9,7 +9,7 @@ defmodule FuschiaWeb.UserAuth do import Phoenix.Controller alias Fuschia.Accounts - alias Fuschia.Accounts.Models.UserModel + alias Fuschia.Accounts.Models.User alias FuschiaWeb.Router.Helpers, as: Routes # Faça o cookie lembrar do usuário ser válido por 60 dias. @@ -30,7 +30,7 @@ defmodule FuschiaWeb.UserAuth do "/app/pesquisadores/#{user.id}" else with user_token when is_binary(user_token) <- get_session(conn, :user_token), - %UserModel{id: user_id} <- Accounts.get_user_by_session_token(user_token) do + %User{id: user_id} <- Accounts.get_user_by_session_token(user_token) do "/app/pesquisadores/#{user_id}" else _e -> "/not_found" diff --git a/lib/fuschia_web/controllers/nucleo_controller.ex b/lib/fuschia_web/controllers/nucleo_controller.ex index 20f9cce8..ec9b5547 100644 --- a/lib/fuschia_web/controllers/nucleo_controller.ex +++ b/lib/fuschia_web/controllers/nucleo_controller.ex @@ -5,7 +5,7 @@ defmodule FuschiaWeb.NucleoController do alias Fuschia.Database alias Fuschia.ModuloPesquisa - alias Fuschia.ModuloPesquisa.Models.NucleoModel + alias Fuschia.ModuloPesquisa.Models.Nucleo alias FuschiaWeb.Swagger.{NucleoSchemas, Response, Security} alias OpenApiSpex.Schema @@ -57,7 +57,7 @@ defmodule FuschiaWeb.NucleoController do @spec show(Plug.Conn.t(), map) :: Plug.Conn.t() def show(conn, %{"id" => nucleo_id}) do - with %NucleoModel{} = nucleo <- ModuloPesquisa.get_nucleo(nucleo_id) do + with %Nucleo{} = nucleo <- ModuloPesquisa.get_nucleo(nucleo_id) do render_response(nucleo, conn) end end @@ -81,7 +81,7 @@ defmodule FuschiaWeb.NucleoController do @spec update(Plug.Conn.t(), map) :: Plug.Conn.t() def update(conn, %{"nucleo" => attrs, "id" => nucleo_id}) do - with %NucleoModel{} = nucleo <- ModuloPesquisa.get_nucleo(nucleo_id), + with %Nucleo{} = nucleo <- ModuloPesquisa.get_nucleo(nucleo_id), {:ok, updated_nucleo} <- ModuloPesquisa.update_nucleo(nucleo, attrs) do render_response(updated_nucleo, conn) end @@ -104,7 +104,7 @@ defmodule FuschiaWeb.NucleoController do @spec delete(Plug.Conn.t(), map) :: Plug.Conn.t() def delete(conn, %{"id" => nucleo_id}) do - with %NucleoModel{} = nucleo <- ModuloPesquisa.get_nucleo(nucleo_id), + with %Nucleo{} = nucleo <- ModuloPesquisa.get_nucleo(nucleo_id), {:ok, _nucleo} <- Database.delete(nucleo) do render_response(nucleo, conn) end diff --git a/lib/fuschia_web/live/init_assigns.ex b/lib/fuschia_web/live/init_assigns.ex index 5c62f0e6..97787140 100644 --- a/lib/fuschia_web/live/init_assigns.ex +++ b/lib/fuschia_web/live/init_assigns.ex @@ -7,7 +7,7 @@ defmodule FuschiaWeb.Live.InitAssigns do import Phoenix.LiveView alias Fuschia.Accounts - alias Fuschia.Accounts.Models.UserModel + alias Fuschia.Accounts.Models.User alias FuschiaWeb.Router.Helpers, as: Routes def on_mount(:default, _params, session, socket) do @@ -21,7 +21,7 @@ defmodule FuschiaWeb.Live.InitAssigns do end) case socket.assigns.current_user do - %UserModel{} -> + %User{} -> socket _other -> @@ -33,7 +33,7 @@ defmodule FuschiaWeb.Live.InitAssigns do defp find_current_user(session) do with session_token when is_binary(session_token) <- session["user_token"], - %UserModel{} = user <- Accounts.get_user_by_session_token(session_token), + %User{} = user <- Accounts.get_user_by_session_token(session_token), do: user end end diff --git a/lib/fuschia_web/live/user_registration/new.ex b/lib/fuschia_web/live/user_registration/new.ex index 7b45ddc5..2bf7894a 100644 --- a/lib/fuschia_web/live/user_registration/new.ex +++ b/lib/fuschia_web/live/user_registration/new.ex @@ -6,19 +6,19 @@ defmodule FuschiaWeb.UserRegistrationLive.New do import FuschiaWeb.Gettext alias Fuschia.Accounts - alias Fuschia.Accounts.Models.UserModel + alias Fuschia.Accounts.Models.User alias FuschiaWeb.UserAuth alias Surface.Components.Form alias Surface.Components.Form.{EmailInput, Field, Label, PasswordInput} def mount(_params, _session, socket) do - changeset = Accounts.change_user_registration(%UserModel{}) + changeset = Accounts.change_user_registration(%User{}) {:ok, assign(socket, changeset: changeset)} end def handle_event("validate", %{"user_model" => user_params}, socket) do changeset = - %UserModel{} + %User{} |> Accounts.change_user_registration(user_params) |> Map.put(:action, :insert) diff --git a/lib/fuschia_web/plugs/ensure_role_plug.ex b/lib/fuschia_web/plugs/ensure_role_plug.ex index 3ad61db9..b2c8c148 100644 --- a/lib/fuschia_web/plugs/ensure_role_plug.ex +++ b/lib/fuschia_web/plugs/ensure_role_plug.ex @@ -12,7 +12,7 @@ defmodule FuschiaWeb.EnsureRolePlug do import Plug.Conn alias Fuschia.Accounts - alias Fuschia.Accounts.Models.UserModel + alias Fuschia.Accounts.Models.User alias FuschiaWeb.UserAuth alias Phoenix.Controller @@ -27,12 +27,12 @@ defmodule FuschiaWeb.EnsureRolePlug do |> maybe_halt(conn) end - defp has_role?(%UserModel{} = user, roles) when is_list(roles), + defp has_role?(%User{} = user, roles) when is_list(roles), do: Enum.any?(roles, &has_role?(user, &1)) # Essa cláusula só será exectada quando o ambos # os argumentos com alias `role` tiverem o mesmo valor - defp has_role?(%UserModel{role: role}, role), do: true + defp has_role?(%User{role: role}, role), do: true defp has_role?(_user, _role), do: false defp maybe_halt(true, conn), do: conn diff --git a/lib/fuschia_web/plugs/require_api_key.ex b/lib/fuschia_web/plugs/require_api_key.ex index 3e3194d9..3d56ece6 100644 --- a/lib/fuschia_web/plugs/require_api_key.ex +++ b/lib/fuschia_web/plugs/require_api_key.ex @@ -7,7 +7,7 @@ defmodule FuschiaWeb.RequireApiKeyPlug do import Plug.Conn import FuschiaWeb.Gettext - alias Fuschia.Accounts.Queries.ApiKeyQueries + alias Fuschia.Accounts.Queries.ApiKey alias Fuschia.Database @spec init(map) :: map @@ -18,7 +18,7 @@ defmodule FuschiaWeb.RequireApiKeyPlug do conn = fetch_query_params(conn) api_key = conn.query_params["api_key"] || conn |> get_req_header("x-api-key") |> List.first() - case api_key && Database.get_by(ApiKeyQueries.query(), key: api_key) do + case api_key && Database.get_by(ApiKey.query(), key: api_key) do nil -> conn |> send_resp( diff --git a/lib/seeds/dev/api_keys_seeds.ex b/lib/seeds/dev/api_keys_seeds.ex index a6c912db..f08bf3ff 100644 --- a/lib/seeds/dev/api_keys_seeds.ex +++ b/lib/seeds/dev/api_keys_seeds.ex @@ -1,7 +1,7 @@ defmodule Fuschia.ApiKeysDevSeeds do @moduledoc false - alias Fuschia.Accounts.Models.ApiKeyModel + alias Fuschia.Accounts.Models.ApiKey alias Fuschia.Repo @spec run :: list(ApiKey.t()) @@ -13,13 +13,13 @@ defmodule Fuschia.ApiKeysDevSeeds do defp insert_or_update!(attrs) do changeset = - case Repo.get_by(ApiKeyModel, key: attrs.key) do - nil -> %ApiKeyModel{} + case Repo.get_by(ApiKey, key: attrs.key) do + nil -> %ApiKey{} api_key -> api_key end changeset - |> ApiKeyModel.changeset(attrs) + |> ApiKey.changeset(attrs) |> Repo.insert_or_update!() end diff --git a/test/fuschia/accounts/accounts_test.exs b/test/fuschia/accounts/accounts_test.exs index 81b95830..10111199 100644 --- a/test/fuschia/accounts/accounts_test.exs +++ b/test/fuschia/accounts/accounts_test.exs @@ -1,14 +1,19 @@ defmodule Fuschia.AccountsTest do - use Fuschia.DataCase + use Fuschia.DataCase, async: true import Fuschia.Factory alias Fuschia.Accounts - alias Fuschia.Accounts.Models.{UserModel, UserTokenModel} - alias Fuschia.Accounts.Queries.UserQueries + alias Fuschia.Accounts.Models.AuthLog + alias Fuschia.Accounts.Models.User, as: UserModel + alias Fuschia.Accounts.Models.UserToken + alias Fuschia.Accounts.Queries.User, as: UserQueries alias Fuschia.Database + alias Fuschia.Repo - @moduletag :unit + @moduletag :integration + + @ip "127.0.0.1" describe "list_user/1" do test "return all users in database" do @@ -248,7 +253,7 @@ defmodule Fuschia.AccountsTest do end) {:ok, token} = Base.url_decode64(token, padding: false) - assert user_token = Repo.get_by(UserTokenModel, token: :crypto.hash(:sha256, token)) + assert user_token = Repo.get_by(UserToken, token: :crypto.hash(:sha256, token)) assert user_token.user_cpf == user.cpf assert user_token.sent_to == user.contato.email assert user_token.context == "change:current@example.com" @@ -281,27 +286,27 @@ defmodule Fuschia.AccountsTest do assert changed_user.contato.email == email assert changed_user.confirmed_at assert changed_user.confirmed_at != user.confirmed_at - refute Repo.get_by(UserTokenModel, user_cpf: user.cpf) + refute Repo.get_by(UserToken, user_cpf: user.cpf) end test "does not update email with invalid token", %{user: user} do assert Accounts.update_user_email(user, "oops") == :error assert Accounts.get_user(user.cpf).contato.email == user.contato.email - assert Repo.get_by(UserTokenModel, user_cpf: user.cpf) + assert Repo.get_by(UserToken, user_cpf: user.cpf) end test "does not update email if user email changed", %{user: user, token: token} do contact = %{user.contato | email: "current@example.com"} assert Accounts.update_user_email(%{user | contato: contact}, token) == :error assert Accounts.get_user(user.cpf).contato.email == user.contato.email - assert Repo.get_by(UserTokenModel, user_cpf: user.cpf) + assert Repo.get_by(UserToken, user_cpf: user.cpf) end test "does not update email if token expired", %{user: user, token: token} do - {1, nil} = Repo.update_all(UserTokenModel, set: [inserted_at: ~N[2020-01-01 00:00:00]]) + {1, nil} = Repo.update_all(UserToken, set: [inserted_at: ~N[2020-01-01 00:00:00]]) assert Accounts.update_user_email(user, token) == :error assert Accounts.get_user(user.cpf).contato.email == user.contato.email - assert Repo.get_by(UserTokenModel, user_cpf: user.cpf) + assert Repo.get_by(UserToken, user_cpf: user.cpf) end end @@ -382,7 +387,7 @@ defmodule Fuschia.AccountsTest do password_confirmation: "New valid password!" }) - refute Repo.get_by(UserTokenModel, user_cpf: user.cpf) + refute Repo.get_by(UserToken, user_cpf: user.cpf) end end @@ -393,12 +398,12 @@ defmodule Fuschia.AccountsTest do test "generates a token", %{user: user} do token = Accounts.generate_user_session_token(user) - assert user_token = Repo.get_by(UserTokenModel, token: token) + assert user_token = Repo.get_by(UserToken, token: token) assert user_token.context == "session" # Creating the same token for another user should fail assert_raise Ecto.ConstraintError, fn -> - Repo.insert!(%UserTokenModel{ + Repo.insert!(%UserToken{ token: user_token.token, user_cpf: user_fixture().cpf, context: "session" @@ -424,7 +429,7 @@ defmodule Fuschia.AccountsTest do end test "does not return user for expired token", %{token: token} do - {1, nil} = Repo.update_all(UserTokenModel, set: [inserted_at: ~N[2020-01-01 00:00:00]]) + {1, nil} = Repo.update_all(UserToken, set: [inserted_at: ~N[2020-01-01 00:00:00]]) refute Accounts.get_user_by_session_token(token) end end @@ -450,7 +455,7 @@ defmodule Fuschia.AccountsTest do end) {:ok, token} = Base.url_decode64(token, padding: false) - assert user_token = Repo.get_by(UserTokenModel, token: :crypto.hash(:sha256, token)) + assert user_token = Repo.get_by(UserToken, token: :crypto.hash(:sha256, token)) assert user_token.user_cpf == user.cpf assert user_token.sent_to == user.contato.email assert user_token.context == "confirm" @@ -474,20 +479,20 @@ defmodule Fuschia.AccountsTest do assert confirmed_user.confirmed_at assert confirmed_user.confirmed_at != user.confirmed_at assert Repo.get!(UserModel, user.cpf).confirmed_at - refute Repo.get_by(UserTokenModel, user_cpf: user.cpf) + refute Repo.get_by(UserToken, user_cpf: user.cpf) end test "does not confirm with invalid token", %{user: user} do assert Accounts.confirm_user("oops") == :error refute Repo.get!(UserModel, user.cpf).confirmed_at - assert Repo.get_by(UserTokenModel, user_cpf: user.cpf) + assert Repo.get_by(UserToken, user_cpf: user.cpf) end test "does not confirm email if token expired", %{user: user, token: token} do - {1, nil} = Repo.update_all(UserTokenModel, set: [inserted_at: ~N[2020-01-01 00:00:00]]) + {1, nil} = Repo.update_all(UserToken, set: [inserted_at: ~N[2020-01-01 00:00:00]]) assert Accounts.confirm_user(token) == :error refute Repo.get!(UserModel, user.cpf).confirmed_at - assert Repo.get_by(UserTokenModel, user_cpf: user.cpf) + assert Repo.get_by(UserToken, user_cpf: user.cpf) end end @@ -503,7 +508,7 @@ defmodule Fuschia.AccountsTest do end) {:ok, token} = Base.url_decode64(token, padding: false) - assert user_token = Repo.get_by(UserTokenModel, token: :crypto.hash(:sha256, token)) + assert user_token = Repo.get_by(UserToken, token: :crypto.hash(:sha256, token)) assert user_token.user_cpf == user.cpf assert user_token.sent_to == user.contato.email assert user_token.context == "reset_password" @@ -524,18 +529,18 @@ defmodule Fuschia.AccountsTest do test "returns the user with valid token", %{user: %{cpf: cpf}, token: token} do assert %UserModel{cpf: ^cpf} = Accounts.get_user_by_reset_password_token(token) - assert Repo.get_by(UserTokenModel, user_cpf: cpf) + assert Repo.get_by(UserToken, user_cpf: cpf) end test "does not return the user with invalid token", %{user: user} do refute Accounts.get_user_by_reset_password_token("oops") - assert Repo.get_by(UserTokenModel, user_cpf: user.cpf) + assert Repo.get_by(UserToken, user_cpf: user.cpf) end test "does not return the user if token expired", %{user: user, token: token} do - {1, nil} = Repo.update_all(UserTokenModel, set: [inserted_at: ~N[2020-01-01 00:00:00]]) + {1, nil} = Repo.update_all(UserToken, set: [inserted_at: ~N[2020-01-01 00:00:00]]) refute Accounts.get_user_by_reset_password_token(token) - assert Repo.get_by(UserTokenModel, user_cpf: user.cpf) + assert Repo.get_by(UserToken, user_cpf: user.cpf) end end @@ -587,7 +592,7 @@ defmodule Fuschia.AccountsTest do password_confirmation: "New valid password!" }) - refute Repo.get_by(UserTokenModel, user_cpf: user.cpf) + refute Repo.get_by(UserToken, user_cpf: user.cpf) end end @@ -596,4 +601,62 @@ defmodule Fuschia.AccountsTest do refute inspect(%UserModel{password: "123456"}) =~ "password: \"123456\"" end end + + describe "create_auth_log/1" do + test "success should return :ok" do + ua = + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" + + user = insert(:user) + + result = + Accounts.create_auth_log(%{"ip" => @ip, "user_agent" => ua, "user_cpf" => user.cpf}) + + auth_log = get_log(@ip) + + assert result == :ok + assert Map.get(auth_log, :ip) == @ip + assert Map.get(auth_log, :user_agent) == ua + assert Map.get(auth_log, :user_cpf) == user.cpf + end + + test "with error should return :ok" do + user = build(:user) + result = Accounts.create_auth_log(%{"user_cpf" => user}) + auth_log = get_log(@ip) + + assert result == :ok + assert auth_log == nil + end + end + + describe "create_auth_log/3" do + test "success should return :ok" do + ua = + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" + + user = insert(:user) + + result = Accounts.create_auth_log(@ip, ua, user) + auth_log = get_log(@ip) + + assert result == :ok + assert Map.get(auth_log, :ip) == @ip + assert Map.get(auth_log, :user_agent) == ua + assert Map.get(auth_log, :user_cpf) == user.cpf + end + + test "with error should return :ok" do + user = build(:user) + result = Accounts.create_auth_log(nil, nil, user) + auth_log = get_log(@ip) + + assert result == :ok + assert auth_log == nil + end + end + + defp get_log(ip) do + Repo.get_by(AuthLog, ip: ip) + end end diff --git a/test/fuschia/entities/auth_log_test.exs b/test/fuschia/accounts/models/auth_log_test.exs similarity index 92% rename from test/fuschia/entities/auth_log_test.exs rename to test/fuschia/accounts/models/auth_log_test.exs index a48618c3..bb0ad7f9 100644 --- a/test/fuschia/entities/auth_log_test.exs +++ b/test/fuschia/accounts/models/auth_log_test.exs @@ -1,7 +1,7 @@ -defmodule Fuschia.Entities.AuthLogTest do +defmodule Fuschia.Accounts.Models.AuthLogTest do use Fuschia.DataCase, async: true - alias Fuschia.Entities.AuthLog + alias Fuschia.Accounts.Models.AuthLog @moduletag :unit diff --git a/test/fuschia/entities/user_test.exs b/test/fuschia/accounts/models/user_test.exs similarity index 96% rename from test/fuschia/entities/user_test.exs rename to test/fuschia/accounts/models/user_test.exs index 29368e9a..66a01431 100644 --- a/test/fuschia/entities/user_test.exs +++ b/test/fuschia/accounts/models/user_test.exs @@ -1,9 +1,9 @@ -defmodule Fuschia.Accounts.UserTest do +defmodule Fuschia.Accounts.Models.UserTest do use Fuschia.DataCase, async: true import Fuschia.Factory - alias Fuschia.Accounts.User + alias Fuschia.Accounts.Models.User @moduletag :unit diff --git a/test/fuschia/context/auth_logs_test.exs b/test/fuschia/context/auth_logs_test.exs deleted file mode 100644 index 2e32105b..00000000 --- a/test/fuschia/context/auth_logs_test.exs +++ /dev/null @@ -1,71 +0,0 @@ -defmodule Fuschia.AuthLogsTest do - @moduledoc false - - use Fuschia.DataCase, async: true - - import Fuschia.Factory - - alias Fuschia.Context.AuthLogs - alias Fuschia.Entities.AuthLog - alias Fuschia.Repo - - @moduletag :unit - - @ip "127.0.0.1" - - describe "create/1" do - test "success should return :ok" do - ua = - "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" - - user = insert(:user) - - result = AuthLogs.create(%{"ip" => @ip, "user_agent" => ua, "user_cpf" => user.cpf}) - auth_log = get_log(@ip) - - assert result == :ok - assert Map.get(auth_log, :ip) == @ip - assert Map.get(auth_log, :user_agent) == ua - assert Map.get(auth_log, :user_cpf) == user.cpf - end - - test "with error should return :ok" do - user = build(:user) - result = AuthLogs.create(%{"user_cpf" => user}) - auth_log = get_log(@ip) - - assert result == :ok - assert auth_log == nil - end - end - - describe "create/3" do - test "success should return :ok" do - ua = - "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" - - user = insert(:user) - - result = AuthLogs.create(@ip, ua, user) - auth_log = get_log(@ip) - - assert result == :ok - assert Map.get(auth_log, :ip) == @ip - assert Map.get(auth_log, :user_agent) == ua - assert Map.get(auth_log, :user_cpf) == user.cpf - end - - test "with error should return :ok" do - user = build(:user) - result = AuthLogs.create(nil, nil, user) - auth_log = get_log(@ip) - - assert result == :ok - assert auth_log == nil - end - end - - defp get_log(ip) do - Repo.get_by(AuthLog, ip: ip) - end -end diff --git a/test/fuschia/entities/campus_test.exs b/test/fuschia/modulo_pesquisa/models/campus_test.exs similarity index 86% rename from test/fuschia/entities/campus_test.exs rename to test/fuschia/modulo_pesquisa/models/campus_test.exs index 0b5ad616..9a2bfcc9 100644 --- a/test/fuschia/entities/campus_test.exs +++ b/test/fuschia/modulo_pesquisa/models/campus_test.exs @@ -1,9 +1,9 @@ -defmodule Fuschia.Entities.CampusTest do +defmodule Fuschia.ModuloPesquisa.Models.CampusTest do use Fuschia.DataCase, async: true import Fuschia.Factory - alias Fuschia.Entities.Campus + alias Fuschia.ModuloPesquisa.Models.Campus @moduletag :unit diff --git a/test/fuschia/entities/cidade_test.exs b/test/fuschia/modulo_pesquisa/models/cidade_test.exs similarity index 84% rename from test/fuschia/entities/cidade_test.exs rename to test/fuschia/modulo_pesquisa/models/cidade_test.exs index 937c79ac..029915fe 100644 --- a/test/fuschia/entities/cidade_test.exs +++ b/test/fuschia/modulo_pesquisa/models/cidade_test.exs @@ -1,9 +1,9 @@ -defmodule Fuschia.Entities.CidadeTest do +defmodule Fuschia.ModuloPesquisa.Models.CidadeTest do use Fuschia.DataCase, async: true import Fuschia.Factory - alias Fuschia.Entities.Cidade + alias Fuschia.ModuloPesquisa.Models.Cidade @moduletag :unit diff --git a/test/fuschia/entities/linha_pesquisa_test.exs b/test/fuschia/modulo_pesquisa/models/linha_pesquisa_test.exs similarity index 85% rename from test/fuschia/entities/linha_pesquisa_test.exs rename to test/fuschia/modulo_pesquisa/models/linha_pesquisa_test.exs index 8182edfe..4a19bce3 100644 --- a/test/fuschia/entities/linha_pesquisa_test.exs +++ b/test/fuschia/modulo_pesquisa/models/linha_pesquisa_test.exs @@ -1,9 +1,9 @@ -defmodule Fuschia.Entities.LinhaPesquisaTest do +defmodule Fuschia.ModuloPesquisa.Models.LinhaPesquisaTest do use Fuschia.DataCase, async: true import Fuschia.Factory - alias Fuschia.Entities.LinhaPesquisa + alias Fuschia.ModuloPesquisa.Models.LinhaPesquisa @moduletag :unit diff --git a/test/fuschia/entities/midia_test.exs b/test/fuschia/modulo_pesquisa/models/midia_test.exs similarity index 86% rename from test/fuschia/entities/midia_test.exs rename to test/fuschia/modulo_pesquisa/models/midia_test.exs index 17a83fd6..5dc7900b 100644 --- a/test/fuschia/entities/midia_test.exs +++ b/test/fuschia/modulo_pesquisa/models/midia_test.exs @@ -1,9 +1,9 @@ -defmodule Fuschia.Entities.MidiaTest do +defmodule Fuschia.ModuloPesquisa.Models.MidiaTest do use Fuschia.DataCase, async: true import Fuschia.Factory - alias Fuschia.Entities.Midia + alias Fuschia.ModuloPesquisa.Models.Midia @moduletag :unit diff --git a/test/fuschia/entities/nucleo_test.exs b/test/fuschia/modulo_pesquisa/models/nucleo_test.exs similarity index 85% rename from test/fuschia/entities/nucleo_test.exs rename to test/fuschia/modulo_pesquisa/models/nucleo_test.exs index 32a369e0..7e8c1bdc 100644 --- a/test/fuschia/entities/nucleo_test.exs +++ b/test/fuschia/modulo_pesquisa/models/nucleo_test.exs @@ -1,9 +1,9 @@ -defmodule Fuschia.Entities.NucleoTest do +defmodule Fuschia.ModuloPesquisa.Models.NucleoTest do use Fuschia.DataCase, async: true import Fuschia.Factory - alias Fuschia.Entities.Nucleo + alias Fuschia.ModuloPesquisa.Models.Nucleo @moduletag :unit diff --git a/test/fuschia/entities/pesquisador_test.exs b/test/fuschia/modulo_pesquisa/models/pesquisador_test.exs similarity index 77% rename from test/fuschia/entities/pesquisador_test.exs rename to test/fuschia/modulo_pesquisa/models/pesquisador_test.exs index 11ed90eb..6d988538 100644 --- a/test/fuschia/entities/pesquisador_test.exs +++ b/test/fuschia/modulo_pesquisa/models/pesquisador_test.exs @@ -1,9 +1,9 @@ -defmodule Fuschia.Accounts.PesquisadorTest do +defmodule Fuschia.ModuloPesquisa.Models.PesquisadorTest do use Fuschia.DataCase, async: true import Fuschia.Factory - alias Fuschia.Accounts.Pesquisador + alias Fuschia.ModuloPesquisa.Models.Pesquisador @moduletag :unit @@ -18,9 +18,13 @@ defmodule Fuschia.Accounts.PesquisadorTest do } test "when all params are valid, return a valid changeset" do + valid_password = valid_user_password() + usuario_params = :user |> params_for() + |> Map.put(:password, valid_password) + |> Map.put(:password_confirmation, valid_password) |> Map.put(:contato, params_for(:contato)) default_params = diff --git a/test/fuschia/entities/relatorio_test.exs b/test/fuschia/modulo_pesquisa/models/relatorio_test.exs similarity index 85% rename from test/fuschia/entities/relatorio_test.exs rename to test/fuschia/modulo_pesquisa/models/relatorio_test.exs index 5272c714..2ffcc79b 100644 --- a/test/fuschia/entities/relatorio_test.exs +++ b/test/fuschia/modulo_pesquisa/models/relatorio_test.exs @@ -1,9 +1,9 @@ -defmodule Fuschia.Entities.RelatorioTest do +defmodule Fuschia.ModuloPesquisa.Models.RelatorioTest do use Fuschia.DataCase, async: true import Fuschia.Factory - alias Fuschia.Entities.Relatorio + alias Fuschia.ModuloPesquisa.Models.Relatorio @moduletag :unit diff --git a/test/fuschia/modulo_pesquisa/module_pesquisa_test.exs b/test/fuschia/modulo_pesquisa/module_pesquisa_test.exs new file mode 100644 index 00000000..09647191 --- /dev/null +++ b/test/fuschia/modulo_pesquisa/module_pesquisa_test.exs @@ -0,0 +1,296 @@ +defmodule Fuschia.ModuloPesquisaTest do + use Fuschia.DataCase, async: true + + import Fuschia.Factory + + alias Fuschia.ModuloPesquisa + + alias Fuschia.ModuloPesquisa.Models.{ + Campus, + Cidade, + LinhaPesquisa, + Midia, + Nucleo, + Pesquisador, + Relatorio + } + + @moduletag :integration + + describe "campus" do + @valid_attrs %{ + nome: "Campus Estadual do Norte Fluminence Darcy Ribeiro", + cidade_municipio: "Campos Dos Goytacazes" + } + + @valid_attrs_cidade %{ + nome: "Campus Estadual do Norte Fluminence Darcy Ribeiro", + cidade: %{municipio: "Campos dos Goytacazes"} + } + + @invalid_attrs %{ + nome: nil, + cidade: nil + } + + test "create_campus/1" do + assert {:ok, %Campus{}} = ModuloPesquisa.create_campus(@valid_attrs_cidade) + assert {:error, %Ecto.Changeset{}} = ModuloPesquisa.create_campus(@invalid_attrs) + end + + test "create_campus/2" do + insert(:cidade, municipio: "Campos dos Goytacazes") + + assert {:ok, %Campus{}} = + ModuloPesquisa.create_campus(@valid_attrs, change_fun: &Campus.foreign_changeset/2) + + assert {:error, %Ecto.Changeset{}} = + ModuloPesquisa.create_campus(@invalid_attrs, + change_fun: &Campus.foreign_changeset/2 + ) + end + + test "list_campus/0" do + insert(:campus) + + campi = ModuloPesquisa.list_campus() + + assert length(campi) > 0 + end + + test "get_campus/1" do + campus = insert(:campus) + + assert ModuloPesquisa.get_campus(campus.nome) + refute ModuloPesquisa.get_campus("") + end + end + + describe "cidade" do + @valid_attrs %{ + municipio: "Campos dos Goytacazes" + } + + @invalid_attrs %{ + municipio: nil + } + + test "create_cidade/1" do + assert {:ok, %Cidade{}} = ModuloPesquisa.create_cidade(@valid_attrs) + assert {:error, %Ecto.Changeset{}} = ModuloPesquisa.create_cidade(@invalid_attrs) + end + + test "get_cidade/1" do + cidade = insert(:cidade) + + assert ModuloPesquisa.get_cidade(cidade.municipio) + refute ModuloPesquisa.get_cidade("") + end + end + + describe "linha pesquisa" do + @invalid_attrs %{ + numero: nil, + nucleo_nome: nil, + descricao_curta: nil, + descricao_longa: nil + } + + test "create_linha_pesquisa/1" do + valid_attrs = params_for(:linha_pesquisa) + assert {:ok, %LinhaPesquisa{}} = ModuloPesquisa.create_linha_pesquisa(valid_attrs) + assert {:error, %Ecto.Changeset{}} = ModuloPesquisa.create_linha_pesquisa(@invalid_attrs) + end + + test "list_linha_pesquisa/0" do + insert(:linha_pesquisa) + + linhas_pesquisas = ModuloPesquisa.list_linha_pesquisa() + + assert length(linhas_pesquisas) > 0 + end + + test "list_linha_pesquisa_by_nucleo/1" do + linha_pesquisa = insert(:linha_pesquisa) + + linhas_pesquisas = ModuloPesquisa.list_linha_pesquisa_by_nucleo(linha_pesquisa.nucleo_nome) + + assert length(linhas_pesquisas) > 0 + end + + test "get_linha_pesquisa/1" do + linha_pesquisa = insert(:linha_pesquisa) + + assert ModuloPesquisa.get_linha_pesquisa(linha_pesquisa.numero) + refute ModuloPesquisa.get_linha_pesquisa(0) + end + end + + describe "Mídia" do + @update_attrs %{ + link: "https://example.com", + tipo: "video", + tags: [] + } + + @invalid_attrs %{ + link: nil, + tipo: nil, + tags: nil, + pesquisador_cpf: nil + } + + test "create_midia/1" do + valid_attrs = params_for(:midia) + + assert {:ok, %Midia{}} = ModuloPesquisa.create_midia(valid_attrs) + assert {:error, %Ecto.Changeset{}} = ModuloPesquisa.create_midia(@invalid_attrs) + end + + test "list_midia/0" do + insert(:midia) + + midias = ModuloPesquisa.list_midia() + + assert length(midias) > 0 + end + + test "get_midia/1" do + midia = insert(:midia) + + assert ModuloPesquisa.get_midia(midia.link) + refute ModuloPesquisa.get_midia("") + end + + test "update_midia/2" do + midia = insert(:midia) + + assert {:ok, %Midia{}} = ModuloPesquisa.update_midia(midia, @update_attrs) + assert {:error, %Ecto.Changeset{}} = ModuloPesquisa.update_midia(midia, @invalid_attrs) + end + end + + describe "Nucleo" do + @update_attrs %{ + nome: "Nucleo Teste", + descricao: "Nucleo Descricao Teste" + } + + @invalid_attrs %{ + nome: nil, + descricao: nil + } + + test "create_nucleo/1" do + valid_attrs = params_for(:nucleo) + + assert {:ok, %Nucleo{}} = ModuloPesquisa.create_nucleo(valid_attrs) + assert {:error, %Ecto.Changeset{}} = ModuloPesquisa.create_nucleo(@invalid_attrs) + end + + test "list_nucleo/0" do + insert(:nucleo) + + nucleos = ModuloPesquisa.list_nucleo() + + assert length(nucleos) > 0 + end + + test "get_nucleo/1" do + nucleo = insert(:nucleo) + + assert ModuloPesquisa.get_nucleo(nucleo.nome) + refute ModuloPesquisa.get_nucleo("") + end + + test "update_nucleo/2" do + nucleo = insert(:nucleo) + + assert {:ok, %Nucleo{}} = ModuloPesquisa.update_nucleo(nucleo, @update_attrs) + assert {:error, %Ecto.Changeset{}} = ModuloPesquisa.update_nucleo(nucleo, @invalid_attrs) + end + end + + describe "Pesquisador" do + @invalid_attrs %{ + minibiografia: nil, + tipo_bolsa: nil, + link_lattes: nil, + orientador: nil, + campus_nome: nil, + usuario: nil, + orientandos: nil + } + + test "create_pesquisador/1" do + valid_password = valid_user_password() + + campus = insert(:campus) + + contato_attrs = params_for(:contato) + + user_attrs = + :user + |> params_for() + |> Map.put(:contato, contato_attrs) + |> Map.put(:password, valid_password) + |> Map.put(:password_confirmation, valid_password) + + valid_attrs = + :pesquisador + |> params_for() + |> Map.put(:campus_nome, campus.nome) + |> Map.put(:usuario, user_attrs) + + assert {:ok, %Pesquisador{}} = ModuloPesquisa.create_pesquisador(valid_attrs) + assert {:error, %Ecto.Changeset{}} = ModuloPesquisa.create_pesquisador(@invalid_attrs) + end + + test "list_pesquisador/0" do + insert(:pesquisador) + + pesquisadores = ModuloPesquisa.list_pesquisador() + + assert length(pesquisadores) > 0 + end + + test "get_pesquisador/1" do + pesquisador = insert(:pesquisador) + + assert ModuloPesquisa.get_pesquisador(pesquisador.usuario_cpf) + refute ModuloPesquisa.get_pesquisador("") + end + end + + describe "Relatorio" do + @invalid_attrs %{ + ano: nil, + mes: nil, + link: nil, + tipo: nil, + pesquisador_cpf: nil + } + + test "create_relatorio/1" do + valid_attrs = params_for(:relatorio) + + assert {:ok, %Relatorio{}} = ModuloPesquisa.create_relatorio(valid_attrs) + assert {:error, %Ecto.Changeset{}} = ModuloPesquisa.create_relatorio(@invalid_attrs) + end + + test "list_relatorio/0" do + insert(:relatorio) + + relatorios = ModuloPesquisa.list_relatorio() + + assert length(relatorios) > 0 + end + + test "get_relatorio/1" do + relatorio = insert(:relatorio) + + assert ModuloPesquisa.get_relatorio(relatorio.ano, relatorio.mes) + refute ModuloPesquisa.get_relatorio(0, 0) + end + end +end diff --git a/test/fuschia/queries/campi_test.exs b/test/fuschia/queries/campi_test.exs deleted file mode 100644 index ed044455..00000000 --- a/test/fuschia/queries/campi_test.exs +++ /dev/null @@ -1,138 +0,0 @@ -defmodule Fuschia.Queries.CampiTest do - use Fuschia.DataCase, async: true - - import Fuschia.Factory - - alias Fuschia.Database - alias Fuschia.Entities.Campus - alias Fuschia.Queries.Campi - - @moduletag :unit - - describe "list/0" do - test "return all campi in database" do - insert(:campus) - - campus = Database.one(Campi.query()) - - assert [campus] == Database.list(Campi.query()) - end - end - - describe "list_by_municipio/1" do - test "return all campi in database" do - insert(:campus) - - campus = Database.one(Campi.query()) - - assert [campus] == campus.cidade_municipio |> Campi.query_by_municipio() |> Database.list() - end - end - - describe "one/1" do - test "when nome is valid, returns a campus" do - insert(:campus) - - campus = Database.one(Campi.query()) - - assert campus == Database.get(Campi.query(), campus.nome) - end - - test "when id is invalid, returns nil" do - assert Campi.query() |> Database.get("") |> is_nil() - end - end - - describe "create_with_cidade/1" do - @valid_attrs %{ - nome: "Campus Estadual do Norte Fluminence Darcy Ribeiro", - cidade: %{municipio: "Campos dos Goytacazes"} - } - - @invalid_attrs %{ - nome: nil, - cidade: nil - } - - test "when all params are valid, creates an admin campus" do - assert {:ok, %Campus{}} = Database.create(Campus, @valid_attrs) - end - - test "when params are invalid, returns an error changeset" do - assert {:error, %Ecto.Changeset{}} = Database.create(Campus, @invalid_attrs) - end - end - - describe "create/1" do - @valid_attrs %{ - nome: "Campus Estadual do Norte Fluminence Darcy Ribeiro", - cidade_municipio: "Campos Dos Goytacazes" - } - - @invalid_attrs %{ - nome: nil, - cidade_municipio: nil - } - - test "when all params are valid, creates an admin campus" do - insert(:cidade, municipio: "Campos dos Goytacazes") - - assert {:ok, %Campus{}} = - Database.create_with_custom_changeset( - Campus, - &Campus.foreign_changeset/2, - @valid_attrs - ) - end - - test "when params are invalid, returns an error changeset" do - assert {:error, %Ecto.Changeset{}} = - Database.create_with_custom_changeset( - Campus, - &Campus.foreign_changeset/2, - @invalid_attrs - ) - end - end - - describe "update/1" do - @valid_attrs %{ - nome: "Campus Estadual do Norte Fluminence Darcy Ribeiro", - cidade: %{municipio: "Campos dos Goytacazes"} - } - - @update_attrs %{ - nome: "Campus Federal De São Carlos" - } - - @invalid_attrs %{ - nome: nil - } - - test "when all params are valid, updates a campus" do - assert {:ok, campus} = Database.create(Campus, @valid_attrs) - - assert {:ok, updated_campus} = - Database.update( - Campi.query(), - &Campus.foreign_changeset/2, - campus.nome, - @update_attrs - ) - - assert updated_campus.nome == @update_attrs.nome - end - - test "when params are invalid, returns an error changeset" do - assert {:ok, campus} = Database.create(Campus, @valid_attrs) - - assert {:error, %Ecto.Changeset{}} = - Database.update( - Campi.query(), - &Campus.foreign_changeset/2, - campus.nome, - @invalid_attrs - ) - end - end -end diff --git a/test/fuschia/queries/cidades_test.exs b/test/fuschia/queries/cidades_test.exs deleted file mode 100644 index 4f9e40af..00000000 --- a/test/fuschia/queries/cidades_test.exs +++ /dev/null @@ -1,93 +0,0 @@ -defmodule Fuschia.Queries.CidadesTest do - use Fuschia.DataCase, async: true - - import Fuschia.Factory - - alias Fuschia.Database - alias Fuschia.Entities.Cidade - alias Fuschia.Queries.Cidades - - @moduletag :unit - - describe "list/0" do - test "return all cidades in database" do - insert(:cidade) - - cidade = Database.one(Cidades.query()) - - assert [cidade] == Database.list(Cidades.query()) - end - end - - describe "one/1" do - test "when nome is valid, returns a cidade" do - insert(:cidade) - - cidade = Database.one(Cidades.query()) - - assert cidade == Database.get(Cidades.query(), cidade.municipio) - end - - test "when id is invalid, returns nil" do - assert Cidades.query() |> Database.get("") |> is_nil() - end - end - - describe "create/1" do - @valid_attrs %{ - municipio: "Campos dos Goytacazes" - } - - @invalid_attrs %{ - municipio: nil - } - - test "when all params are valid, creates an admin cidade" do - assert {:ok, %Cidade{}} = Database.create(Cidade, @valid_attrs) - end - - test "when params are invalid, returns an error changeset" do - assert {:error, %Ecto.Changeset{}} = Database.create(Cidade, @invalid_attrs) - end - end - - describe "update/1" do - @valid_attrs %{ - municipio: "Campos dos Goytacazes" - } - - @update_attrs %{ - municipio: "São Carlos" - } - - @invalid_attrs %{ - municipio: nil - } - - test "when all params are valid, updates a cidade" do - assert {:ok, cidade} = Database.create(Cidade, @valid_attrs) - - assert {:ok, updated_cidade} = - Database.update( - Cidades.query(), - &Cidade.changeset/2, - cidade.municipio, - @update_attrs - ) - - assert updated_cidade.municipio == @update_attrs.municipio - end - - test "when params are invalid, returns an error changeset" do - assert {:ok, cidade} = Database.create(Cidade, @valid_attrs) - - assert {:error, %Ecto.Changeset{}} = - Database.update( - Cidades.query(), - &Cidade.changeset/2, - cidade.municipio, - @invalid_attrs - ) - end - end -end diff --git a/test/fuschia/queries/linhas_pesquisas_test.exs b/test/fuschia/queries/linhas_pesquisas_test.exs deleted file mode 100644 index 0c19efe3..00000000 --- a/test/fuschia/queries/linhas_pesquisas_test.exs +++ /dev/null @@ -1,112 +0,0 @@ -defmodule Fuschia.Queries.LinhasPesquisasTest do - use Fuschia.DataCase, async: true - - import Fuschia.Factory - - alias Fuschia.Database - alias Fuschia.Entities.LinhaPesquisa - alias Fuschia.Queries.LinhasPesquisas - - @moduletag :unit - - describe "list/0" do - test "return all linha_pesquisas in database" do - insert(:linha_pesquisa) - - linha_pesquisa = Database.one(LinhasPesquisas.query()) - - assert [linha_pesquisa] == Database.list(LinhasPesquisas.query()) - end - end - - describe "list_by_nucleo/1" do - test "return all linha_pesquisas in database" do - insert(:linha_pesquisa) - - linha_pesquisa = Database.one(LinhasPesquisas.query()) - - assert [linha_pesquisa] == - linha_pesquisa.nucleo_nome |> LinhasPesquisas.query_by_nucleo() |> Database.list() - end - end - - describe "one/1" do - test "when numero is valid, returns a linha_pesquisa" do - insert(:linha_pesquisa) - - linha_pesquisa = Database.one(LinhasPesquisas.query()) - - assert linha_pesquisa == Database.get(LinhasPesquisas.query(), linha_pesquisa.numero) - end - - test "when id is invalid, returns nil" do - assert LinhasPesquisas.query() |> Database.get(0) |> is_nil() - end - end - - describe "create/1" do - @invalid_attrs %{ - numero: nil, - nucleo_nome: nil, - descricao_curta: nil, - descricao_longa: nil - } - - test "when all params are valid, creates an admin linha_pesquisa" do - valid_attrs = params_for(:linha_pesquisa) - - assert {:ok, %LinhaPesquisa{}} = Database.create(LinhaPesquisa, valid_attrs) - end - - test "when params are invalid, returns an error changeset" do - assert {:error, %Ecto.Changeset{}} = Database.create(LinhaPesquisa, @invalid_attrs) - end - end - - describe "update/1" do - @update_attrs %{ - numero: 100, - descricao_curta: "Descricao Curta Teste", - descricao_longa: "Descricao Longa Teste" - } - - @invalid_attrs %{ - numero: nil, - nucleo_nome: nil, - descricao_curta: nil, - descricao_longa: nil - } - - test "when all params are valid, updates a linha_pesquisa" do - attrs = params_for(:linha_pesquisa) - - assert {:ok, linha_pesquisa} = Database.create(LinhaPesquisa, attrs) - - assert {:ok, updated_linha_pesquisa} = - Database.update( - LinhasPesquisas.query(), - &LinhaPesquisa.changeset/2, - linha_pesquisa.numero, - @update_attrs - ) - - assert updated_linha_pesquisa.numero == @update_attrs.numero - assert updated_linha_pesquisa.descricao_curta == @update_attrs.descricao_curta - assert updated_linha_pesquisa.descricao_longa == @update_attrs.descricao_longa - end - - test "when params are invalid, returns an error changeset" do - attrs = params_for(:linha_pesquisa) - - assert {:ok, linha_pesquisa} = Database.create(LinhaPesquisa, attrs) - - assert {:error, %Ecto.Changeset{}} = - Database.update( - LinhasPesquisas.query(), - &LinhaPesquisa.changeset/2, - linha_pesquisa.numero, - @invalid_attrs - ) - end - end -end diff --git a/test/fuschia/queries/midias_test.exs b/test/fuschia/queries/midias_test.exs deleted file mode 100644 index 33645267..00000000 --- a/test/fuschia/queries/midias_test.exs +++ /dev/null @@ -1,112 +0,0 @@ -defmodule Fuschia.Queries.MidiasTest do - use Fuschia.DataCase, async: true - - import Fuschia.Factory - - alias Fuschia.Database - alias Fuschia.Entities.Midia - alias Fuschia.Queries.Midias - - @moduletag :unit - - describe "list/0" do - test "return all midias in database" do - insert(:midia) - - midia = Database.one(Midias.query()) - - assert [midia] == Database.list(Midias.query()) - end - end - - describe "list_by_pesquisador/1" do - test "return all midia in database" do - insert(:midia) - - midia = Database.one(Midias.query()) - - assert [midia] == - midia.pesquisador_cpf |> Midias.query_by_pesquisador() |> Database.list() - end - end - - describe "one/1" do - test "when numero is valid, returns a midia" do - insert(:midia) - - midia = Database.one(Midias.query()) - - assert midia == Database.get(Midias.query(), midia.link) - end - - test "when id is invalid, returns nil" do - assert Midias.query() |> Database.get("") |> is_nil() - end - end - - describe "create/1" do - @invalid_attrs %{ - link: nil, - tipo: nil, - tags: nil, - pesquisador_cpf: nil - } - - test "when all params are valid, creates a midia" do - valid_attrs = params_for(:midia) - - assert {:ok, %Midia{}} = Database.create(Midia, valid_attrs) - end - - test "when params are invalid, returns an error changeset" do - assert {:error, %Ecto.Changeset{}} = Database.create(Midia, @invalid_attrs) - end - end - - describe "update/1" do - @update_attrs %{ - link: "https://example.com", - tipo: "video", - tags: [] - } - - @invalid_attrs %{ - link: nil, - tipo: nil, - tags: nil, - pesquisador_cpf: nil - } - - test "when all params are valid, updates a midia" do - attrs = params_for(:midia) - - assert {:ok, midia} = Database.create(Midia, attrs) - - assert {:ok, updated_midia} = - Database.update( - Midias.query(), - &Midia.changeset/2, - midia.link, - @update_attrs - ) - - assert updated_midia.link == @update_attrs.link - assert updated_midia.tipo == @update_attrs.tipo - assert updated_midia.tags == @update_attrs.tags - end - - test "when params are invalid, returns an error changeset" do - attrs = params_for(:midia) - - assert {:ok, midia} = Database.create(Midia, attrs) - - assert {:error, %Ecto.Changeset{}} = - Database.update( - Midias.query(), - &Midia.changeset/2, - midia.link, - @invalid_attrs - ) - end - end -end diff --git a/test/fuschia/queries/nucleos_test.exs b/test/fuschia/queries/nucleos_test.exs deleted file mode 100644 index ee30e2bb..00000000 --- a/test/fuschia/queries/nucleos_test.exs +++ /dev/null @@ -1,85 +0,0 @@ -defmodule Fuschia.Queries.NucleosTest do - use Fuschia.DataCase, async: true - - import Fuschia.Factory - - alias Fuschia.Database - alias Fuschia.Entities.Nucleo - alias Fuschia.Queries.Nucleos - - @moduletag :unit - - describe "list/0" do - test "return all nucleos in database" do - insert(:nucleo) - - nucleo = Database.one(Nucleos.query()) - - assert [nucleo] == Database.list(Nucleos.query()) - end - end - - describe "one/1" do - test "when nome is valid, returns a nucleo" do - insert(:nucleo) - - nucleo = Database.one(Nucleos.query()) - - assert nucleo == Database.get(Nucleos.query(), nucleo.nome) - end - - test "when id is invalid, returns nil" do - assert Nucleos.query() |> Database.get("") |> is_nil() - end - end - - describe "create/1" do - @invalid_attrs %{ - nome: nil, - descricao: nil - } - - test "when all params are valid, creates an admin nucleo" do - valid_attrs = params_for(:nucleo) - - assert {:ok, %Nucleo{}} = Database.create(Nucleo, valid_attrs) - end - - test "when params are invalid, returns an error changeset" do - assert {:error, %Ecto.Changeset{}} = Database.create(Nucleo, @invalid_attrs) - end - end - - describe "update/1" do - @update_attrs %{ - nome: "Nucleo Teste", - descricao: "Nucleo Descricao Teste" - } - - @invalid_attrs %{ - nome: nil, - descricao: nil - } - - test "when all params are valid, updates a nucleo" do - attrs = params_for(:nucleo) - - assert {:ok, nucleo} = Database.create(Nucleo, attrs) - - assert {:ok, updated_nucleo} = - Database.update(Nucleos.query(), &Nucleo.changeset/2, nucleo.nome, @update_attrs) - - assert updated_nucleo.nome == @update_attrs.nome - assert updated_nucleo.descricao == @update_attrs.descricao - end - - test "when params are invalid, returns an error changeset" do - attrs = params_for(:nucleo) - - assert {:ok, nucleo} = Database.create(Nucleo, attrs) - - assert {:error, %Ecto.Changeset{}} = - Database.update(Nucleos.query(), &Nucleo.changeset/2, nucleo.nome, @invalid_attrs) - end - end -end diff --git a/test/fuschia/queries/pesquisadores_test.exs b/test/fuschia/queries/pesquisadores_test.exs deleted file mode 100644 index 4b6c8658..00000000 --- a/test/fuschia/queries/pesquisadores_test.exs +++ /dev/null @@ -1,198 +0,0 @@ -defmodule Fuschia.Queries.PesquisadoresTest do - use Fuschia.DataCase, async: true - - import Fuschia.Factory - - alias Fuschia.Accounts.Pesquisador - alias Fuschia.Database - alias Fuschia.Queries.Pesquisadores - - @moduletag :unit - - describe "list/1" do - test "return all pesquisadores in database" do - insert(:pesquisador) - - pesquisador = Database.one(Pesquisadores.query()) - - assert [pesquisador] == Database.list(Pesquisadores.query()) - end - end - - describe "one/1" do - test "when id is valid, returns a pesquisador" do - insert(:pesquisador) - - pesquisador = Database.one(Pesquisadores.query()) - - assert pesquisador == Database.get(Pesquisadores.query(), pesquisador.usuario_cpf) - end - - test "when id is invalid, returns nil" do - assert Pesquisadores.query() |> Database.get("") |> is_nil() - end - end - - describe "list_by_orientador/1" do - test "return all pesquisadores in database with orientador of a cpf" do - orientador = insert(:pesquisador) - - %{usuario_cpf: pesquisador_cpf} = - insert(:pesquisador, orientador_cpf: orientador.usuario_cpf) - - pesquisador = Database.get(Pesquisadores.query(), pesquisador_cpf) - - assert [pesquisador] == - pesquisador.orientador_cpf - |> Pesquisadores.query_by_orientador() - |> Database.list() - end - end - - describe "create/1" do - @valid_attrs %{ - minibiografia: "minibibliografia aaa", - tipo_bolsa: "ic", - link_lattes: "www.lattes", - usuario: %{ - nome_completo: "Matheus de Souza Pessanha", - cpf: "264.722.590-70", - data_nascimento: ~D[2001-07-27], - perfil: "admin", - contato: %{ - endereco: "Av Teste, Rua Teste, numero 123", - email: "teste@exemplo.com", - celular: "(22)12345-6789" - } - } - } - - @invalid_attrs %{ - minibiografia: nil, - tipo_bolsa: nil, - link_lattes: nil, - orientador: nil, - campus_nome: nil, - usuario: nil, - orientandos: nil - } - - test "when all params are valid, creates an admin pesquisador" do - %{nome: campus_nome} = insert(:campus) - - assert {:ok, %Pesquisador{}} = - @valid_attrs - |> Map.put(:campus_nome, campus_nome) - |> then(&Database.create(Pesquisador, &1)) - end - - test "when params are invalid, returns an error changeset" do - assert {:error, %Ecto.Changeset{}} = Database.create(Pesquisador, @invalid_attrs) - end - end - - describe "update/1" do - setup do - %{campus_nome: insert(:campus).nome} - end - - @valid_attrs %{ - minibiografia: "minibibliografia aaa", - tipo_bolsa: "ic", - link_lattes: "www.lattes.com", - usuario: %{ - nome_completo: "Matheus de Souza Pessanha", - cpf: "264.722.590-70", - data_nascimento: ~D[2001-07-27], - perfil: "admin", - contato: %{ - endereco: "Av Teste, Rua Teste, numero 123", - email: "teste@exemplo.com", - celular: "(22)12345-6789" - } - } - } - - @update_attrs %{ - link_lattes: "www.lattes/novo_link", - minibiografia: "updated bio" - } - - @invalid_attrs %{ - minibiografia: nil, - tipo_bolsa: nil, - link_lattes: nil, - orientador: nil, - campus_nome: nil, - usuario: nil, - orientandos: nil - } - - test "when all params are valid, updates a pesquisador", %{campus_nome: campus_nome} do - assert {:ok, pesquisador} = - @valid_attrs - |> Map.put(:campus_nome, campus_nome) - |> then(&Database.create(Pesquisador, &1)) - - update_attrs = Map.put(@update_attrs, :campus_nome, campus_nome) - - assert {:ok, updated_pesquisador} = - Database.update( - Pesquisadores.query(), - &Pesquisador.changeset/2, - pesquisador.usuario_cpf, - update_attrs, - Pesquisadores.relationships() - ) - - for key <- Map.keys(@update_attrs) do - cond do - key == :contato -> - contato = Map.get(updated_pesquisador, key) - contato_attrs = Map.get(@update_attrs, key) - assert contato.email == contato_attrs.email - assert contato.endereco == contato_attrs.endereco - assert contato.celular == contato_attrs.celular - - key == :usuario -> - usuario = Map.get(updated_pesquisador, key) - usuario_attrs = Map.get(@update_attrs, key) - assert usuario.cpf == usuario_attrs.cpf - assert usuario.nome_completo == usuario_attrs.nome_completo - assert usuario.data_nascimento == usuario_attrs.data_nascimento - - true -> - assert Map.get(updated_pesquisador, key) == Map.get(@update_attrs, key) - end - end - end - - test "when params are invalid, returns an error changeset", %{campus_nome: campus_nome} do - assert {:ok, pesquisador} = - @valid_attrs - |> Map.put(:campus_nome, campus_nome) - |> then(&Database.create(Pesquisador, &1)) - - assert {:error, %Ecto.Changeset{}} = - Database.update( - Pesquisadores.query(), - &Pesquisador.changeset/2, - pesquisador.usuario_cpf, - @invalid_attrs, - Pesquisadores.relationships() - ) - end - end - - describe "exists?/1" do - test "when id is valid, returns true" do - pesquisador = insert(:pesquisador) - - assert pesquisador.usuario_cpf |> Pesquisadores.query_exists() |> Database.exists?() - end - - test "when id is invalid, returns false" do - refute "" |> Pesquisadores.query_exists() |> Database.exists?() - end - end -end diff --git a/test/fuschia/queries/relatorios_test.exs b/test/fuschia/queries/relatorios_test.exs deleted file mode 100644 index 24661b06..00000000 --- a/test/fuschia/queries/relatorios_test.exs +++ /dev/null @@ -1,105 +0,0 @@ -defmodule Fuschia.Queries.RelatoriosTest do - use Fuschia.DataCase, async: true - - import Fuschia.Factory - - alias Fuschia.Database - alias Fuschia.Entities.Relatorio - alias Fuschia.Queries.Relatorios - - @moduletag :unit - - describe "list/0" do - test "return all relatorios in database" do - insert(:relatorio) - - relatorio = Database.one(Relatorios.query()) - - assert [relatorio] == Database.list(Relatorios.query()) - end - end - - describe "list_by_pesquisador/1" do - test "return all relatorio in database" do - insert(:relatorio) - - relatorio = Database.one(Relatorios.query()) - - assert [relatorio] == - relatorio.pesquisador_cpf |> Relatorios.query_by_pesquisador() |> Database.list() - end - end - - describe "one/1" do - test "when numero is valid, returns a relatorio" do - insert(:relatorio) - - relatorio = Database.one(Relatorios.query()) - - assert relatorio == - Database.get_by(Relatorios.query(), ano: relatorio.ano, mes: relatorio.mes) - end - - test "when id is invalid, returns nil" do - assert Relatorios.query() |> Database.get_by(ano: 0, mes: 0) |> is_nil() - end - end - - describe "create/1" do - @invalid_attrs %{ - ano: nil, - mes: nil, - link: nil, - tipo: nil, - pesquisador_cpf: nil - } - - test "when all params are valid, creates a relatorio" do - valid_attrs = params_for(:relatorio) - - assert {:ok, %Relatorio{}} = Database.create(Relatorio, valid_attrs) - end - - test "when params are invalid, returns an error changeset" do - assert {:error, %Ecto.Changeset{}} = Database.create(Relatorio, @invalid_attrs) - end - end - - describe "update/1" do - @update_attrs %{ - ano: Date.utc_today().year - 2, - mes: Integer.mod(Date.utc_today().month + 1, 12), - link: "https://example.com", - tipo: "trimestral" - } - - @invalid_attrs %{ - ano: nil, - mes: nil, - link: nil, - tipo: nil, - pesquisador_cpf: nil - } - - test "when all params are valid, updates a midia" do - attrs = params_for(:relatorio) - - assert {:ok, relatorio} = Database.create(Relatorio, attrs) - - assert {:ok, updated_relatorio} = Database.update_struct(relatorio, @update_attrs) - - assert updated_relatorio.ano == @update_attrs.ano - assert updated_relatorio.mes == @update_attrs.mes - assert updated_relatorio.link == @update_attrs.link - assert updated_relatorio.tipo == @update_attrs.tipo - end - - test "when params are invalid, returns an error changeset" do - attrs = params_for(:relatorio) - - assert {:ok, relatorio} = Database.create(Relatorio, attrs) - - assert {:error, %Ecto.Changeset{}} = Database.update_struct(relatorio, @invalid_attrs) - end - end -end diff --git a/test/support/factories/auth_log_factory.ex b/test/support/factories/auth_log_factory.ex index bfb7d3c0..d9573c18 100644 --- a/test/support/factories/auth_log_factory.ex +++ b/test/support/factories/auth_log_factory.ex @@ -1,7 +1,7 @@ defmodule Fuschia.AuthLogFactory do @moduledoc false - alias Fuschia.Accounts.Models.AuthLogModel + alias Fuschia.Accounts.Models.AuthLog defmacro __using__(_opts) do quote do @@ -10,7 +10,7 @@ defmodule Fuschia.AuthLogFactory do user_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" - %AuthLogModel{ + %AuthLog{ ip: "127.0.0.1", user_agent: user_agent, user_cpf: 1 diff --git a/test/support/factories/campus_factory.ex b/test/support/factories/campus_factory.ex index 0fa655a0..89225464 100644 --- a/test/support/factories/campus_factory.ex +++ b/test/support/factories/campus_factory.ex @@ -3,13 +3,13 @@ defmodule Fuschia.CampusFactory do defmacro __using__(_opts) do quote do - alias Fuschia.ModuloPesquisa.Models.CampusModel + alias Fuschia.ModuloPesquisa.Models.Campus @spec campus_factory :: Campus.t() def campus_factory do cidade = insert(:cidade) - %CampusModel{ + %Campus{ id: Nanoid.generate_non_secure(), nome: sequence(:nome, &"Campus #{&1}"), cidade: cidade diff --git a/test/support/factories/cidade_factory.ex b/test/support/factories/cidade_factory.ex index cc6749e9..9a52ac16 100644 --- a/test/support/factories/cidade_factory.ex +++ b/test/support/factories/cidade_factory.ex @@ -3,11 +3,11 @@ defmodule Fuschia.CidadeFactory do defmacro __using__(_opts) do quote do - alias Fuschia.ModuloPesquisa.Models.CidadeModel + alias Fuschia.ModuloPesquisa.Models.Cidade @spec cidade_factory :: Cidade.t() def cidade_factory do - %CidadeModel{ + %Cidade{ id: Nanoid.generate_non_secure(), municipio: sequence(:municipio, &"Cidade #{&1}") } diff --git a/test/support/factories/contato_factory.ex b/test/support/factories/contato_factory.ex index 41331d08..ab7bd5ac 100644 --- a/test/support/factories/contato_factory.ex +++ b/test/support/factories/contato_factory.ex @@ -3,11 +3,11 @@ defmodule Fuschia.ContatoFactory do defmacro __using__(_opts) do quote do - alias Fuschia.Accounts.Models.ContatoModel + alias Fuschia.Accounts.Models.Contato @spec contato_factory :: Contato.t() def contato_factory do - %ContatoModel{ + %Contato{ email: sequence(:email, &"test-#{&1}@example.com"), celular: sequence(:celular, ["(22)12345-6789"]), endereco: sequence(:endereco, &"Teste, Rua teste, número #{&1}") diff --git a/test/support/factories/linha_pesquisa_factory.ex b/test/support/factories/linha_pesquisa_factory.ex index 1d852bab..d42bc12e 100644 --- a/test/support/factories/linha_pesquisa_factory.ex +++ b/test/support/factories/linha_pesquisa_factory.ex @@ -3,13 +3,13 @@ defmodule Fuschia.LinhaPesquisaFactory do defmacro __using__(_opts) do quote do - alias Fuschia.ModuloPesquisa.Models.LinhaPesquisaModel + alias Fuschia.ModuloPesquisa.Models.LinhaPesquisa @spec linha_pesquisa_factory :: LinhaPesquisa.t() def linha_pesquisa_factory do nucleo = insert(:nucleo) - %LinhaPesquisaModel{ + %LinhaPesquisa{ id: Nanoid.generate_non_secure(), numero: sequence(:numero, Enum.to_list(1..21)), descricao_curta: sequence(:descricao_curta, &"Descricao LinhaPesquisa Curta #{&1}"), diff --git a/test/support/factories/midia_factory.ex b/test/support/factories/midia_factory.ex index 19d69983..ceeb527e 100644 --- a/test/support/factories/midia_factory.ex +++ b/test/support/factories/midia_factory.ex @@ -3,13 +3,13 @@ defmodule Fuschia.MidiaFactory do defmacro __using__(_opts) do quote do - alias Fuschia.ModuloPesquisa.Models.MidiaModel + alias Fuschia.ModuloPesquisa.Models.Midia @spec midia_factory :: Midia.t() def midia_factory do pesquisador = insert(:pesquisador) - %MidiaModel{ + %Midia{ id: Nanoid.generate_non_secure(), pesquisador: pesquisador, tipo: sequence(:tipo, ["video", "documento", "imagem"]), diff --git a/test/support/factories/nucleo_factory.ex b/test/support/factories/nucleo_factory.ex index dee71715..8f2a225c 100644 --- a/test/support/factories/nucleo_factory.ex +++ b/test/support/factories/nucleo_factory.ex @@ -3,11 +3,11 @@ defmodule Fuschia.NucleoFactory do defmacro __using__(_opts) do quote do - alias Fuschia.ModuloPesquisa.Models.NucleoModel + alias Fuschia.ModuloPesquisa.Models.Nucleo @spec nucleo_factory :: Nucleo.t() def nucleo_factory do - %NucleoModel{ + %Nucleo{ id: Nanoid.generate_non_secure(), nome: sequence(:nome, &"Nucleo #{&1}"), descricao: sequence(:descricao, &"Descricao Nucleo #{&1}") diff --git a/test/support/factories/pesquisador_factory.ex b/test/support/factories/pesquisador_factory.ex index 8eebe743..dab15916 100644 --- a/test/support/factories/pesquisador_factory.ex +++ b/test/support/factories/pesquisador_factory.ex @@ -3,14 +3,14 @@ defmodule Fuschia.PesquisadorFactory do defmacro __using__(_opts) do quote do - alias Fuschia.ModuloPesquisa.Models.PesquisadorModel + alias Fuschia.ModuloPesquisa.Models.Pesquisador @spec pesquisador_factory :: Pesquisador.t() def pesquisador_factory do campus = insert(:campus) usuario = build(:user) - %PesquisadorModel{ + %Pesquisador{ id: Nanoid.generate_non_secure(), usuario: usuario, minibiografia: sequence(:minibiografia, &"Esta e minha minibiografia gerada: #{&1}"), diff --git a/test/support/factories/relatorio_factory.ex b/test/support/factories/relatorio_factory.ex index 38f7eac5..325d8ccb 100644 --- a/test/support/factories/relatorio_factory.ex +++ b/test/support/factories/relatorio_factory.ex @@ -3,13 +3,13 @@ defmodule Fuschia.RelatorioFactory do defmacro __using__(_opts) do quote do - alias Fuschia.ModuloPesquisa.Models.RelatorioModel + alias Fuschia.ModuloPesquisa.Models.Relatorio @spec relatorio_factory :: Relatorio.t() def relatorio_factory do pesquisador = insert(:pesquisador) - %RelatorioModel{ + %Relatorio{ id: Nanoid.generate_non_secure(), pesquisador: pesquisador, tipo: sequence(:tipo, ["mensal", "trimestral", "anual"]), diff --git a/test/support/factories/user_factory.ex b/test/support/factories/user_factory.ex index 6f29e18b..fa4a211d 100644 --- a/test/support/factories/user_factory.ex +++ b/test/support/factories/user_factory.ex @@ -4,8 +4,8 @@ defmodule Fuschia.UserFactory do defmacro __using__(_opts) do quote do alias Fuschia.Accounts - alias Fuschia.Accounts.Models.UserModel - alias Fuschia.Accounts.Queries.UserQueries + alias Fuschia.Accounts.Models.User, as: UserModel + alias Fuschia.Accounts.Queries.User, as: UserQueries alias Fuschia.Database def unique_user_email, do: "user#{System.unique_integer()}@example.com" diff --git a/test/support/test_support.ex b/test/support/test_support.ex index 50eb36aa..55a404eb 100644 --- a/test/support/test_support.ex +++ b/test/support/test_support.ex @@ -4,8 +4,8 @@ defmodule CoreWeb.TestSupport do """ import Plug.Conn - alias Fuschia.Accounts.Models.ApiKeyModel - alias Fuschia.Accounts.Queries.ApiKeyQueries + alias Fuschia.Accounts.Models.ApiKey, as: ApiKeyModel + alias Fuschia.Accounts.Queries.ApiKey, as: ApiKeyQueries alias Fuschia.Database alias FuschiaWeb.Auth.Guardian