@@ -22,10 +22,8 @@ defmodule Astarte.Core.Generators.Mapping.ValueTest do
2222
2323 alias Astarte.Core.Interface
2424 alias Astarte.Core.Mapping
25- alias Astarte.Core.Mapping.EndpointsAutomaton
2625
2726 alias Astarte.Core.Generators.Interface , as: InterfaceGenerator
28- alias Astarte.Core.Generators.Mapping , as: MappingGenerator
2927 alias Astarte.Core.Generators.Mapping.Value , as: ValueGenerator
3028
3129 @ moduletag :value
@@ -121,98 +119,39 @@ defmodule Astarte.Core.Generators.Mapping.ValueTest do
121119 @ describetag :success
122120 @ describetag :ut
123121
124- property "generates value based on interface" do
122+ property "generates value based on interface (gen) " do
125123 gen = InterfaceGenerator . interface ( ) |> ValueGenerator . value ( )
126124
127125 check all value <- gen do
128126 assert % { path: _path , value: _value } = value
129127 end
130128 end
131129
132- @ tag :temp
133- property "generates values based on aggregation :object must have mapping endpoint = base_endpoint + postfix" do
134- gen all % Interface { mappings: mappings } = interface <-
135- InterfaceGenerator . interface ( aggregation: :object ) ,
136- % { path: path , value: value } <- ValueGenerator . value ( interface ) do
137- IO . inspect ( "Ciao" )
130+ property "generates value based on interface (struct)" do
131+ check all interface <- InterfaceGenerator . interface ( ) ,
132+ value <- ValueGenerator . value ( interface ) do
133+ assert % { path: _path , value: _value } = value
134+ end
135+ end
138136
139- for % Mapping { endpoint: endpoint } <- mappings do
140- IO . inspect ( endpoint )
141- end
137+ property "generates value must have mapping path matches endpoint" do
138+ check all % Interface { mappings: mappings , aggregation: aggregation } = interface <-
139+ InterfaceGenerator . interface ( ) ,
140+ % { path: path , value: _value } <- ValueGenerator . value ( interface ) do
141+ assert Enum . any? ( mappings , fn % Mapping { endpoint: endpoint } ->
142+ ValueGenerator . path_matches_endpoint? ( aggregation , endpoint , path )
143+ end )
142144 end
143145 end
144146
145147 property "generates values based on aggregation :object must have postfix different from other fields" do
146148 gen = InterfaceGenerator . interface ( aggregation: :object ) |> ValueGenerator . value ( )
147149
148150 check all % { path: path , value: value } <- gen do
149- endpoint_postfix = path |> String . split ( "/" ) |> List . last ( )
150-
151- for { postfix , _ } <- value do
152- refute postfix == endpoint_postfix
153- end
151+ last_seg = path |> String . split ( "/" ) |> List . last ( )
152+ keys = Map . keys ( value )
153+ refute last_seg in keys
154154 end
155155 end
156156 end
157-
158- # @doc false
159- # describe "value generator" do
160- # @describetag :success
161- # @describetag :ut
162-
163- # property "generates value based on interface" do
164- # check all value <- InterfaceGenerator.interface() |> ValueGenerator.value() do
165- # assert %{path: _path, value: _value} = value
166- # end
167- # end
168-
169- # property "generates valid value based on aggregation" do
170- # check all aggregation <- one_of([:individual, :object]),
171- # value <-
172- # InterfaceGenerator.interface(aggregation: aggregation)
173- # |> ValueGenerator.value() do
174- # assert valid?(aggregation, value)
175- # end
176- # end
177-
178- # property "generates values for the correct endpoint for :individual interfaces" do
179- # check all interface <- InterfaceGenerator.interface(aggregation: :individual),
180- # %{path: path, value: value} <- ValueGenerator.value(interface) do
181- # assert valid_value_for_path?(interface, path, value)
182- # end
183- # end
184-
185- # # property "check if path matches at least one endpoint considering aggregation" do
186- # # check all aggregation <- one_of([:individual, :object]),
187- # # interface_type <- InterfaceGenerator.type(),
188- # # mappings <-
189- # # MappingGenerator.mapping(interface_type: interface_type)
190- # # |> list_of(min_length: 1, max_length: 10),
191- # # %{path: path} <-
192- # # InterfaceGenerator.interface(
193- # # type: interface_type,
194- # # aggregation: aggregation,
195- # # mappings: mappings
196- # # )
197- # # |> ValueGenerator.value() do
198- # # assert Enum.any?(mappings, fn %Mapping{endpoint: endpoint} ->
199- # # path_matches_endpoint?(aggregation, path, endpoint)
200- # # end)
201- # # end
202- # # end
203-
204- # property "check field is present in object field (aggregation :object)" do
205- # check all %{mappings: mappings} = interface <-
206- # InterfaceGenerator.interface(aggregation: :object),
207- # %{value: value} <- ValueGenerator.value(interface),
208- # endpoints =
209- # mappings
210- # |> Enum.map(fn %Mapping{endpoint: endpoint} ->
211- # Regex.replace(~r"^.*/", endpoint, "")
212- # end),
213- # fields = value |> Enum.map(fn {field, _} -> field end) do
214- # assert Enum.all?(fields, &(&1 in endpoints))
215- # end
216- # end
217- # end
218157end
0 commit comments