Skip to content

Commit

Permalink
[patch] EHealth-1721 - view response (#1755)
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelVesnin authored Jan 22, 2018
1 parent 96bf4fe commit e27f036
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
54 changes: 30 additions & 24 deletions lib/ehealth/web/views/legal_entity_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/support/prm_factories/legal_entity_factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 8 additions & 0 deletions test/web/controllers/legal_entity_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e27f036

Please sign in to comment.