Commit 3fb0dcf7 authored by Mayel's avatar Mayel

fix some tests

parent 3ed3b6e1
Pipeline #215223899 failed with stage
in 1 minute and 6 seconds
......@@ -12,7 +12,7 @@ defmodule CommonsPub.Web.AdminLive do
}
def mount(params, session, socket) do
IO.inspect(session)
# IO.inspect(session)
socket = init_assigns(params, session, socket)
{:ok,
......
......@@ -39,7 +39,7 @@ defmodule CommonsPub.Web.SearchLive do
search = CommonsPub.Search.search(q, nil, ["index_type"], facet_filters)
IO.inspect(search)
IO.inspect(search: search)
hits =
if(Map.has_key?(search, "hits") and length(search["hits"])) do
......
......@@ -268,8 +268,8 @@ defmodule CommonsPub.Tag.Categories do
def update(user, %Category{} = category, attrs) do
category = Repo.preload(category, [:profile, :character])
IO.inspect(category)
IO.inspect(attrs)
# IO.inspect(category)
# IO.inspect(attrs)
Repo.transact_with(fn ->
# :ok <- publish(category, :updated)
......
......@@ -11,7 +11,7 @@ defmodule CommonsPub.Web.SettingsLive do
}
def mount(params, session, socket) do
IO.inspect(session)
# IO.inspect(session)
socket = init_assigns(params, session, socket)
{:ok,
......
......@@ -14,7 +14,7 @@ defmodule ValueFlows.Agent.People do
end
def person(id, signed_in_user) do
IO.inspect(id)
# IO.inspect(id)
case CommonsPub.Users.one([:default, :geolocation, id: id, user: signed_in_user]) do
{:ok, item} -> item |> ValueFlows.Agent.Agents.character_to_agent()
......
......@@ -126,6 +126,9 @@ defmodule ValueFlows.Hydration do
resource_inventoried_as: [
resolve: &ValueFlows.Planning.Intent.GraphQL.fetch_resource_inventoried_as_edge/3
],
available_quantity: [
resolve: &ValueFlows.Util.GraphQL.available_quantity_edge/3
],
resource_quantity: [
resolve: &ValueFlows.Util.GraphQL.resource_quantity_edge/3
],
......
......@@ -367,7 +367,7 @@ defmodule ValueFlows.Observation.EconomicResource.GraphQL do
def fetch_state_edge(%{state_id: id} = thing, _, _) when is_binary(id) do
thing = EconomicResources.preload_state(thing)
{:ok, Map.get(thing, :conforms_to)}
{:ok, Map.get(thing, :state)}
end
......
......@@ -82,7 +82,7 @@ defmodule ValueFlows.Planning.Intent do
@required ~w(name is_public action_id)a
@cast @required ++
~w(note at_location_id is_disabled image_id context_id input_of_id output_of_id)a ++
~w(resource_conforms_to_id resource_inventoried_as_id provider_id receiver_id)a
~w(available_quantity_id resource_quantity_id effort_quantity_id resource_conforms_to_id resource_inventoried_as_id provider_id receiver_id)a
def create_changeset(%User{} = creator, attrs) do
%__MODULE__{}
......
......@@ -312,8 +312,11 @@ defmodule ValueFlows.Simulate do
overrides = Map.merge(overrides, measures)
{:ok, event} = EconomicEvents.create(user, economic_event(overrides))
event
with {:ok, event} <- EconomicEvents.create(user, economic_event(overrides)) do
event
else e ->
e
end
end
def fake_process!(user, overrides \\ %{}) do
......
......@@ -11,7 +11,7 @@ defmodule Valueflows.Agent.Person.GraphQLTest do
import ValueFlows.Simulate
import ValueFlows.Test.Faking
@debug true
@debug false
@schema CommonsPub.Web.GraphQL.Schema
describe "person" do
......@@ -68,11 +68,9 @@ defmodule Valueflows.Agent.Person.GraphQLTest do
unit
)
IO.inspect(event: event)
# IO.inspect(
# resource: ValueFlows.Observation.EconomicResource.EconomicResources.many(agent_id: user.id)
# )
# IO.inspect(intent: intent)
# IO.inspect(resource: resource)
# IO.inspect(event: event)
assert queried =
CommonsPub.Web.GraphQL.QueryHelper.run_query_id(
......
......@@ -24,8 +24,11 @@ defmodule ValueFlows.Observation.EconomicEvent.EventsGraphQLTest do
describe "EconomicEvent" do
test "fetches an economic event by ID (via HTTP)" do
user = fake_user!()
unit = fake_unit!(user)
provider = fake_agent!()
receiver = fake_agent!()
action = action()
event =
......@@ -36,9 +39,9 @@ defmodule ValueFlows.Observation.EconomicEvent.EventsGraphQLTest do
input_of: fake_process!(user).id,
output_of: fake_process!(user).id,
resource_conforms_to: fake_resource_specification!(user).id,
to_resource_inventoried_as: fake_economic_resource!(user).id,
resource_inventoried_as: fake_economic_resource!(user).id
})
to_resource_inventoried_as: fake_economic_resource!(user, %{}, unit).id,
resource_inventoried_as: fake_economic_resource!(user, %{}, unit).id
}, unit)
q = economic_event_query()
conn = user_conn(user)
......@@ -50,13 +53,14 @@ defmodule ValueFlows.Observation.EconomicEvent.EventsGraphQLTest do
user = fake_user!()
location = fake_geolocation!(user)
unit = fake_unit!(user)
provider = fake_agent!()
receiver = fake_agent!()
action = action()
triggered_by = fake_economic_event!(user)
triggered_by = fake_economic_event!(user, %{}, unit)
event =
fake_economic_event!(user, %{
......@@ -68,10 +72,10 @@ defmodule ValueFlows.Observation.EconomicEvent.EventsGraphQLTest do
output_of: fake_process!(user).id,
triggered_by: triggered_by.id,
resource_conforms_to: fake_resource_specification!(user).id,
to_resource_inventoried_as: fake_economic_resource!(user).id,
resource_inventoried_as: fake_economic_resource!(user).id,
to_resource_inventoried_as: fake_economic_resource!(user, %{}, unit).id,
resource_inventoried_as: fake_economic_resource!(user, %{}, unit).id,
at_location: location.id
})
}, unit)
# IO.inspect(created: event)
......@@ -90,15 +94,16 @@ defmodule ValueFlows.Observation.EconomicEvent.EventsGraphQLTest do
test "fails if has been deleted" do
user = fake_user!()
unit = fake_unit!(user)
event =
fake_economic_event!(user, %{
input_of: fake_process!(user).id,
output_of: fake_process!(user).id,
resource_conforms_to: fake_resource_specification!(user).id,
to_resource_inventoried_as: fake_economic_resource!(user).id,
resource_inventoried_as: fake_economic_resource!(user).id
})
to_resource_inventoried_as: fake_economic_resource!(user, %{}, unit).id,
resource_inventoried_as: fake_economic_resource!(user, %{}, unit).id
}, unit)
q = economic_event_query()
conn = user_conn(user)
......@@ -160,6 +165,7 @@ defmodule ValueFlows.Observation.EconomicEvent.EventsGraphQLTest do
some(5, fn ->
fake_economic_event!(user)
end)
after_event = List.first(events)
# deleted
some(2, fn ->
......@@ -181,20 +187,26 @@ defmodule ValueFlows.Observation.EconomicEvent.EventsGraphQLTest do
describe "EconomicEvent.track" do
test "Returns a list of EconomicResources or Processes" do
user = fake_user!()
unit = fake_unit!(user)
process = fake_process!(user)
another_process = fake_process!(user)
resource = fake_economic_resource!(user)
another_resource = fake_economic_resource!(user)
resource = fake_economic_resource!(user, %{}, unit)
another_resource = fake_economic_resource!(user, %{}, unit)
event =
fake_economic_event!(user, %{
input_of: process.id,
output_of: another_process.id,
resource_inventoried_as: resource.id,
to_resource_inventoried_as: another_resource.id,
action: "transfer"
})
fake_economic_event!(
user,
%{
input_of: process.id,
output_of: another_process.id,
resource_inventoried_as: resource.id,
to_resource_inventoried_as: another_resource.id,
action: "transfer"
},
unit
)
q = economic_event_query(fields: [track: [:__typename]])
conn = user_conn(user)
......@@ -207,20 +219,26 @@ defmodule ValueFlows.Observation.EconomicEvent.EventsGraphQLTest do
describe "EconomicEvent.trace" do
test "Returns a list of economic events that are outputs" do
user = fake_user!()
unit = fake_unit!(user)
process = fake_process!(user)
another_process = fake_process!(user)
resource = fake_economic_resource!(user)
another_resource = fake_economic_resource!(user)
resource = fake_economic_resource!(user, %{}, unit)
another_resource = fake_economic_resource!(user, %{}, unit)
event =
fake_economic_event!(user, %{
input_of: process.id,
output_of: another_process.id,
resource_inventoried_as: resource.id,
to_resource_inventoried_as: another_resource.id,
action: "transfer"
})
fake_economic_event!(
user,
%{
input_of: process.id,
output_of: another_process.id,
resource_inventoried_as: resource.id,
to_resource_inventoried_as: another_resource.id,
action: "transfer"
},
unit
)
q = economic_event_query(fields: [trace: [:__typename]])
conn = user_conn(user)
......@@ -372,8 +390,9 @@ defmodule ValueFlows.Observation.EconomicEvent.EventsGraphQLTest do
test "create an economic event triggered by another economic event" do
user = fake_user!()
unit = fake_unit!(user)
trigger = fake_economic_event!(user)
trigger = fake_economic_event!(user, %{}, unit)
q = create_economic_event_mutation(fields: [triggered_by: [:id]])
conn = user_conn(user)
......
......@@ -398,21 +398,16 @@ defmodule ValueFlows.Observation.EconomicEvent.EconomicEventsResourcesTest do
resource_inventoried_as = fake_economic_resource!(user, %{}, unit)
to_resource_inventoried_as = fake_economic_resource!(user, %{}, unit2)
try do
event = fake_economic_event!(
user,
%{
to_resource_inventoried_as: to_resource_inventoried_as.id,
resource_inventoried_as: resource_inventoried_as.id,
action: "transfer-custody"
},
unit
)
refute event
rescue
MatchError ->
:ok
end
assert {:error, e} =
fake_economic_event!(
user,
%{
to_resource_inventoried_as: to_resource_inventoried_as.id,
resource_inventoried_as: resource_inventoried_as.id,
action: "transfer-custody"
},
unit
)
end
end
......
......@@ -16,15 +16,16 @@ defmodule ValueFlows.Observation.EconomicEvent.EconomicEventsTest do
describe "one" do
test "fetches an existing economic event by ID" do
user = fake_user!()
unit = fake_unit!(user)
event =
fake_economic_event!(user, %{
input_of: fake_process!(user).id,
output_of: fake_process!(user).id,
resource_conforms_to: fake_resource_specification!(user).id,
to_resource_inventoried_as: fake_economic_resource!(user).id,
resource_inventoried_as: fake_economic_resource!(user).id
})
to_resource_inventoried_as: fake_economic_resource!(user, %{}, unit).id,
resource_inventoried_as: fake_economic_resource!(user, %{}, unit).id
}, unit)
assert {:ok, fetched} = EconomicEvents.one(id: event.id)
assert_economic_event(fetched)
......@@ -37,62 +38,97 @@ defmodule ValueFlows.Observation.EconomicEvent.EconomicEventsTest do
test "Return the process to which it is an input" do
user = fake_user!()
process = fake_process!(user)
event = fake_economic_event!(user, %{
input_of: process.id,
action: "consume"
})
event =
fake_economic_event!(user, %{
input_of: process.id,
action: "consume"
})
assert {:ok, [tracked_process]} = EconomicEvents.track(event)
assert process.id == tracked_process.id
end
test "return an economic Resource which it affected as the output of a process" do
user = fake_user!()
resource = fake_economic_resource!(user)
another_resource = fake_economic_resource!(user)
unit = fake_unit!(user)
resource = fake_economic_resource!(user, %{}, unit)
another_resource = fake_economic_resource!(user, %{}, unit)
process = fake_process!(user)
event = fake_economic_event!(user, %{
output_of: process.id,
action: "produce"
})
event_a = fake_economic_event!(user, %{
output_of: process.id,
action: "produce",
resource_inventoried_as: resource.id
})
event_b = fake_economic_event!(user, %{
output_of: process.id,
action: "produce",
resource_inventoried_as: another_resource.id
})
event =
fake_economic_event!(
user,
%{
output_of: process.id,
action: "produce"
},
unit
)
event_a =
fake_economic_event!(
user,
%{
output_of: process.id,
action: "produce",
resource_inventoried_as: resource.id
},
unit
)
event_b =
fake_economic_event!(
user,
%{
output_of: process.id,
action: "produce",
resource_inventoried_as: another_resource.id
},
unit
)
assert {:ok, resources} = EconomicEvents.track(event)
assert Enum.map(resources, &(&1.id)) == [resource.id, another_resource.id]
assert Enum.map(resources, & &1.id) == [resource.id, another_resource.id]
end
test "if it is a transfer or move event, the EconomicResource labelled toResourceInventoriedAs" do
user = fake_user!()
resource = fake_economic_resource!(user)
event = fake_economic_event!(user, %{
action: "transfer",
to_resource_inventoried_as: resource.id,
provider: user.id,
receiver: user.id
})
unit = fake_unit!(user)
resource = fake_economic_resource!(user, %{}, unit)
event =
fake_economic_event!(user, %{
action: "transfer",
to_resource_inventoried_as: resource.id,
provider: user.id,
receiver: user.id
}, unit)
assert {:ok, [tracked_resource]} = EconomicEvents.track(event)
assert resource.id == tracked_resource.id
end
test "if it is a transfer or move event part of a process, the distinct EconomicResource labelled toResourceInventoriedAs" do
user = fake_user!()
resource = fake_economic_resource!(user)
unit = fake_unit!(user)
resource = fake_economic_resource!(user, %{}, unit)
process = fake_process!(user)
event = fake_economic_event!(user, %{
action: "transfer",
output_of: process.id,
resource_inventoried_as: resource.id,
# to_resource_inventoried_as: resource.id,
provider: user.id,
receiver: user.id
})
event =
fake_economic_event!(user, %{
action: "transfer",
output_of: process.id,
resource_inventoried_as: resource.id,
# to_resource_inventoried_as: resource.id,
provider: user.id,
receiver: user.id
}, unit)
assert {:ok, [tracked_resource]} = EconomicEvents.track(event)
assert resource.id == tracked_resource.id
end
......@@ -102,10 +138,13 @@ defmodule ValueFlows.Observation.EconomicEvent.EconomicEventsTest do
test "Return the process to which it is an output" do
user = fake_user!()
process = fake_process!(user)
event = fake_economic_event!(user, %{
output_of: process.id,
action: "produce"
})
event =
fake_economic_event!(user, %{
output_of: process.id,
action: "produce"
})
assert {:ok, [traced_process]} = EconomicEvents.trace(event)
assert process.id == traced_process.id
......@@ -116,34 +155,50 @@ defmodule ValueFlows.Observation.EconomicEvent.EconomicEventsTest do
resource = fake_economic_resource!(user)
another_resource = fake_economic_resource!(user)
process = fake_process!(user)
event = fake_economic_event!(user, %{
input_of: process.id,
action: "consume"
})
event_a = fake_economic_event!(user, %{
input_of: process.id,
action: "use",
resource_inventoried_as: resource.id
})
event_b = fake_economic_event!(user, %{
input_of: process.id,
action: "cite",
resource_inventoried_as: another_resource.id
})
event =
fake_economic_event!(user, %{
input_of: process.id,
action: "consume"
})
event_a =
fake_economic_event!(user, %{
input_of: process.id,
action: "use",
resource_inventoried_as: resource.id
})
event_b =
fake_economic_event!(user, %{
input_of: process.id,
action: "cite",
resource_inventoried_as: another_resource.id
})
assert {:ok, resources} = EconomicEvents.trace(event)
assert Enum.map(resources, &(&1.id)) == [resource.id, another_resource.id]
assert Enum.map(resources, & &1.id) == [resource.id, another_resource.id]
end
test "if it is a transfer or move event, then the previous
EconomicResource is the resourceInventoriedAs" do
user = fake_user!()
resource = fake_economic_resource!(user)
event = fake_economic_event!(user, %{
action: "transfer",
resource_inventoried_as: resource.id,
provider: user.id,
receiver: user.id
})
unit = fake_unit!(user)
resource = fake_economic_resource!(user, %{}, unit)
event =
fake_economic_event!(
user,
%{
action: "transfer",
resource_inventoried_as: resource.id,
provider: user.id,
receiver: user.id
},
unit
)
assert {:ok, [traced_resource]} = EconomicEvents.trace(event)
assert resource.id == traced_resource.id
end
......@@ -156,7 +211,8 @@ defmodule ValueFlows.Observation.EconomicEvent.EconomicEventsTest do
receiver = fake_agent!()
action = action()
assert {:ok, event} = EconomicEvents.create(
assert {:ok, event} =
EconomicEvents.create(
user,
economic_event(%{
provider: provider.id,
......@@ -216,6 +272,7 @@ defmodule ValueFlows.Observation.EconomicEvent.EconomicEventsTest do
test "can create an economic event with resource_inventoried_as" do
user = fake_user!()
attrs = %{
resource_inventoried_as: fake_economic_resource!(user).id
}
......@@ -333,14 +390,14 @@ defmodule ValueFlows.Observation.EconomicEvent.EconomicEventsTest do
user = fake_user!()
economic_event = fake_economic_event!(user)
assert {:ok, updated} = EconomicEvents.update(economic_event, economic_event(%{note: "test"}))
assert {:ok, updated} =
EconomicEvents.update(economic_event, economic_event(%{note: "test"}))