Skip to content

Instantly share code, notes, and snippets.

@emtudo
Created May 20, 2024 16:10
Show Gist options
  • Save emtudo/75c75c6abdcb1601f326b542949694fd to your computer and use it in GitHub Desktop.
Save emtudo/75c75c6abdcb1601f326b542949694fd to your computer and use it in GitHub Desktop.
test unarchive
defmodule App.Tenant.OrganizationTest do
use ExUnit.Case, async: true
use App.DataCase
alias App.Tenant.Organization
@valid_attrs %{name: "Some Organization", domain: "example.com"}
@update_attrs %{name: "Updated Organization", domain: "updated.com"}
@invalid_attrs %{name: nil, domain: nil}
# .... hidden all tests ok!
describe "unarchive/1" do
test "unarchives an organization" do
organization = Organization
|> Ash.Changeset.for_create(:create, @valid_attrs)
|> Ash.create!()
organization
|> Ash.Changeset.for_destroy(:destroy)
|> Ash.destroy!()
archived_organization = Organization
|> Ash.Query.for_read(:archived_by_id, %{id: organization.id})
|> Ash.read_one!()
IO.inspect(archived_organization, label: "organization xx")
unarchived_organization = archived_organization
|> Ash.Changeset.for_update(:unarchive, @update_attrs)
# |> Ash.update!()
IO.inspect(unarchived_organization, label: "unarchived_organization")
# assert unarchived_organization.id == organization.id
fetched_organization = Organization
|> Ash.Query.for_read(:by_id, %{id: organization.id})
|> Ash.read_one!()
IO.inspect(fetched_organization, label: "fetched XX")
# assert unarchived_organization.id == organization.id
# fetched_organization = Organization
# |> Ash.Query.for_read(:by_id, id: organization.id)
# |> Ash.read_one!()
# assert fetched_organization.id == organization.id
# assert fetched_organization.archived_at == nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment