Skip to content

Commit 0021c30

Browse files
committed
Feat: ARX004_3A - Script & Types Integration Tests
Add integration tests for SQL script operations and type creation against a real ArcadeDB server. Script tests cover: - LET/RETURN statements with single and multiple variables - Parameter binding in scripts - Aggregation queries (count, sum) Type tests cover: - Document, vertex, and edge type creation - Property creation on types - Type introspection via schema:types - Edge creation between vertices - Type dropping (with UNSAFE for data)
1 parent ae233cc commit 0021c30

File tree

2 files changed

+351
-0
lines changed

2 files changed

+351
-0
lines changed

test/integration/script_test.exs

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
defmodule Arcadex.Integration.ScriptTest do
2+
@moduledoc """
3+
Integration tests for SQL script operations against ArcadeDB.
4+
"""
5+
use Arcadex.IntegrationCase, async: true
6+
7+
setup_all %{conn: conn} do
8+
Arcadex.command!(conn, "CREATE DOCUMENT TYPE Order")
9+
Arcadex.command!(conn, "CREATE DOCUMENT TYPE OrderItem")
10+
Arcadex.command!(conn, "CREATE PROPERTY Order.uid STRING")
11+
Arcadex.command!(conn, "CREATE PROPERTY Order.status STRING")
12+
Arcadex.command!(conn, "CREATE PROPERTY OrderItem.order_uid STRING")
13+
Arcadex.command!(conn, "CREATE PROPERTY OrderItem.name STRING")
14+
Arcadex.command!(conn, "CREATE PROPERTY OrderItem.quantity INTEGER")
15+
:ok
16+
end
17+
18+
describe "script with LET and RETURN" do
19+
test "script with single LET and RETURN", %{conn: conn} do
20+
uid = generate_uid()
21+
22+
Arcadex.command!(
23+
conn,
24+
"INSERT INTO Order SET uid = :uid, status = 'pending'",
25+
%{uid: uid}
26+
)
27+
28+
result =
29+
Arcadex.script!(
30+
conn,
31+
"""
32+
LET order = SELECT FROM Order WHERE uid = :uid;
33+
RETURN $order
34+
""",
35+
%{uid: uid}
36+
)
37+
38+
# Script returns the result of RETURN directly
39+
assert length(result) == 1
40+
[order] = result
41+
assert order["uid"] == uid
42+
assert order["status"] == "pending"
43+
end
44+
45+
test "script with multiple LET statements", %{conn: conn} do
46+
uid = generate_uid()
47+
48+
Arcadex.command!(
49+
conn,
50+
"INSERT INTO Order SET uid = :uid, status = 'active'",
51+
%{uid: uid}
52+
)
53+
54+
Arcadex.command!(
55+
conn,
56+
"INSERT INTO OrderItem SET order_uid = :uid, name = 'Item1', quantity = 2",
57+
%{uid: uid}
58+
)
59+
60+
Arcadex.command!(
61+
conn,
62+
"INSERT INTO OrderItem SET order_uid = :uid, name = 'Item2', quantity = 3",
63+
%{uid: uid}
64+
)
65+
66+
[result] =
67+
Arcadex.script!(
68+
conn,
69+
"""
70+
LET order = SELECT FROM Order WHERE uid = :uid;
71+
LET items = SELECT FROM OrderItem WHERE order_uid = :uid;
72+
RETURN { order: $order, items: $items }
73+
""",
74+
%{uid: uid}
75+
)
76+
77+
# When returning a map, ArcadeDB wraps it in a "value" key
78+
value = result["value"]
79+
assert length(value["order"]) == 1
80+
assert length(value["items"]) == 2
81+
end
82+
83+
test "script with parameters", %{conn: conn} do
84+
uid = generate_uid()
85+
status = "completed"
86+
87+
Arcadex.command!(
88+
conn,
89+
"INSERT INTO Order SET uid = :uid, status = :status",
90+
%{uid: uid, status: status}
91+
)
92+
93+
result =
94+
Arcadex.script!(
95+
conn,
96+
"""
97+
LET orders = SELECT FROM Order WHERE uid = :uid AND status = :status;
98+
RETURN $orders
99+
""",
100+
%{uid: uid, status: status}
101+
)
102+
103+
# Script returns the result directly
104+
assert length(result) == 1
105+
[order] = result
106+
assert order["status"] == status
107+
end
108+
end
109+
110+
describe "script with computations" do
111+
test "script with count computation", %{conn: conn} do
112+
uid = generate_uid()
113+
114+
Arcadex.command!(
115+
conn,
116+
"INSERT INTO Order SET uid = :uid, status = 'active'",
117+
%{uid: uid}
118+
)
119+
120+
for i <- 1..3 do
121+
Arcadex.command!(
122+
conn,
123+
"INSERT INTO OrderItem SET order_uid = :uid, name = :name, quantity = :qty",
124+
%{uid: uid, name: "Item#{i}", qty: i}
125+
)
126+
end
127+
128+
[result] =
129+
Arcadex.script!(
130+
conn,
131+
"""
132+
LET items = SELECT FROM OrderItem WHERE order_uid = :uid;
133+
LET count = SELECT count(*) as total FROM OrderItem WHERE order_uid = :uid;
134+
RETURN { items: $items, count: $count }
135+
""",
136+
%{uid: uid}
137+
)
138+
139+
# When returning a map, ArcadeDB wraps it in a "value" key
140+
value = result["value"]
141+
assert length(value["items"]) == 3
142+
[count_result] = value["count"]
143+
assert count_result["total"] == 3
144+
end
145+
146+
test "script with aggregation", %{conn: conn} do
147+
uid = generate_uid()
148+
149+
Arcadex.command!(
150+
conn,
151+
"INSERT INTO Order SET uid = :uid, status = 'active'",
152+
%{uid: uid}
153+
)
154+
155+
for i <- 1..3 do
156+
Arcadex.command!(
157+
conn,
158+
"INSERT INTO OrderItem SET order_uid = :uid, name = :name, quantity = :qty",
159+
%{uid: uid, name: "Item#{i}", qty: i * 10}
160+
)
161+
end
162+
163+
result =
164+
Arcadex.script!(
165+
conn,
166+
"""
167+
LET total = SELECT sum(quantity) as total_qty FROM OrderItem WHERE order_uid = :uid;
168+
RETURN $total
169+
""",
170+
%{uid: uid}
171+
)
172+
173+
# Script returns the result directly
174+
[total] = result
175+
# 10 + 20 + 30 = 60
176+
assert total["total_qty"] == 60
177+
end
178+
end
179+
end

test/integration/types_test.exs

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
defmodule Arcadex.Integration.TypesTest do
2+
@moduledoc """
3+
Integration tests for type creation operations against ArcadeDB.
4+
"""
5+
use Arcadex.IntegrationCase, async: true
6+
7+
describe "document types" do
8+
@tag :fresh_db
9+
test "create document type", %{conn: conn} do
10+
Arcadex.command!(conn, "CREATE DOCUMENT TYPE MyDoc")
11+
12+
[type] =
13+
Arcadex.query!(
14+
conn,
15+
"SELECT FROM schema:types WHERE name = 'MyDoc'"
16+
)
17+
18+
assert type["name"] == "MyDoc"
19+
end
20+
21+
@tag :fresh_db
22+
test "create document type with properties", %{conn: conn} do
23+
Arcadex.command!(conn, "CREATE DOCUMENT TYPE Customer")
24+
Arcadex.command!(conn, "CREATE PROPERTY Customer.name STRING")
25+
Arcadex.command!(conn, "CREATE PROPERTY Customer.age INTEGER")
26+
Arcadex.command!(conn, "CREATE PROPERTY Customer.active BOOLEAN")
27+
28+
[type] =
29+
Arcadex.query!(
30+
conn,
31+
"SELECT FROM schema:types WHERE name = 'Customer'"
32+
)
33+
34+
assert type["name"] == "Customer"
35+
properties = type["properties"]
36+
property_names = Enum.map(properties, & &1["name"])
37+
38+
assert "name" in property_names
39+
assert "age" in property_names
40+
assert "active" in property_names
41+
end
42+
end
43+
44+
describe "vertex types" do
45+
@tag :fresh_db
46+
test "create vertex type", %{conn: conn} do
47+
Arcadex.command!(conn, "CREATE VERTEX TYPE Person")
48+
49+
[type] =
50+
Arcadex.query!(
51+
conn,
52+
"SELECT FROM schema:types WHERE name = 'Person'"
53+
)
54+
55+
assert type["name"] == "Person"
56+
assert type["type"] == "vertex"
57+
end
58+
59+
@tag :fresh_db
60+
test "create vertex and insert", %{conn: conn} do
61+
Arcadex.command!(conn, "CREATE VERTEX TYPE City")
62+
Arcadex.command!(conn, "CREATE PROPERTY City.name STRING")
63+
64+
[city] =
65+
Arcadex.command!(
66+
conn,
67+
"CREATE VERTEX City SET name = 'Tokyo'"
68+
)
69+
70+
assert city["name"] == "Tokyo"
71+
assert city["@rid"]
72+
assert city["@type"] == "City"
73+
end
74+
end
75+
76+
describe "edge types" do
77+
@tag :fresh_db
78+
test "create edge type", %{conn: conn} do
79+
Arcadex.command!(conn, "CREATE VERTEX TYPE Person")
80+
Arcadex.command!(conn, "CREATE EDGE TYPE Knows")
81+
82+
[type] =
83+
Arcadex.query!(
84+
conn,
85+
"SELECT FROM schema:types WHERE name = 'Knows'"
86+
)
87+
88+
assert type["name"] == "Knows"
89+
assert type["type"] == "edge"
90+
end
91+
92+
@tag :fresh_db
93+
test "create edge between vertices", %{conn: conn} do
94+
Arcadex.command!(conn, "CREATE VERTEX TYPE Person")
95+
Arcadex.command!(conn, "CREATE PROPERTY Person.name STRING")
96+
Arcadex.command!(conn, "CREATE EDGE TYPE Knows")
97+
Arcadex.command!(conn, "CREATE PROPERTY Knows.since INTEGER")
98+
99+
[alice] =
100+
Arcadex.command!(
101+
conn,
102+
"CREATE VERTEX Person SET name = 'Alice'"
103+
)
104+
105+
[bob] =
106+
Arcadex.command!(
107+
conn,
108+
"CREATE VERTEX Person SET name = 'Bob'"
109+
)
110+
111+
alice_rid = alice["@rid"]
112+
bob_rid = bob["@rid"]
113+
114+
[edge] =
115+
Arcadex.command!(
116+
conn,
117+
"CREATE EDGE Knows FROM #{alice_rid} TO #{bob_rid} SET since = 2020"
118+
)
119+
120+
assert edge["@type"] == "Knows"
121+
assert edge["since"] == 2020
122+
assert edge["@in"] == bob_rid
123+
assert edge["@out"] == alice_rid
124+
end
125+
end
126+
127+
describe "drop types" do
128+
@tag :fresh_db
129+
test "drop type", %{conn: conn} do
130+
Arcadex.command!(conn, "CREATE DOCUMENT TYPE TempDoc")
131+
132+
# Verify type exists
133+
[type] =
134+
Arcadex.query!(
135+
conn,
136+
"SELECT FROM schema:types WHERE name = 'TempDoc'"
137+
)
138+
139+
assert type["name"] == "TempDoc"
140+
141+
# Drop the type
142+
Arcadex.command!(conn, "DROP TYPE TempDoc")
143+
144+
# Verify type no longer exists
145+
result =
146+
Arcadex.query!(
147+
conn,
148+
"SELECT FROM schema:types WHERE name = 'TempDoc'"
149+
)
150+
151+
assert result == []
152+
end
153+
154+
@tag :fresh_db
155+
test "drop type with UNSAFE when data exists", %{conn: conn} do
156+
Arcadex.command!(conn, "CREATE DOCUMENT TYPE TempData")
157+
Arcadex.command!(conn, "INSERT INTO TempData SET value = 1")
158+
159+
# Drop with UNSAFE to force deletion even with data
160+
Arcadex.command!(conn, "DROP TYPE TempData UNSAFE")
161+
162+
# Verify type no longer exists
163+
result =
164+
Arcadex.query!(
165+
conn,
166+
"SELECT FROM schema:types WHERE name = 'TempData'"
167+
)
168+
169+
assert result == []
170+
end
171+
end
172+
end

0 commit comments

Comments
 (0)