2024-03-28 09:06:40 +13:00
|
|
|
defmodule Ash.Test.Domain.Info.DiagramTest do
|
2022-10-02 15:21:24 +13:00
|
|
|
@moduledoc false
|
|
|
|
use ExUnit.Case, async: true
|
|
|
|
|
2024-03-28 09:06:40 +13:00
|
|
|
test "generate a mermaid entity relationship diagram from a domain" do
|
|
|
|
assert Ash.Domain.Info.Diagram.mermaid_er_diagram(Ash.Test.Flow.Domain) == """
|
2022-10-02 15:21:24 +13:00
|
|
|
erDiagram
|
|
|
|
User {
|
|
|
|
UUID id
|
|
|
|
String first_name
|
|
|
|
String last_name
|
|
|
|
String email
|
|
|
|
}
|
|
|
|
Org {
|
|
|
|
UUID id
|
|
|
|
String name
|
|
|
|
}
|
|
|
|
|
|
|
|
Org ||--|| User : ""
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2024-03-28 09:06:40 +13:00
|
|
|
test "generate a mermaid class diagram from a domain" do
|
|
|
|
assert Ash.Domain.Info.Diagram.mermaid_class_diagram(Ash.Test.Flow.Domain) == """
|
2022-10-02 15:21:24 +13:00
|
|
|
classDiagram
|
|
|
|
class User {
|
|
|
|
UUID id
|
|
|
|
String first_name
|
|
|
|
String last_name
|
|
|
|
String email
|
|
|
|
Org org
|
2022-10-18 04:18:47 +13:00
|
|
|
destroy()
|
2022-10-02 15:21:24 +13:00
|
|
|
read()
|
2022-10-06 19:04:21 +13:00
|
|
|
for_org(UUID org)
|
2023-01-17 04:04:09 +13:00
|
|
|
by_name(String name)
|
2024-03-28 09:06:40 +13:00
|
|
|
create(UUID org, String first_name, String last_name, String email)
|
|
|
|
update(String first_name, String last_name, String email)
|
2022-10-02 15:21:24 +13:00
|
|
|
approve()
|
|
|
|
unapprove()
|
|
|
|
}
|
|
|
|
class Org {
|
|
|
|
UUID id
|
|
|
|
String name
|
|
|
|
User[] users
|
2024-03-28 09:06:40 +13:00
|
|
|
update(String name)
|
|
|
|
create(String name)
|
2022-10-18 04:18:47 +13:00
|
|
|
destroy()
|
2022-10-02 15:21:24 +13:00
|
|
|
read()
|
2022-10-06 19:04:21 +13:00
|
|
|
by_name(String name)
|
2022-10-02 15:21:24 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
Org -- User
|
|
|
|
"""
|
|
|
|
end
|
2022-10-04 04:30:10 +13:00
|
|
|
|
2024-03-28 09:06:40 +13:00
|
|
|
test "include private fields in a mermaid entity relationship diagram from a domain if specified" do
|
|
|
|
assert Ash.Domain.Info.Diagram.mermaid_er_diagram(Ash.Test.Flow.Domain, show_private?: true) ==
|
2022-10-04 04:30:10 +13:00
|
|
|
"""
|
|
|
|
erDiagram
|
|
|
|
User {
|
|
|
|
UUID id
|
|
|
|
String first_name
|
|
|
|
String last_name
|
|
|
|
String email
|
|
|
|
Boolean approved
|
|
|
|
UUID org_id
|
|
|
|
}
|
|
|
|
Org {
|
|
|
|
UUID id
|
|
|
|
String name
|
|
|
|
}
|
|
|
|
|
|
|
|
Org ||--|| User : ""
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2024-03-28 09:06:40 +13:00
|
|
|
test "include private fields in a mermaid class diagram from a domain if specified" do
|
|
|
|
assert Ash.Domain.Info.Diagram.mermaid_class_diagram(Ash.Test.Flow.Domain,
|
2022-10-04 04:30:10 +13:00
|
|
|
show_private?: true
|
|
|
|
) == """
|
|
|
|
classDiagram
|
|
|
|
class User {
|
|
|
|
UUID id
|
|
|
|
String first_name
|
|
|
|
String last_name
|
|
|
|
String email
|
|
|
|
Boolean approved
|
|
|
|
UUID org_id
|
|
|
|
Org org
|
2022-10-18 04:18:47 +13:00
|
|
|
destroy()
|
2022-10-04 04:30:10 +13:00
|
|
|
read()
|
2022-10-06 19:04:21 +13:00
|
|
|
for_org(UUID org)
|
2023-01-17 04:04:09 +13:00
|
|
|
by_name(String name)
|
2024-03-28 09:06:40 +13:00
|
|
|
create(UUID org, String first_name, String last_name, String email)
|
|
|
|
update(String first_name, String last_name, String email)
|
2022-10-04 04:30:10 +13:00
|
|
|
approve()
|
|
|
|
unapprove()
|
|
|
|
}
|
|
|
|
class Org {
|
|
|
|
UUID id
|
|
|
|
String name
|
|
|
|
User[] users
|
2024-03-28 09:06:40 +13:00
|
|
|
update(String name)
|
|
|
|
create(String name)
|
2022-10-18 04:18:47 +13:00
|
|
|
destroy()
|
2022-10-04 04:30:10 +13:00
|
|
|
read()
|
2022-10-06 19:04:21 +13:00
|
|
|
by_name(String name)
|
2022-10-04 04:30:10 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
Org -- User
|
|
|
|
"""
|
|
|
|
end
|
2022-10-02 15:21:24 +13:00
|
|
|
end
|