zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

commit 2c8423ef88201d9429501c0c57db4c742f4ad316
parent d505b75f258cd210f7e3b907e90fd5cdf187757c
Author: srfsh <dev@srf.sh>
Date:   Mon, 29 Aug 2022 11:40:50 +0300

Zenflows{Test,}.VF: add support for multiple images

Diffstat:
Msrc/zenflows/vf/agent.ex | 5+++--
Msrc/zenflows/vf/agent/domain.ex | 6+++++-
Msrc/zenflows/vf/agent/resolv.ex | 9+++++++--
Msrc/zenflows/vf/agent/type.ex | 9++++-----
Msrc/zenflows/vf/economic_event/resolv.ex | 1+
Msrc/zenflows/vf/economic_resource.ex | 9+++++----
Msrc/zenflows/vf/economic_resource/domain.ex | 7++++++-
Msrc/zenflows/vf/economic_resource/resolv.ex | 5+++++
Msrc/zenflows/vf/economic_resource/type.ex | 29+++++++++++++----------------
Msrc/zenflows/vf/intent.ex | 9+++++----
Msrc/zenflows/vf/organization.ex | 9+++++----
Msrc/zenflows/vf/organization/domain.ex | 6+++++-
Msrc/zenflows/vf/organization/resolv.ex | 15+++++++--------
Msrc/zenflows/vf/organization/type.ex | 16++++++----------
Msrc/zenflows/vf/person.ex | 12++++++------
Msrc/zenflows/vf/person/domain.ex | 6+++++-
Msrc/zenflows/vf/person/resolv.ex | 15+++++++--------
Msrc/zenflows/vf/person/type.ex | 16++++++----------
Msrc/zenflows/vf/recipe_resource.ex | 9+++++----
Msrc/zenflows/vf/resource_specification.ex | 9+++++----
Msrc/zenflows/vf/resource_specification/domain.ex | 6+++++-
Msrc/zenflows/vf/resource_specification/resolv.ex | 5+++++
Msrc/zenflows/vf/resource_specification/type.ex | 16++++++----------
Atest/file.test.exs | 265+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtest/help/factory.ex | 34+++++++++++++++++++++++++---------
Mtest/vf/agent/domain.test.exs | 2--
Mtest/vf/agent/type.test.exs | 10----------
Mtest/vf/economic_event/domain.test.exs | 24++++++++++++------------
Mtest/vf/economic_resource/domain.test.exs | 6+++---
Mtest/vf/economic_resource/type.test.exs | 10+++++-----
Mtest/vf/intent/domain.test.exs | 11+++++------
Mtest/vf/intent/type.test.exs | 11++++-------
Mtest/vf/organization/domain.test.exs | 4----
Mtest/vf/organization/type.test.exs | 7++-----
Mtest/vf/person/domain.test.exs | 4----
Mtest/vf/person/type.test.exs | 7++-----
Mtest/vf/recipe_resource/domain.test.exs | 4----
Mtest/vf/recipe_resource/type.test.exs | 7++-----
Mtest/vf/resource_specification/domain.test.exs | 4----
Mtest/vf/resource_specification/type.test.exs | 7++-----
40 files changed, 454 insertions(+), 192 deletions(-)

diff --git a/src/zenflows/vf/agent.ex b/src/zenflows/vf/agent.ex @@ -22,6 +22,7 @@ A person or group or organization with economic agency. use Zenflows.DB.Schema, types?: false +alias Zenflows.File alias Zenflows.VF.SpatialThing @type t() :: %__MODULE__{ @@ -29,7 +30,7 @@ alias Zenflows.VF.SpatialThing type: :per | :org, # Person or Organization name: String.t(), note: String.t() | nil, - image: String.t() | nil, + images: [File.t()], primary_location: SpatialThing.t() | nil, # person @@ -50,7 +51,7 @@ schema "vf_agent" do field :type, Ecto.Enum, values: [:per, :org] field :name, :string field :note, :string - field :image, :string + has_many :images, File belongs_to :primary_location, SpatialThing timestamps() diff --git a/src/zenflows/vf/agent/domain.ex b/src/zenflows/vf/agent/domain.ex @@ -39,7 +39,11 @@ def all(params) do Paging.page(Agent, params) end -@spec preload(Agent.t(), :primary_location) :: Agent.t() +@spec preload(Agent.t(), :images | :primary_location) :: Agent.t() +def preload(agent, :images) do + Repo.preload(agent, :images) +end + def preload(agent, :primary_location) do Repo.preload(agent, :primary_location) end diff --git a/src/zenflows/vf/agent/resolv.ex b/src/zenflows/vf/agent/resolv.ex @@ -18,7 +18,7 @@ defmodule Zenflows.VF.Agent.Resolv do @moduledoc "Resolvers of Agents." -alias Zenflows.VF.{Agent, Agent.Domain} +alias Zenflows.VF.Agent.Domain def my_agent(_, %{context: %{req_user: user}}) do {:ok, user} @@ -32,7 +32,12 @@ def agents(params, _) do Domain.all(params) end -def primary_location(%Agent{} = agent, _, _) do +def images(agent, _, _) do + agent = Domain.preload(agent, :images) + {:ok, agent.images} +end + +def primary_location(agent, _, _) do agent = Domain.preload(agent, :primary_location) {:ok, agent.primary_location} end diff --git a/src/zenflows/vf/agent/type.ex b/src/zenflows/vf/agent/type.ex @@ -25,9 +25,8 @@ alias Zenflows.VF.{Agent, Agent.Resolv} An informal or formal textual identifier for an agent. Does not imply uniqueness. """ -@image """ -The base64-encoded image binary relevant to the agent, such as a logo, -avatar, photo, etc. +@images """ +The image files relevant to the agent, such as a logo, avatar, photo, etc. """ @note "A textual description or comment." @primary_location """ @@ -44,8 +43,8 @@ interface :agent do @desc @name field :name, non_null(:string) - @desc @image - field :image, :base64 + @desc @images + field :images, list_of(non_null(:file)), resolve: &Resolv.images/3 @desc @note field :note, :string diff --git a/src/zenflows/vf/economic_event/resolv.ex b/src/zenflows/vf/economic_event/resolv.ex @@ -32,6 +32,7 @@ end def create_economic_event(%{event: evt_params} = params, _) do res_params = params[:new_inventoried_resource] + case Domain.create(evt_params, res_params) do {:ok, evt, res, nil} -> evt = Map.put(evt, :resource_inventoried_as, res) # tiny optimization diff --git a/src/zenflows/vf/economic_resource.ex b/src/zenflows/vf/economic_resource.ex @@ -20,6 +20,7 @@ defmodule Zenflows.VF.EconomicResource do use Zenflows.DB.Schema +alias Zenflows.File alias Zenflows.VF.{ Action, Agent, @@ -36,7 +37,7 @@ alias Zenflows.VF.{ @type t() :: %__MODULE__{ name: String.t(), note: String.t() | nil, - image: String.t() | nil, + images: [File.t()], tracking_identifier: String.t() | nil, classified_as: [String.t()] | nil, conforms_to: ResourceSpecification.t(), @@ -60,7 +61,7 @@ alias Zenflows.VF.{ schema "vf_economic_resource" do field :name, :string field :note, :string - field :image, :string + has_many :images, File field :tracking_identifier, :string field :classified_as, {:array, :string} belongs_to :conforms_to, ResourceSpecification @@ -90,7 +91,7 @@ end onhand_quantity_has_unit_id onhand_quantity_has_numerical_value ]a @cast @reqr ++ ~w[ - note image tracking_identifier + note tracking_identifier classified_as stage_id state_id current_location_id lot_id contained_in_id unit_of_effort_id @@ -104,9 +105,9 @@ def chgset(schema \\ %__MODULE__{}, params) do |> Changeset.validate_required(@reqr) |> Validate.name(:name) |> Validate.note(:note) - |> Validate.img(:image) |> Validate.class(:classified_as) |> require_quantity_units_same() + |> Changeset.cast_assoc(:images, with: &File.chgset/2) |> Changeset.assoc_constraint(:conforms_to) |> Changeset.assoc_constraint(:accounting_quantity_has_unit) |> Changeset.assoc_constraint(:onhand_quantity_has_unit) diff --git a/src/zenflows/vf/economic_resource/domain.ex b/src/zenflows/vf/economic_resource/domain.ex @@ -73,11 +73,16 @@ def delete(id) do end end -@spec preload(EconomicResource.t(), :conforms_to | :accounting_quantity +@spec preload(EconomicResource.t(), :images + | :conforms_to | :accounting_quantity | :onhand_quantity | :primary_accountable | :custodian | :stage | :state | :current_location | :lot | :contained_in | :unit_of_effort) :: EconomicResource.t() +def preload(eco_res, :images) do + Repo.preload(eco_res, :images) +end + def preload(eco_res, :conforms_to) do Repo.preload(eco_res, :conforms_to) end diff --git a/src/zenflows/vf/economic_resource/resolv.ex b/src/zenflows/vf/economic_resource/resolv.ex @@ -42,6 +42,11 @@ def delete_economic_resource(%{id: id}, _) do end end +def images(eco_res, _, _) do + eco_res = Domain.preload(eco_res, :images) + {:ok, eco_res.images} +end + def conforms_to(eco_res, _, _) do eco_res = Domain.preload(eco_res, :conforms_to) {:ok, eco_res.conforms_to} diff --git a/src/zenflows/vf/economic_resource/type.ex b/src/zenflows/vf/economic_resource/type.ex @@ -27,8 +27,8 @@ An informal or formal textual identifier for an item. Does not imply uniqueness. """ @note "A textual description or comment." -@image """ -The base64-encoded image binary relevant to the entity, such as a photo, diagram, etc. +@images """ +The image files relevant to the entity, such as a photo, diagram, etc. """ @tracking_identifier """ Sometimes called serial number, used when each item must have a traceable @@ -105,8 +105,8 @@ object :economic_resource do @desc @note field :note, :string - @desc @image - field :image, :base64 + @desc @images + field :images, list_of(non_null(:file)), resolve: &Resolv.images/3 @desc @tracking_identifier field :tracking_identifier, :string @@ -162,8 +162,8 @@ input_object :economic_resource_create_params do @desc @note field :note, :string - @desc @image - field :image, :base64 + @desc @images + field :images, list_of(non_null(:ifile)) @desc @tracking_identifier field :tracking_identifier, :string @@ -172,6 +172,13 @@ input_object :economic_resource_create_params do field :lot_id, :id, name: "lot" end +input_object :economic_resource_update_params do + field :id, non_null(:id) + + @desc @note + field :note, :string +end + object :economic_resource_response do field :economic_resource, non_null(:economic_resource) end @@ -186,16 +193,6 @@ object :economic_resource_connection do field :edges, non_null(list_of(non_null(:economic_resource_edge))) end -input_object :economic_resource_update_params do - field :id, non_null(:id) - - @desc @note - field :note, :string - - @desc @image - field :image, :base64 -end - object :query_economic_resource do field :economic_resource, :economic_resource do arg :id, non_null(:id) diff --git a/src/zenflows/vf/intent.ex b/src/zenflows/vf/intent.ex @@ -22,6 +22,7 @@ to economic events (sometimes through commitments). """ use Zenflows.DB.Schema +alias Zenflows.File alias Zenflows.VF.{ Action, Agent, @@ -54,7 +55,7 @@ alias Zenflows.VF.{ has_point_in_time: DateTime.t() | nil, due: DateTime.t() | nil, finished: boolean(), - image: String.t() | nil, + images: [File.t()], note: String.t() | nil, # in_scope_of: agreed_in: String.t() | nil, @@ -88,7 +89,7 @@ schema "vf_intent" do field :has_point_in_time, :utc_datetime_usec field :due, :utc_datetime_usec field :finished, :boolean, default: false - field :image, :string + has_many :images, File field :note, :string # field :in_scope_of field :agreed_in, :string @@ -103,7 +104,7 @@ end resource_classified_as resource_conforms_to_id resource_inventoried_as_id resource_quantity effort_quantity available_quantity at_location_id has_beginning has_end has_point_in_time due - finished note image agreed_in + finished note agreed_in ]a # in_scope_of_id @doc false @@ -115,7 +116,7 @@ def chgset(schema \\ %__MODULE__{}, params) do |> mutex_check() |> Validate.name(:name) |> Validate.note(:note) - |> Validate.img(:image) + |> Changeset.cast_assoc(:images, with: &File.chgset/2) |> Validate.class(:resource_classified_as) |> Measure.cast(:resource_quantity) |> Measure.cast(:effort_quantity) diff --git a/src/zenflows/vf/organization.ex b/src/zenflows/vf/organization.ex @@ -20,12 +20,13 @@ defmodule Zenflows.VF.Organization do use Zenflows.DB.Schema +alias Zenflows.File alias Zenflows.VF.{SpatialThing, Validate} @type t() :: %__MODULE__{ type: :org, name: String.t(), - image: String.t() | nil, + images: [File.t()], note: String.t() | nil, primary_location: SpatialThing.t() | nil, classified_as: [String.t()] | nil, @@ -35,7 +36,7 @@ alias Zenflows.VF.{SpatialThing, Validate} schema "vf_agent" do field :type, Ecto.Enum, values: [:org], default: :org field :name, :string - field :image, :string + has_many :images, File, foreign_key: :agent_id field :note, :string belongs_to :primary_location, SpatialThing field :classified_as, {:array, :string} @@ -43,7 +44,7 @@ schema "vf_agent" do end @reqr [:name] -@cast @reqr ++ ~w[classified_as image note primary_location_id]a +@cast @reqr ++ ~w[classified_as note primary_location_id]a @doc false @spec chgset(Schema.t(), params()) :: Changeset.t() @@ -53,7 +54,7 @@ def chgset(schema \\ %__MODULE__{}, params) do |> Changeset.validate_required(@reqr) |> Validate.name(:name) |> Validate.note(:note) - |> Validate.img(:image) + |> Changeset.cast_assoc(:images, with: &File.chgset/2) |> Validate.class(:classified_as) |> Changeset.assoc_constraint(:primary_location) end diff --git a/src/zenflows/vf/organization/domain.ex b/src/zenflows/vf/organization/domain.ex @@ -86,7 +86,11 @@ def delete(id) do end end -@spec preload(Organization.t(), :primary_location) :: Organization.t() +@spec preload(Organization.t(), :images | :primary_location) :: Organization.t() +def preload(org, :images) do + Repo.preload(org, :images) +end + def preload(org, :primary_location) do Repo.preload(org, :primary_location) end diff --git a/src/zenflows/vf/organization/resolv.ex b/src/zenflows/vf/organization/resolv.ex @@ -18,7 +18,7 @@ defmodule Zenflows.VF.Organization.Resolv do @moduledoc "Resolvers of Organizations." -alias Zenflows.VF.{Agent, Organization, Organization.Domain} +alias Zenflows.VF.Organization.Domain def organization(params, _) do Domain.one(params) @@ -46,14 +46,13 @@ def delete_organization(%{id: id}, _) do end end -def primary_location(%Organization{} = org, _, _) do - org = Domain.preload(org, :primary_location) - {:ok, org.primary_location} +def images(org, _, _) do + org = Domain.preload(org, :images) + {:ok, org.images} end -# For some reason, Absinthe calls this one instead of the one on -# Zenflows.VF.Agent.Type for queries to Agent itself. -def primary_location(%Agent{} = agent, params, info) do - Agent.Resolv.primary_location(agent, params, info) +def primary_location(org, _, _) do + org = Domain.preload(org, :primary_location) + {:ok, org.primary_location} end end diff --git a/src/zenflows/vf/organization/type.ex b/src/zenflows/vf/organization/type.ex @@ -23,9 +23,8 @@ use Absinthe.Schema.Notation alias Zenflows.VF.Organization.Resolv @name "The name that this agent will be referred to by." -@image """ -The base64-encoded image binary relevant to the agent, such as a logo, -avatar, photo, etc. +@images """ +The image files relevant to the agent, such as a logo, avatar, photo, etc. """ @primary_location """ The main place an agent is located, often an address where activities @@ -49,8 +48,8 @@ object :organization do @desc @name field :name, non_null(:string) - @desc @image - field :image, :base64 + @desc @images + field :images, list_of(non_null(:file)) @desc @primary_location field :primary_location, :spatial_thing, @@ -67,8 +66,8 @@ input_object :organization_create_params do @desc @name field :name, non_null(:string) - @desc @image - field :image, :base64 + @desc @images + field :images, list_of(non_null(:ifile)), resolve: &Resolv.images/3 @desc @note field :note, :string @@ -86,9 +85,6 @@ input_object :organization_update_params do @desc @name field :name, :string - @desc @image - field :image, :base64 - @desc @note field :note, :string diff --git a/src/zenflows/vf/person.ex b/src/zenflows/vf/person.ex @@ -20,12 +20,13 @@ defmodule Zenflows.VF.Person do use Zenflows.DB.Schema +alias Zenflows.File alias Zenflows.VF.{SpatialThing, Validate} @type t() :: %__MODULE__{ type: :per, name: String.t(), - image: String.t() | nil, + images: [File.t()], note: String.t() | nil, primary_location: SpatialThing.t() | nil, user: String.t(), @@ -40,7 +41,7 @@ alias Zenflows.VF.{SpatialThing, Validate} schema "vf_agent" do field :type, Ecto.Enum, values: [:per], default: :per field :name, :string - field :image, :string + has_many :images, File, foreign_key: :agent_id field :note, :string belongs_to :primary_location, SpatialThing field :user, :string @@ -55,7 +56,7 @@ end @insert_reqr ~w[name user email]a @insert_cast @insert_reqr ++ ~w[ - image note primary_location_id + note primary_location_id ecdh_public_key eddsa_public_key ethereum_address @@ -64,7 +65,7 @@ end ]a # TODO: Maybe add email to @update_cast as well? # TODO: Maybe add the pubkeys to @update_cast as well? -@update_cast ~w[name image note primary_location_id user]a +@update_cast ~w[name note primary_location_id user]a # insert changeset @doc false @@ -76,7 +77,7 @@ def chgset(params) do |> Validate.name(:name) |> Validate.name(:user) |> Validate.name(:email) - |> Validate.uri(:image) + |> Changeset.cast_assoc(:images, with: &File.chgset/2) |> Validate.note(:note) |> Validate.key(:ecdh_public_key) |> Validate.key(:eddsa_public_key) @@ -98,7 +99,6 @@ def chgset(schema, params) do |> Changeset.cast(params, @update_cast) |> Validate.name(:name) |> Validate.name(:user) - |> Validate.img(:image) |> Validate.note(:note) |> check_email() |> Changeset.unique_constraint(:user) diff --git a/src/zenflows/vf/person/domain.ex b/src/zenflows/vf/person/domain.ex @@ -90,7 +90,11 @@ def delete(id) do end end -@spec preload(Person.t(), :primary_location) :: Person.t() +@spec preload(Person.t(), :images | :primary_location) :: Person.t() +def preload(per, :images) do + Repo.preload(per, :images) +end + def preload(per, :primary_location) do Repo.preload(per, :primary_location) end diff --git a/src/zenflows/vf/person/resolv.ex b/src/zenflows/vf/person/resolv.ex @@ -18,7 +18,7 @@ defmodule Zenflows.VF.Person.Resolv do @moduledoc "Resolvers of Persons." -alias Zenflows.VF.{Agent, Person, Person.Domain} +alias Zenflows.VF.Person.Domain def person(params, _) do Domain.one(params) @@ -50,14 +50,13 @@ def delete_person(%{id: id}, _) do end end -def primary_location(%Person{} = per, _, _) do - per = Domain.preload(per, :primary_location) - {:ok, per.primary_location} +def images(per, _, _) do + per = Domain.preload(per, :images) + {:ok, per.images} end -# For some reason, Absinthe calls this one instead of the one on -# Zenflows.VF.Agent.Type for queries to Agent itself. -def primary_location(%Agent{} = agent, params, info) do - Agent.Resolv.primary_location(agent, params, info) +def primary_location(per, _, _) do + per = Domain.preload(per, :primary_location) + {:ok, per.primary_location} end end diff --git a/src/zenflows/vf/person/type.ex b/src/zenflows/vf/person/type.ex @@ -23,9 +23,8 @@ use Absinthe.Schema.Notation alias Zenflows.VF.Person.Resolv @name "The name that this agent will be referred to by." -@image """ -The base64-encoded image binary relevant to the agent, such as a logo, -avatar, photo, etc. +@images """ +The image files relevant to the agent, such as a logo, avatar, photo, etc. """ @note "A textual description or comment." @primary_location """ @@ -52,8 +51,8 @@ object :person do @desc @name field :name, non_null(:string) - @desc @image - field :image, :base64 + @desc @images + field :images, list_of(non_null(:file)), resolve: &Resolv.images/3 @desc @note field :note, :string @@ -88,8 +87,8 @@ input_object :person_create_params do @desc @name field :name, non_null(:string) - @desc @image - field :image, :base64 + @desc @images + field :images, list_of(non_null(:ifile)) @desc @note field :note, :string @@ -125,9 +124,6 @@ input_object :person_update_params do @desc @name field :name, :string - @desc @image - field :image, :base64 - @desc @note field :note, :string diff --git a/src/zenflows/vf/recipe_resource.ex b/src/zenflows/vf/recipe_resource.ex @@ -23,6 +23,7 @@ recipe. use Zenflows.DB.Schema +alias Zenflows.File alias Zenflows.VF.{ ResourceSpecification, Unit, @@ -35,7 +36,7 @@ alias Zenflows.VF.{ unit_of_effort: Unit.t() | nil, resource_conforms_to: ResourceSpecification.t() | nil, substitutable: boolean(), - image: String.t() | nil, + images: [File.t()], note: String.t() | nil, } @@ -46,7 +47,7 @@ schema "vf_recipe_resource" do field :resource_classified_as, {:array, :string} belongs_to :resource_conforms_to, ResourceSpecification field :substitutable, :boolean, default: false - field :image, :string + has_many :images, File field :note, :string timestamps() end @@ -55,7 +56,7 @@ end @cast @reqr ++ ~w[ unit_of_resource_id unit_of_effort_id resource_classified_as resource_conforms_to_id - substitutable image note + substitutable note ]a @doc false @@ -66,7 +67,7 @@ def chgset(schema \\ %__MODULE__{}, params) do |> Changeset.validate_required(@reqr) |> Validate.name(:name) |> Validate.note(:note) - |> Validate.img(:image) + |> Changeset.cast_assoc(:images, with: &File.chgset/2) |> Validate.class(:resource_conforms_to) |> Changeset.assoc_constraint(:unit_of_resource) |> Changeset.assoc_constraint(:unit_of_effort) diff --git a/src/zenflows/vf/resource_specification.ex b/src/zenflows/vf/resource_specification.ex @@ -24,11 +24,12 @@ classification when more information is needed, particularly for recipes. use Zenflows.DB.Schema +alias Zenflows.File alias Zenflows.VF.{Unit, Validate} @type t() :: %__MODULE__{ name: String.t(), - image: String.t() | nil, + images: [File.t()], resource_classified_as: [String.t()] | nil, note: String.t() | nil, default_unit_of_effort: Unit.t() | nil, @@ -37,7 +38,7 @@ alias Zenflows.VF.{Unit, Validate} schema "vf_resource_specification" do field :name, :string - field :image, :string + has_many :images, File field :resource_classified_as, {:array, :string} field :note, :string belongs_to :default_unit_of_resource, Unit @@ -47,7 +48,7 @@ end @reqr [:name] @cast @reqr ++ ~w[ - resource_classified_as image note + resource_classified_as note default_unit_of_effort_id default_unit_of_resource_id ]a @@ -60,7 +61,7 @@ def chgset(schema \\ %__MODULE__{}, params) do |> Changeset.validate_required(@reqr) |> Validate.name(:name) |> Validate.note(:note) - |> Validate.img(:image) + |> Changeset.cast_assoc(:images, with: &File.chgset/2) |> Validate.class(:resource_classified_as) |> Changeset.assoc_constraint(:default_unit_of_resource) |> Changeset.assoc_constraint(:default_unit_of_effort) diff --git a/src/zenflows/vf/resource_specification/domain.ex b/src/zenflows/vf/resource_specification/domain.ex @@ -84,8 +84,12 @@ def delete(id) do end @spec preload(ResourceSpecification.t(), - :default_unit_of_resource | :default_unit_of_effort) + :images | :default_unit_of_resource | :default_unit_of_effort) :: ResourceSpecification.t() +def preload(res_spec, :images) do + Repo.preload(res_spec, :images) +end + def preload(res_spec, :default_unit_of_resource) do Repo.preload(res_spec, :default_unit_of_resource) end diff --git a/src/zenflows/vf/resource_specification/resolv.ex b/src/zenflows/vf/resource_specification/resolv.ex @@ -46,6 +46,11 @@ def delete_resource_specification(%{id: id}, _) do end end +def images(res_spec, _, _) do + res_spec = Domain.preload(res_spec, :images) + {:ok, res_spec.images} +end + def default_unit_of_resource(res_spec, _, _) do res_spec = Domain.preload(res_spec, :default_unit_of_resource) {:ok, res_spec.default_unit_of_resource} diff --git a/src/zenflows/vf/resource_specification/type.ex b/src/zenflows/vf/resource_specification/type.ex @@ -26,9 +26,8 @@ alias Zenflows.VF.ResourceSpecification.Resolv An informal or formal textual identifier for a type of resource. Does not imply uniqueness. """ -@image """ -The base64-encoded image binary relevant to the entity, such as a photo, -diagram, etc. +@images """ +The image files relevant to the entity, such as a photo, diagram, etc. """ @resource_classified_as """ References a concept in a common taxonomy or other classification scheme @@ -51,8 +50,8 @@ object :resource_specification do @desc @name field :name, non_null(:string) - @desc @image - field :image, :base64 + @desc @images + field :images, list_of(non_null(:file)), resolve: &Resolv.images/3 @desc @resource_classified_as field :resource_classified_as, list_of(non_null(:uri)) @@ -73,8 +72,8 @@ input_object :resource_specification_create_params do @desc @name field :name, non_null(:string) - @desc @image - field :image, :base64 + @desc @images + field :images, list_of(non_null(:ifile)) @desc @resource_classified_as field :resource_classified_as, list_of(non_null(:uri)) @@ -95,9 +94,6 @@ input_object :resource_specification_update_params do @desc @name field :name, :string - @desc @image - field :image, :base64 - @desc @resource_classified_as field :resource_classified_as, list_of(non_null(:uri)) diff --git a/test/file.test.exs b/test/file.test.exs @@ -0,0 +1,265 @@ +# Zenflows is designed to implement the Valueflows vocabulary, +# written and maintained by srfsh <info@dyne.org>. +# Copyright (C) 2021-2022 Dyne.org foundation <foundation@dyne.org>. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +defmodule ZenflowsTest.File do +use ZenflowsTest.Help.EctoCase, async: true + +alias Ecto.Changeset +alias Zenflows.File +alias Zenflows.VF.{ + EconomicEvent, + EconomicResource, + Intent, + Organization, + Person, + RecipeResource, + ResourceSpecification, +} + +test "works on RecipeResource" do + assert {:ok, %RecipeResource{} = rec_res} = + RecipeResource.Domain.create(%{ + name: Factory.str("name"), + images: [ + %{ + hash: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + name: "aaaaaaaaaaaaaaa", + description: "aaaaaaaa", + mime_type: "aaaaaa", + extension: "aaaaaaa", + size: 42, + signature: "aaaaaaaaaaaaaaaaaaaaaa", + width: 42, + height: 42, + }, + %{ + hash: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + name: "bbbbbbbbbbbbbbb", + description: "bbbbbbbb", + mime_type: "bbbbbb", + extension: "bbbbbbb", + size: 42, + signature: "bbbbbbbbbbbbbbbbbbbbbb", + width: 42, + height: 42, + }, + ], + }) + + assert [%File{}, %File{}] = rec_res.images +end + +test "works on EconomicResource" do + agent = Factory.insert!(:agent) + unit = Factory.insert!(:unit) + spec = Factory.insert!(:resource_specification) + {:ok, %EconomicEvent{}, %EconomicResource{} = res, nil} = + EconomicEvent.Domain.create( + %{ + action_id: "raise", + provider_id: agent.id, + receiver_id: agent.id, + has_point_in_time: Factory.now(), + resource_conforms_to_id: spec.id, + resource_quantity: %{ + has_numerical_value: 1, + has_unit_id: unit.id, + }, + }, + %{ + name: Factory.str("name"), + images: [ + %{ + hash: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + name: "aaaaaaaaaaaaaaa", + description: "aaaaaaaa", + mime_type: "aaaaaa", + extension: "aaaaaaa", + size: 42, + signature: "aaaaaaaaaaaaaaaaaaaaaa", + width: 42, + height: 42, + }, + %{ + hash: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + name: "bbbbbbbbbbbbbbb", + description: "bbbbbbbb", + mime_type: "bbbbbb", + extension: "bbbbbbb", + size: 42, + signature: "bbbbbbbbbbbbbbbbbbbbbb", + width: 42, + height: 42, + }, + ], + }) + + [%File{}, %File{}] = res.images +end + +test "works on Person Agent" do + assert {:ok, %Person{} = per} = + Person.Domain.create(%{ + name: Factory.str("name"), + user: Factory.str("user"), + email: "#{Factory.str("user")}@example.com", + images: [ + %{ + hash: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + name: "aaaaaaaaaaaaaaa", + description: "aaaaaaaa", + mime_type: "aaaaaa", + extension: "aaaaaaa", + size: 42, + signature: "aaaaaaaaaaaaaaaaaaaaaa", + width: 42, + height: 42, + }, + %{ + hash: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + name: "bbbbbbbbbbbbbbb", + description: "bbbbbbbb", + mime_type: "bbbbbb", + extension: "bbbbbbb", + size: 42, + signature: "bbbbbbbbbbbbbbbbbbbbbb", + width: 42, + height: 42, + }, + ], + }) + + assert [%File{}, %File{}] = per.images +end + +test "works on Organization Agent" do + assert {:ok, %Organization{} = org} = + Organization.Domain.create(%{ + name: Factory.str("name"), + images: [ + %{ + hash: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + name: "aaaaaaaaaaaaaaa", + description: "aaaaaaaa", + mime_type: "aaaaaa", + extension: "aaaaaaa", + size: 42, + signature: "aaaaaaaaaaaaaaaaaaaaaa", + width: 42, + height: 42, + }, + %{ + hash: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + name: "bbbbbbbbbbbbbbb", + description: "bbbbbbbb", + mime_type: "bbbbbb", + extension: "bbbbbbb", + size: 42, + signature: "bbbbbbbbbbbbbbbbbbbbbb", + width: 42, + height: 42, + }, + ], + }) + + assert [%File{}, %File{}] = org.images +end + +test "works on ResourceSpecification" do + assert {:ok, %ResourceSpecification{} = spec} = + ResourceSpecification.Domain.create(%{ + name: Factory.str("name"), + images: [ + %{ + hash: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + name: "aaaaaaaaaaaaaaa", + description: "aaaaaaaa", + mime_type: "aaaaaa", + extension: "aaaaaaa", + size: 42, + signature: "aaaaaaaaaaaaaaaaaaaaaa", + width: 42, + height: 42, + }, + %{ + hash: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + name: "bbbbbbbbbbbbbbb", + description: "bbbbbbbb", + mime_type: "bbbbbb", + extension: "bbbbbbb", + size: 42, + signature: "bbbbbbbbbbbbbbbbbbbbbb", + width: 42, + height: 42, + }, + ], + }) + + assert [%File{}, %File{}] = spec.images +end + +test "works on Intent" do + assert {:ok, %Intent{} = int} = + Intent.Domain.create(%{ + action_id: "raise", + provider_id: Factory.insert!(:agent).id, + images: [ + %{ + hash: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + name: "aaaaaaaaaaaaaaa", + description: "aaaaaaaa", + mime_type: "aaaaaa", + extension: "aaaaaaa", + size: 42, + signature: "aaaaaaaaaaaaaaaaaaaaaa", + width: 42, + height: 42, + }, + %{ + hash: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + name: "bbbbbbbbbbbbbbb", + description: "bbbbbbbb", + mime_type: "bbbbbb", + extension: "bbbbbbb", + size: 42, + signature: "bbbbbbbbbbbbbbbbbbbbbb", + width: 42, + height: 42, + }, + ], + }) + + assert [%File{}, %File{}] = int.images +end + +test "doesn't work without a belongs_to field" do + {:error, %Changeset{errors: errs}} = + File.chgset(%File{}, %{ + hash: "asnotehusnatoheusntaoehusntaeohu", + name: "satoehusnoaethu", + description: "foobaour", + mime_type: "foobar", + extension: "jpeeeeg", + size: 25, + signature: "faaosnetuhaoenthuousth", + width: 200, + height: 300, + }) + |> Repo.insert() + assert Keyword.has_key?(errs, :general) +end +end diff --git a/test/help/factory.ex b/test/help/factory.ex @@ -50,6 +50,7 @@ end Returns a list of string composed of one or ten items. Each item is generated by piping `str` to `uniq/1` """ +@spec str_list(String.t(), non_neg_integer(), non_neg_integer()) :: [String.t()] def str_list(s, min \\ 1, max \\ 10) do max = Enum.random(1..max) Enum.map(min..max, fn _ -> str(s) end) @@ -84,9 +85,24 @@ def uri() do str("schema://user@host:port/path") end -@doc "Returns a unique base64 encoded string (mock-up of image data)" -def img() do - :rand.bytes(200) |> Base.encode64(padding: true) +@doc "Returns a file list." +@spec file_list(non_neg_integer(), non_neg_integer()) :: [File.t()] +def file_list(min \\ 1, max \\ 10) do + max = Enum.random(1..max) + Enum.map(min..max, fn _ -> + bin = str("some binary") + hash = :crypto.hash(:sha512, bin) |> Base.url_encode64(padding: false) + %Zenflows.File{ + name: str("some name"), + description: str("some description"), + mime_type: str("some mime type"), + extension: str("some extension"), + signature: str("some signature"), + bin: bin, + hash: hash, + size: byte_size(bin), + } + end) end @doc "Inserts a schema into the database with field overrides." @@ -164,7 +180,7 @@ def build(:resource_specification) do name: str("some name"), resource_classified_as: str_list("some uri"), note: str("some note"), - image: img(), + images: file_list(), default_unit_of_effort: build(:unit), default_unit_of_resource: build(:unit), } @@ -179,7 +195,7 @@ def build(:recipe_resource) do resource_conforms_to: build(:resource_specification), substitutable: bool(), note: str("some note"), - image: img(), + images: file_list(), } end @@ -223,7 +239,7 @@ def build(:person) do %VF.Person{ type: :per, name: str("some name"), - image: img(), + images: file_list(), note: str("some note"), primary_location: build(:spatial_thing), user: str("some user"), @@ -243,7 +259,7 @@ def build(:organization) do %VF.Organization{ type: :org, name: str("some name"), - image: img(), + images: file_list(), classified_as: str_list("some uri"), note: str("some note"), primary_location: build(:spatial_thing), @@ -350,7 +366,7 @@ def build(:economic_resource) do %VF.EconomicResource{ name: str("some name"), note: str("some note"), - image: img(), + images: file_list(), tracking_identifier: str("some tracking identifier"), classified_as: str_list("some uri"), conforms_to: build(:resource_specification), @@ -409,7 +425,7 @@ def build(:intent) do has_point_in_time: now(), due: now(), finished: bool(), - image: img(), + images: file_list(), note: str("some note"), # in_scope_of: agreed_in: str("some uri"), diff --git a/test/vf/agent/domain.test.exs b/test/vf/agent/domain.test.exs @@ -36,7 +36,6 @@ describe "one/1" do assert agent.type == per.type and agent.type == :per assert agent.name == per.name assert agent.note == per.note - assert agent.image == per.image assert agent.primary_location_id == per.primary_location_id # person @@ -55,7 +54,6 @@ describe "one/1" do assert agent.type == org.type and agent.type == :org assert agent.name == org.name assert agent.note == org.note - assert agent.image == org.image assert agent.primary_location_id == org.primary_location_id # person diff --git a/test/vf/agent/type.test.exs b/test/vf/agent/type.test.exs @@ -33,7 +33,6 @@ test "Query myAgent" do myAgent { id name - image note } } @@ -41,7 +40,6 @@ test "Query myAgent" do assert {:ok, _} = Zenflows.DB.ID.cast(data["id"]) assert data["name"] == "hello" - assert data["image"] == "https://example.test/img.jpg" assert data["note"] == "world" end @@ -54,7 +52,6 @@ describe "Query agent()" do id name note - image primaryLocation { id } } } @@ -63,7 +60,6 @@ describe "Query agent()" do assert data["id"] == per.id assert data["name"] == per.name assert data["note"] == per.note - assert data["image"] == per.image assert data["primaryLocation"]["id"] == per.primary_location_id end @@ -75,7 +71,6 @@ describe "Query agent()" do id name note - image primaryLocation { id } } } @@ -84,7 +79,6 @@ describe "Query agent()" do assert data["id"] == org.id assert data["name"] == org.name assert data["note"] == org.note - assert data["image"] == org.image assert data["primaryLocation"]["id"] == org.primary_location_id end @@ -97,7 +91,6 @@ describe "Query agent()" do id name note - image primaryLocation { id } user email @@ -114,7 +107,6 @@ describe "Query agent()" do assert data["id"] == per.id assert data["name"] == per.name assert data["note"] == per.note - assert data["image"] == per.image assert data["primaryLocation"]["id"] == per.primary_location_id assert data["user"] == per.user @@ -135,7 +127,6 @@ describe "Query agent()" do id name note - image primaryLocation { id } classifiedAs } @@ -146,7 +137,6 @@ describe "Query agent()" do assert data["id"] == org.id assert data["name"] == org.name assert data["note"] == org.note - assert data["image"] == org.image assert data["primaryLocation"]["id"] == org.primary_location_id assert data["classifiedAs"] == org.classified_as diff --git a/test/vf/economic_event/domain.test.exs b/test/vf/economic_event/domain.test.exs @@ -119,7 +119,7 @@ describe "`create/2` with raise:" do res_params = %{ name: Factory.str("name"), note: Factory.str("note"), - image: Factory.img(), + #image: Factory.img(), tracking_identifier: Factory.str("tracking identifier"), lot_id: Factory.insert!(:product_batch).id, } @@ -128,7 +128,7 @@ describe "`create/2` with raise:" do assert res.name == res_params.name assert res.note == res_params.note - assert res.image == res_params.image + #assert res.image == res_params.image assert res.tracking_identifier == res_params.tracking_identifier assert res.lot_id == res_params.lot_id @@ -219,7 +219,7 @@ describe "`create/2` with produce:" do res_params = %{ name: Factory.str("name"), note: Factory.str("note"), - image: Factory.img(), + #image: Factory.img(), tracking_identifier: Factory.str("tracking identifier"), lot_id: Factory.insert!(:product_batch).id, } @@ -228,7 +228,7 @@ describe "`create/2` with produce:" do assert res.name == res_params.name assert res.note == res_params.note - assert res.image == res_params.image + #assert res.image == res_params.image assert res.tracking_identifier == res_params.tracking_identifier assert res.lot_id == res_params.lot_id @@ -783,7 +783,7 @@ describe "`create/2` with transferCustody:" do res_params = %{ name: Factory.str("name"), note: Factory.str("note"), - image: Factory.img(), + #image: Factory.img(), tracking_identifier: Factory.str("tracking identifier"), lot_id: Factory.insert!(:product_batch).id, } @@ -797,7 +797,7 @@ describe "`create/2` with transferCustody:" do assert to_res.name == res_params.name assert to_res.note == res_params.note - assert to_res.image == res_params.image + #assert to_res.image == res_params.image assert to_res.tracking_identifier == res_params.tracking_identifier assert to_res.lot_id == res_params.lot_id @@ -1031,7 +1031,7 @@ describe "`create/2` with transferAllRights:" do res_params = %{ name: Factory.str("name"), note: Factory.str("note"), - image: Factory.img(), + #image: Factory.img(), tracking_identifier: Factory.str("tracking identifier"), lot_id: Factory.insert!(:product_batch).id, } @@ -1045,7 +1045,7 @@ describe "`create/2` with transferAllRights:" do assert to_res.name == res_params.name assert to_res.note == res_params.note - assert to_res.image == res_params.image + #assert to_res.image == res_params.image assert to_res.tracking_identifier == res_params.tracking_identifier assert to_res.lot_id == res_params.lot_id @@ -1278,7 +1278,7 @@ describe "`create/2` with transfer:" do res_params = %{ name: Factory.str("name"), note: Factory.str("note"), - image: Factory.img(), + #image: Factory.img(), tracking_identifier: Factory.str("tracking identifier"), lot_id: Factory.insert!(:product_batch).id, } @@ -1292,7 +1292,7 @@ describe "`create/2` with transfer:" do assert to_res.name == res_params.name assert to_res.note == res_params.note - assert to_res.image == res_params.image + #assert to_res.image == res_params.image assert to_res.tracking_identifier == res_params.tracking_identifier assert to_res.lot_id == res_params.lot_id @@ -1562,7 +1562,7 @@ describe "`create/2` with move:" do res_params = %{ name: Factory.str("name"), note: Factory.str("note"), - image: Factory.img(), + #image: Factory.img(), tracking_identifier: Factory.str("tracking identifier"), lot_id: Factory.insert!(:product_batch).id, } @@ -1576,7 +1576,7 @@ describe "`create/2` with move:" do assert to_res.name == res_params.name assert to_res.note == res_params.note - assert to_res.image == res_params.image + #assert to_res.image == res_params.image assert to_res.tracking_identifier == res_params.tracking_identifier assert to_res.lot_id == res_params.lot_id diff --git a/test/vf/economic_resource/domain.test.exs b/test/vf/economic_resource/domain.test.exs @@ -37,7 +37,7 @@ setup ctx do params = %{ name: Factory.str("name"), note: Factory.str("note"), - image: Factory.img(), + #image: Factory.img(), tracking_identifier: Factory.str("tracking identifier"), classified_as: Factory.str_list("uri"), conforms_to_id: Factory.insert!(:resource_specification).id, @@ -87,7 +87,7 @@ describe "update/2" do assert new.onhand_quantity_has_numerical_value == old.onhand_quantity_has_numerical_value assert new.current_location_id == old.current_location_id assert new.note == old.note - assert new.image == old.image + #assert new.image == old.image assert new.unit_of_effort_id == old.unit_of_effort_id assert new.stage_id == old.stage_id assert new.state_id == old.state_id @@ -110,7 +110,7 @@ describe "update/2" do assert new.onhand_quantity_has_numerical_value == params.onhand_quantity.has_numerical_value assert new.current_location_id == params.current_location_id assert new.note == params.note - assert new.image == params.image + #assert new.image == params.image assert new.unit_of_effort_id == params.unit_of_effort_id assert new.stage_id == params.stage_id assert new.state_id == params.state_id diff --git a/test/vf/economic_resource/type.test.exs b/test/vf/economic_resource/type.test.exs @@ -23,7 +23,7 @@ setup do params: %{ "name" => Factory.str("name"), "note" => Factory.str("note"), - "image" => Factory.img(), + #"image" => Factory.img(), }, inserted: Factory.insert!(:economic_resource), } @@ -34,7 +34,7 @@ fragment economicResource on EconomicResource { id name note - image + #image trackingIdentifier classifiedAs conformsTo {id} @@ -70,7 +70,7 @@ describe "Query" do assert data["id"] == new.id assert data["name"] == new.name assert data["note"] == new.note - assert data["image"] == new.image + #assert data["image"] == new.image assert data["trackingIdentifier"] == new.tracking_identifier assert data["classifiedAs"] == new.classified_as assert data["conformsTo"]["id"] == new.conforms_to_id @@ -103,14 +103,14 @@ describe "Mutation" do """, vars: %{"resource" => %{ "id" => old.id, "note" => params["note"], - "image" => params["image"], + #"image" => params["image"], }}) assert data["id"] == old.id assert data["id"] == old.id assert data["name"] == old.name assert data["note"] == params["note"] - assert data["image"] == params["image"] + #assert data["image"] == params["image"] assert data["trackingIdentifier"] == old.tracking_identifier assert data["classifiedAs"] == old.classified_as assert data["conformsTo"]["id"] == old.conforms_to_id diff --git a/test/vf/intent/domain.test.exs b/test/vf/intent/domain.test.exs @@ -60,7 +60,6 @@ setup do due: Factory.now(), finished: Factory.bool(), at_location_id: Factory.insert!(:spatial_thing).id, - image: Factory.img(), name: Factory.str("name"), note: Factory.str("note"), # in_scope_of_id: @@ -91,7 +90,7 @@ describe "create/1" do input_of_id output_of_id resource_inventoried_as_id resource_conforms_to_id resource_classified_as has_beginning has_end has_point_in_time due - finished image name note agreed_in at_location_id + finished name note agreed_in at_location_id ]a # in_scope_of_id assert Map.take(int, keys) == Map.take(params, keys) @@ -113,7 +112,7 @@ describe "create/1" do input_of_id output_of_id resource_inventoried_as_id resource_conforms_to_id resource_classified_as has_beginning has_end has_point_in_time due - finished image name note agreed_in at_location_id + finished name note agreed_in at_location_id ]a # in_scope_of_id assert Map.take(int, keys) == Map.take(params, keys) @@ -148,7 +147,7 @@ describe "update/2" do input_of_id output_of_id resource_inventoried_as_id resource_conforms_to_id resource_classified_as has_beginning has_end has_point_in_time due - finished image name note agreed_in at_location_id + finished name note agreed_in at_location_id ]a # in_scope_of_id assert Map.take(new, keys) == Map.take(params, keys) @@ -171,7 +170,7 @@ describe "update/2" do input_of_id output_of_id resource_inventoried_as_id resource_conforms_to_id resource_classified_as has_beginning has_end has_point_in_time due - finished image name note agreed_in at_location_id + finished name note agreed_in at_location_id ]a # in_scope_of_id assert Map.take(new, keys) == Map.take(params, keys) @@ -210,7 +209,7 @@ describe "update/2" do effort_quantity_has_unit_id effort_quantity_has_numerical_value available_quantity_has_unit_id available_quantity_has_numerical_value has_beginning has_end has_point_in_time due - finished image name note agreed_in at_location_id + finished name note agreed_in at_location_id ]a # in_scope_of_id assert Map.take(new, keys) == Map.take(old, keys) end diff --git a/test/vf/intent/type.test.exs b/test/vf/intent/type.test.exs @@ -49,7 +49,6 @@ setup do "due" => Factory.iso_now(), "finished" => Factory.bool(), "atLocation" => Factory.insert!(:spatial_thing).id, - "image" => Factory.img(), "name" => Factory.str("name"), "note" => Factory.str("note"), # inScopeOf: @@ -85,7 +84,6 @@ fragment intent on Intent { due finished atLocation {id} - image name note agreedIn @@ -123,7 +121,6 @@ describe "Query" do assert data["due"] == DateTime.to_iso8601(int.due) assert data["finished"] == int.finished assert data["atLocation"]["id"] == int.at_location_id - assert data["image"] == int.image assert data["name"] == int.name assert data["note"] == int.note assert data["agreedIn"] == int.agreed_in @@ -163,7 +160,7 @@ describe "Mutation" do Enum.each(~w[ hasBeginning hasEnd hasPointInTime due - finished image name note agreedIn + finished name note agreedIn ], fn x -> assert data[x] == params[x] end) @@ -201,7 +198,7 @@ describe "Mutation" do Enum.each(~w[ hasBeginning hasEnd hasPointInTime due - finished image name note agreedIn + finished name note agreedIn ], fn x -> assert data[x] == params[x] end) @@ -241,7 +238,7 @@ describe "Mutation" do Enum.each(~w[ hasBeginning hasEnd hasPointInTime due - finished image name note agreedIn + finished name note agreedIn ], fn x -> assert data[x] == params[x] end) @@ -281,7 +278,7 @@ describe "Mutation" do Enum.each(~w[ hasBeginning hasEnd hasPointInTime due - finished image name note agreedIn + finished name note agreedIn ], fn x -> assert data[x] == params[x] end) diff --git a/test/vf/organization/domain.test.exs b/test/vf/organization/domain.test.exs @@ -25,7 +25,6 @@ setup do %{ params: %{ name: Factory.str("name"), - image: Factory.img(), classified_as: Factory.str_list("uri"), note: Factory.str("note"), primary_location_id: Factory.insert!(:spatial_thing).id, @@ -54,7 +53,6 @@ describe "create/1" do assert {:ok, %Organization{} = new} = Domain.create(params) assert new.type == :org assert new.name == params.name - assert new.image == params.image assert new.classified_as == params.classified_as assert new.note == params.note assert new.primary_location_id == params.primary_location_id end @@ -70,7 +68,6 @@ describe "update/2" do assert new.name == params.name assert new.classified_as == params.classified_as assert new.note == params.note - assert new.image == params.image assert new.primary_location_id == params.primary_location_id end @@ -79,7 +76,6 @@ describe "update/2" do assert new.name == old.name assert new.classified_as == old.classified_as assert new.note == old.note - assert new.image == old.image assert new.primary_location_id == old.primary_location_id end end diff --git a/test/vf/organization/type.test.exs b/test/vf/organization/type.test.exs @@ -22,7 +22,6 @@ setup do %{ params: %{ "name" => Factory.str("name"), - "image" => Factory.img(), "classifiedAs" => Factory.str_list("uri"), "note" => Factory.str("note"), "primaryLocation" => Factory.insert!(:spatial_thing).id, @@ -36,7 +35,6 @@ fragment organization on Organization { id name note - image primaryLocation { id } classifiedAs } @@ -55,7 +53,6 @@ describe "Query" do assert data["id"] == new.id assert data["name"] == new.name assert data["note"] == new.note - assert data["image"] == new.image assert data["primaryLocation"]["id"] == new.primary_location_id assert data["classifiedAs"] == new.classified_as end @@ -94,12 +91,12 @@ describe "Mutation" do } """, vars: %{"organization" => params - |> Map.take(~w[name note image primaryLocation classifiedAs]) + |> Map.take(~w[name note primaryLocation classifiedAs]) |> Map.put("id", old.id) }) assert data["id"] == old.id - keys = ~w[name image note classifiedAs] + keys = ~w[name note classifiedAs] assert Map.take(data, keys) == Map.take(params, keys) assert data["primaryLocation"]["id"] == params["primaryLocation"] end diff --git a/test/vf/person/domain.test.exs b/test/vf/person/domain.test.exs @@ -25,7 +25,6 @@ setup do %{ params: %{ name: Factory.str("name"), - image: Factory.img(), note: Factory.str("note"), primary_location_id: Factory.insert!(:spatial_thing).id, user: Factory.str("user"), @@ -61,7 +60,6 @@ describe "create/1" do assert new.type == :per assert new.name == params.name assert new.note == params.note - assert new.image == params.image assert new.primary_location_id == params.primary_location_id assert new.user == params.user assert new.email == params.email @@ -82,7 +80,6 @@ describe "update/2" do assert {:ok, %Person{} = new} = Domain.update(old.id, params) assert new.name == params.name assert new.note == params.note - assert new.image == params.image assert new.primary_location_id == params.primary_location_id assert new.user == params.user assert new.email == old.email @@ -97,7 +94,6 @@ describe "update/2" do assert {:ok, %Person{} = new} = Domain.update(old.id, %{email: "can't change that yet"}) assert new.name == old.name assert new.note == old.note - assert new.image == old.image assert new.primary_location_id == old.primary_location_id assert new.user == old.user assert new.email == old.email diff --git a/test/vf/person/type.test.exs b/test/vf/person/type.test.exs @@ -22,7 +22,6 @@ setup do %{ params: %{ "name" => Factory.str("name"), - "image" => Factory.img(), "note" => Factory.str("note"), "primaryLocation" => Factory.insert!(:spatial_thing).id, "user" => Factory.str("user"), @@ -42,7 +41,6 @@ fragment person on Person { id name note - image primaryLocation { id } user email @@ -67,7 +65,6 @@ describe "Query" do assert data["id"] == new.id assert data["name"] == new.name assert data["note"] == new.note - assert data["image"] == new.image assert data["primaryLocation"]["id"] == new.primary_location_id assert data["user"] == new.user @@ -128,11 +125,11 @@ describe "Mutation" do } """, vars: %{"person" => params - |> Map.take(~w[user name image note primaryLocation]) + |> Map.take(~w[user name note primaryLocation]) |> Map.put("id", old.id) }) - keys = ~w[user name image note] + keys = ~w[user name note] assert Map.take(data, keys) == Map.take(params, keys) assert data["primaryLocation"]["id"] == params["primaryLocation"] diff --git a/test/vf/recipe_resource/domain.test.exs b/test/vf/recipe_resource/domain.test.exs @@ -35,7 +35,6 @@ setup do resource_conforms_to_id: Factory.insert!(:resource_specification).id, substitutable: Factory.bool(), note: Factory.str("note"), - image: Factory.img(), }, inserted: Factory.insert!(:recipe_resource), } @@ -61,7 +60,6 @@ describe "create/1" do assert new.resource_conforms_to_id == params.resource_conforms_to_id assert new.substitutable == params.substitutable assert new.note == params.note - assert new.image == params.image end test "with bad params: doesn't create a Process" do @@ -79,7 +77,6 @@ describe "update/2" do assert new.resource_conforms_to_id == params.resource_conforms_to_id assert new.substitutable == params.substitutable assert new.note == params.note - assert new.image == params.image end test "with bad params: doesn't update the RecipeResource", %{inserted: old} do @@ -91,7 +88,6 @@ describe "update/2" do assert new.resource_conforms_to_id == old.resource_conforms_to_id assert new.substitutable == old.substitutable assert new.note == old.note - assert new.image == old.image end end diff --git a/test/vf/recipe_resource/type.test.exs b/test/vf/recipe_resource/type.test.exs @@ -28,7 +28,6 @@ setup do "resourceConformsTo" => Factory.insert!(:resource_specification).id, "substitutable" => Factory.bool(), "note" => Factory.str("note"), - "image" => Factory.img(), }, inserted: Factory.insert!(:recipe_resource), } @@ -43,7 +42,6 @@ fragment recipeResource on RecipeResource { unitOfEffort {id} resourceConformsTo {id} substitutable - image note } """ @@ -66,7 +64,6 @@ describe "Query" do assert data["resourceConformsTo"]["id"] == new.resource_conforms_to_id assert data["note"] == new.note assert data["substitutable"] == new.substitutable - assert data["image"] == new.image end end @@ -83,7 +80,7 @@ describe "Mutation" do """, vars: %{"recipeResource" => params}) assert {:ok, _} = Zenflows.DB.ID.cast(data["id"]) - keys = ~w[name note image resourceClassifiedAs substitutable] + keys = ~w[name note resourceClassifiedAs substitutable] assert Map.take(data, keys) == Map.take(params, keys) assert data["unitOfResource"]["id"] == params["unitOfResource"] assert data["unitOfEffort"]["id"] == params["unitOfEffort"] @@ -102,7 +99,7 @@ describe "Mutation" do """, vars: %{"recipeResource" => Map.put(params, "id", old.id)}) assert data["id"] == old.id - keys = ~w[name note image resourceClassifiedAs substitutable] + keys = ~w[name note resourceClassifiedAs substitutable] assert Map.take(data, keys) == Map.take(params, keys) assert data["unitOfResource"]["id"] == params["unitOfResource"] assert data["unitOfEffort"]["id"] == params["unitOfEffort"] diff --git a/test/vf/resource_specification/domain.test.exs b/test/vf/resource_specification/domain.test.exs @@ -31,7 +31,6 @@ setup do name: Factory.str("name"), resource_classified_as: Factory.str_list("uri"), note: Factory.str("note"), - image: Factory.img(), default_unit_of_effort_id: Factory.insert!(:unit).id, default_unit_of_resource_id: Factory.insert!(:unit).id, }, @@ -55,7 +54,6 @@ describe "create/1" do assert new.name == params.name assert new.resource_classified_as == params.resource_classified_as assert new.note == params.note - assert new.image == params.image assert new.default_unit_of_resource_id == params.default_unit_of_resource_id assert new.default_unit_of_effort_id == params.default_unit_of_effort_id end @@ -71,7 +69,6 @@ describe "update/2" do assert new.name == params.name assert new.resource_classified_as == params.resource_classified_as assert new.note == params.note - assert new.image == params.image assert new.default_unit_of_resource_id == params.default_unit_of_resource_id assert new.default_unit_of_effort_id == params.default_unit_of_effort_id end @@ -81,7 +78,6 @@ describe "update/2" do assert new.name == old.name assert new.resource_classified_as == old.resource_classified_as assert new.note == old.note - assert new.image == old.image assert new.default_unit_of_resource_id == old.default_unit_of_resource_id assert new.default_unit_of_effort_id == old.default_unit_of_effort_id end diff --git a/test/vf/resource_specification/type.test.exs b/test/vf/resource_specification/type.test.exs @@ -24,7 +24,6 @@ setup do "name" => Factory.str("name"), "resourceClassifiedAs" => Factory.str_list("uri"), "note" => Factory.str("note"), - "image" => Factory.img(), "defaultUnitOfEffort" => Factory.insert!(:unit).id, "defaultUnitOfResource" => Factory.insert!(:unit).id, }, @@ -40,7 +39,6 @@ fragment resourceSpecification on ResourceSpecification { defaultUnitOfResource {id} defaultUnitOfEffort {id} note - image } """ @@ -60,7 +58,6 @@ describe "Query" do assert data["defaultUnitOfResource"]["id"] == new.default_unit_of_resource_id assert data["defaultUnitOfEffort"]["id"] == new.default_unit_of_effort_id assert data["note"] == new.note - assert data["image"] == new.image end end @@ -77,7 +74,7 @@ describe "Mutation" do """, vars: %{"resourceSpecification" => params}) assert {:ok, _} = Zenflows.DB.ID.cast(data["id"]) - keys = ~w[name note resourceClassifiedAs note image] + keys = ~w[name note resourceClassifiedAs note] assert Map.take(data, keys) == Map.take(params, keys) assert data["defaultUnitOfResource"]["id"] == params["defaultUnitOfResource"] assert data["defaultUnitOfEffort"]["id"] == params["defaultUnitOfEffort"] @@ -95,7 +92,7 @@ describe "Mutation" do """, vars: %{"resourceSpecification" => Map.put(params, "id", old.id)}) assert data["id"] == old.id - keys = ~w[name note resourceClassifiedAs note image] + keys = ~w[name note resourceClassifiedAs note] assert Map.take(data, keys) == Map.take(params, keys) assert data["defaultUnitOfResource"]["id"] == params["defaultUnitOfResource"] assert data["defaultUnitOfEffort"]["id"] == params["defaultUnitOfEffort"]