type.test.exs (3287B)
1 # Zenflows is designed to implement the Valueflows vocabulary, 2 # written and maintained by srfsh <info@dyne.org>. 3 # Copyright (C) 2021-2023 Dyne.org foundation <foundation@dyne.org>. 4 # 5 # This program is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU Affero General Public License as published by 7 # the Free Software Foundation, either version 3 of the License, or 8 # (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU Affero General Public License for more details. 14 # 15 # You should have received a copy of the GNU Affero General Public License 16 # along with this program. If not, see <https://www.gnu.org/licenses/>. 17 18 defmodule ZenflowsTest.VF.Organization.Type do 19 use ZenflowsTest.Help.AbsinCase, async: true 20 21 setup do 22 %{ 23 params: %{ 24 "name" => Factory.str("name"), 25 "classifiedAs" => Factory.str_list("uri"), 26 "note" => Factory.str("note"), 27 "primaryLocation" => Factory.insert!(:spatial_thing).id, 28 }, 29 inserted: Factory.insert!(:organization), 30 } 31 end 32 33 @frag """ 34 fragment organization on Organization { 35 id 36 name 37 note 38 primaryLocation { id } 39 classifiedAs 40 } 41 """ 42 43 describe "Query" do 44 test "organization()", %{inserted: new} do 45 assert %{data: %{"organization" => data}} = 46 run!(""" 47 #{@frag} 48 query ($id: ID!) { 49 organization(id: $id) {...organization} 50 } 51 """, vars: %{"id" => new.id}) 52 53 assert data["id"] == new.id 54 assert data["name"] == new.name 55 assert data["note"] == new.note 56 assert data["primaryLocation"]["id"] == new.primary_location_id 57 assert data["classifiedAs"] == new.classified_as 58 end 59 end 60 61 describe "Mutation" do 62 test "createOrganization", %{params: params} do 63 assert %{data: %{"createOrganization" => %{"agent" => data}}} = 64 run!(""" 65 #{@frag} 66 mutation ($organization: OrganizationCreateParams!) { 67 createOrganization(organization: $organization) { 68 agent {...organization} 69 } 70 } 71 """, vars: %{"organization" => params}) 72 73 assert {:ok, _} = Zenflows.DB.ID.cast(data["id"]) 74 data = Map.delete(data, "id") 75 76 assert data["primaryLocation"]["id"] == params["primaryLocation"] 77 data = Map.delete(data, "primaryLocation") 78 params = Map.delete(params, "primaryLocation") 79 80 assert data == params 81 end 82 83 test "updateOrganization()", %{params: params, inserted: old} do 84 assert %{data: %{"updateOrganization" => %{"agent" => data}}} = 85 run!(""" 86 #{@frag} 87 mutation ($organization: OrganizationUpdateParams!) { 88 updateOrganization(organization: $organization) { 89 agent {...organization} 90 } 91 } 92 """, vars: %{"organization" => 93 params 94 |> Map.take(~w[name note primaryLocation classifiedAs]) 95 |> Map.put("id", old.id) 96 }) 97 98 assert data["id"] == old.id 99 keys = ~w[name note classifiedAs] 100 assert Map.take(data, keys) == Map.take(params, keys) 101 assert data["primaryLocation"]["id"] == params["primaryLocation"] 102 end 103 104 test "deleteOrganization", %{inserted: %{id: id}} do 105 assert %{data: %{"deleteOrganization" => true}} = 106 run!(""" 107 mutation ($id: ID!) { 108 deleteOrganization(id: $id) 109 } 110 """, vars: %{"id" => id}) 111 end 112 end 113 end