domain.test.exs (4329B)
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.Person.Domain do 19 use ZenflowsTest.Help.EctoCase, async: true 20 21 alias Ecto.Changeset 22 alias Zenflows.VF.{Person, Person.Domain} 23 24 setup do 25 %{ 26 params: %{ 27 name: Factory.str("name"), 28 note: Factory.str("note"), 29 primary_location_id: Factory.insert!(:spatial_thing).id, 30 user: Factory.str("user"), 31 email: "#{Factory.str("user")}@example.com", 32 ecdh_public_key: Base.encode64("ecdh_public_key"), 33 eddsa_public_key: Base.encode64("eddsa_public_key"), 34 ethereum_address: Base.encode64("ethereum_address"), 35 reflow_public_key: Base.encode64("reflow_public_key"), 36 bitcoin_public_key: Base.encode64("bitcoin_public_key"), 37 }, 38 inserted: Factory.insert!(:person), 39 } 40 end 41 42 describe "one/1" do 43 test "with good id: finds the Person", %{inserted: %{id: id}} do 44 assert {:ok, %Person{}} = Domain.one(id) 45 end 46 47 test "with org's id: doesn't return an Organization" do 48 org = Factory.insert!(:organization) 49 assert {:error, "not found"} = Domain.one(org.id) 50 end 51 52 test "with bad id: doesn't find the Person" do 53 assert {:error, "not found"} = Domain.one(Factory.id()) 54 end 55 end 56 57 describe "create/1" do 58 test "with good params: creates a Person", %{params: params} do 59 assert {:ok, %Person{} = new} = Domain.create(params) 60 assert new.type == :per 61 assert new.name == params.name 62 assert new.note == params.note 63 assert new.primary_location_id == params.primary_location_id 64 assert new.user == params.user 65 assert new.email == params.email 66 assert new.ecdh_public_key == params.ecdh_public_key 67 assert new.eddsa_public_key == params.eddsa_public_key 68 assert new.ethereum_address == params.ethereum_address 69 assert new.reflow_public_key == params.reflow_public_key 70 assert new.bitcoin_public_key == params.bitcoin_public_key 71 end 72 73 test "with bad params: doesn't create a Person" do 74 assert {:error, %Changeset{}} = Domain.create(%{}) 75 end 76 end 77 78 describe "update/2" do 79 test "with good params: updates the Person", %{params: params, inserted: old} do 80 assert {:ok, %Person{} = new} = Domain.update(old.id, params) 81 assert new.name == params.name 82 assert new.note == params.note 83 assert new.primary_location_id == params.primary_location_id 84 assert new.user == params.user 85 assert new.email == old.email 86 assert new.ecdh_public_key == old.ecdh_public_key 87 assert new.eddsa_public_key == old.eddsa_public_key 88 assert new.ethereum_address == old.ethereum_address 89 assert new.reflow_public_key == old.reflow_public_key 90 assert new.bitcoin_public_key == old.bitcoin_public_key 91 end 92 93 test "with bad params: doesn't update the Person", %{inserted: old} do 94 assert {:ok, %Person{} = new} = Domain.update(old.id, %{email: "can't change that yet"}) 95 assert new.name == old.name 96 assert new.note == old.note 97 assert new.primary_location_id == old.primary_location_id 98 assert new.user == old.user 99 assert new.email == old.email 100 assert new.ecdh_public_key == old.ecdh_public_key 101 assert new.eddsa_public_key == old.eddsa_public_key 102 assert new.ethereum_address == old.ethereum_address 103 assert new.reflow_public_key == old.reflow_public_key 104 assert new.bitcoin_public_key == old.bitcoin_public_key 105 end 106 end 107 108 describe "delete/1" do 109 test "with good id: deletes the Person", %{inserted: %{id: id}} do 110 assert {:ok, %Person{id: ^id}} = Domain.delete(id) 111 assert {:error, "not found"} = Domain.one(id) 112 end 113 114 test "with bad id: doesn't delete the Person" do 115 assert {:error, "not found"} = Domain.delete(Factory.id()) 116 end 117 end 118 end