From e27f0361adaeab202df33febf77708da3708e641 Mon Sep 17 00:00:00 2001 From: Pavel Vesnin Date: Mon, 22 Jan 2018 16:29:17 +0200 Subject: [PATCH] [patch] EHealth-1721 - view response (#1755) --- lib/ehealth/web/views/legal_entity_view.ex | 54 ++++++++++--------- .../prm_factories/legal_entity_factory.ex | 4 ++ .../legal_entity_controller_test.exs | 8 +++ 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/lib/ehealth/web/views/legal_entity_view.ex b/lib/ehealth/web/views/legal_entity_view.ex index 5e949f6b6..0540a306c 100644 --- a/lib/ehealth/web/views/legal_entity_view.ex +++ b/lib/ehealth/web/views/legal_entity_view.ex @@ -3,9 +3,35 @@ defmodule EHealth.Web.LegalEntityView do Sample view for LegalEntitys controller. """ use EHealth.Web, :view - alias EHealth.LegalEntities.LegalEntity + @fields ~w( + id + name + short_name + public_name + status + type + owner_property_type + legal_form + edrpou + kveds + addresses + phones + email + is_active + inserted_by + updated_by + inserted_at + updated_at + nhs_verified + mis_verified + archive + website + beneficiary + receiver_funds_code + )a + def render("index.json", %{legal_entities: legal_entities}) do render_many(legal_entities, __MODULE__, "legal_entity.json") end @@ -17,29 +43,9 @@ defmodule EHealth.Web.LegalEntityView do def render("legal_entity.json", %{legal_entity: %LegalEntity{} = legal_entity}) do %{medical_service_provider: msp} = legal_entity - %{ - id: legal_entity.id, - name: legal_entity.name, - short_name: legal_entity.short_name, - public_name: legal_entity.public_name, - status: legal_entity.status, - type: legal_entity.type, - owner_property_type: legal_entity.owner_property_type, - legal_form: legal_entity.legal_form, - edrpou: legal_entity.edrpou, - kveds: legal_entity.kveds, - addresses: legal_entity.addresses, - phones: legal_entity.phones, - email: legal_entity.email, - is_active: legal_entity.is_active, - inserted_by: legal_entity.inserted_by, - updated_by: legal_entity.updated_by, - inserted_at: legal_entity.inserted_at, - updated_at: legal_entity.updated_at, - nhs_verified: legal_entity.nhs_verified, - mis_verified: legal_entity.mis_verified, - medical_service_provider: render_one(msp, __MODULE__, "medical_service_provider.json") - } + legal_entity + |> Map.take(@fields) + |> Map.put(:medical_service_provider, render_one(msp, __MODULE__, "medical_service_provider.json")) end def render("legal_entity.json", %{legal_entity: legal_entity}) do diff --git a/test/support/prm_factories/legal_entity_factory.ex b/test/support/prm_factories/legal_entity_factory.ex index df392822c..a706530de 100644 --- a/test/support/prm_factories/legal_entity_factory.ex +++ b/test/support/prm_factories/legal_entity_factory.ex @@ -22,6 +22,10 @@ defmodule EHealth.PRMFactories.LegalEntityFactory do mis_verified: "VERIFIED", type: "MSP", nhs_verified: false, + website: "http://example.com", + archive: [%{"date" => "2012-12-29", "place" => "Житомир вул. Малярів, буд. 211, корп. 2, оф. 1"}], + beneficiary: "Марко Вовчок", + receiver_funds_code: "088912", updated_by: UUID.generate(), inserted_by: UUID.generate(), created_by_mis_client_id: UUID.generate(), diff --git a/test/web/controllers/legal_entity_controller_test.exs b/test/web/controllers/legal_entity_controller_test.exs index 5a78efa7e..49c445d80 100644 --- a/test/web/controllers/legal_entity_controller_test.exs +++ b/test/web/controllers/legal_entity_controller_test.exs @@ -172,6 +172,10 @@ defmodule EHealth.Web.LegalEntityControllerTest do assert id == resp["data"]["id"] assert Map.has_key?(resp["data"], "medical_service_provider") + assert Map.has_key?(resp["data"], "website") + assert Map.has_key?(resp["data"], "archive") + assert Map.has_key?(resp["data"], "beneficiary") + assert Map.has_key?(resp["data"], "receiver_funds_code") refute Map.has_key?(resp, "paging") assert_security_in_urgent_response(resp) end @@ -223,6 +227,10 @@ defmodule EHealth.Web.LegalEntityControllerTest do resp = json_response(conn, 200) assert "CLOSED" == resp["data"]["status"] + assert Map.has_key?(resp["data"], "website") + assert Map.has_key?(resp["data"], "archive") + assert Map.has_key?(resp["data"], "beneficiary") + assert Map.has_key?(resp["data"], "receiver_funds_code") end test "deactivate legal entity with OWNER employee", %{conn: conn} do