Skip to content

Commit

Permalink
feat: data_reference controller (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
pichoemr authored Apr 1, 2022
1 parent e3d1c95 commit 6273cf7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule LenraWeb.DataReferenceController do
use LenraWeb, :controller

alias Lenra.DataReferencesServices

def create(conn, params) do
with {:ok, inserted_reference: reference} <- DataReferencesServices.create(params) do
conn
|> assign_data(:inserted_reference, reference)
|> reply
end
end

def delete(conn, params) do
with {:ok, deleted_reference: reference} <- DataReferencesServices.delete(params) do
conn
|> assign_data(:deleted_reference, reference)
|> reply
end
end
end
40 changes: 40 additions & 0 deletions apps/lenra_web/test/controllers/data_reference_controller_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
defmodule LenraWeb.DataReferenceControllerTest do
@moduledoc """
Test the `LenraWeb.DataReferenceController` module
"""

use LenraWeb.ConnCase, async: true

alias Lenra.{Environment, LenraApplication, Repo}

setup %{conn: conn} do
{:ok, %{conn: conn}}
end

defp create_app_and_get_env(conn) do
post(conn, Routes.apps_path(conn, :create), %{
"name" => "test",
"color" => "ffffff",
"icon" => 12
})

Repo.get_by(Environment, application_id: Enum.at(Repo.all(LenraApplication), 0).id)
end

# TODO make tests when route are defined
describe "LenraWeb.DataReferenceController.create_2/1" do
test "should create data if params valid" do
end

test "should return error if params not valid" do
end
end

describe "LenraWeb.DataReferenceController.delete_1/1" do
test "should delete data if id valid" do
end

test "should return error if id invalid" do
end
end
end

0 comments on commit 6273cf7

Please sign in to comment.