forked from ash-project/ash_postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_layer_metadata_test.exs
More file actions
80 lines (64 loc) · 2.23 KB
/
data_layer_metadata_test.exs
File metadata and controls
80 lines (64 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# SPDX-FileCopyrightText: 2019 ash_postgres contributors <https://github.com/ash-project/ash_postgres/graphs.contributors>
#
# SPDX-License-Identifier: MIT
defmodule AshPostgres.DataLayerMetadataTest do
use AshPostgres.RepoCase, async: false
alias AshPostgres.Test.Post
require Ash.Query
test "update_query sets bulk metadata on returned records" do
_post1 = Ash.create!(Post, %{title: "title1"})
_post2 = Ash.create!(Post, %{title: "title2"})
_post3 = Ash.create!(Post, %{title: "title3"})
ash_query = Ash.Query.new(Post)
{:ok, query} = Ash.Query.data_layer_query(ash_query)
ref = make_ref()
changeset = %Ash.Changeset{
resource: Post,
action_type: :update,
data: %Post{},
attributes: %{title: "updated"},
atomics: [],
filter: nil,
context: %{bulk_update: %{index: 0, ref: ref}},
domain: AshPostgres.Test.Domain,
tenant: nil,
timeout: :infinity
}
{:ok, results} =
AshPostgres.DataLayer.update_query(query, changeset, Post, return_records?: true)
assert is_list(results)
assert length(results) > 0
Enum.each(results, fn result ->
assert is_integer(result.__metadata__.bulk_update_index)
assert result.__metadata__.bulk_action_ref == ref
end)
end
test "destroy_query sets bulk metadata on returned records" do
_post1 = Ash.create!(Post, %{title: "title1"})
_post2 = Ash.create!(Post, %{title: "title2"})
_post3 = Ash.create!(Post, %{title: "title3"})
ash_query = Ash.Query.new(Post)
{:ok, query} = Ash.Query.data_layer_query(ash_query)
ref = make_ref()
changeset = %Ash.Changeset{
resource: Post,
action_type: :destroy,
data: %Post{},
attributes: %{},
atomics: [],
filter: nil,
context: %{bulk_destroy: %{index: 0, ref: ref}},
domain: AshPostgres.Test.Domain,
tenant: nil,
timeout: :infinity
}
{:ok, results} =
AshPostgres.DataLayer.destroy_query(query, changeset, Post, return_records?: true)
assert is_list(results)
assert length(results) > 0
Enum.each(results, fn result ->
assert is_integer(result.__metadata__.bulk_destroy_index)
assert result.__metadata__.bulk_action_ref == ref
end)
end
end