Skip to content

Commit 5b7b8b9

Browse files
incoming_data_event + test
Signed-off-by: Gabriele Ghio <gabriele.ghio@secomind.com>
1 parent 95c012a commit 5b7b8b9

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#
2+
# This file is part of Astarte.
3+
#
4+
# Copyright 2025 SECO Mind Srl
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
defmodule Astarte.Core.Generators.Triggers.SimpleEvents.IncomingDataEvent do
20+
@moduledoc """
21+
This module provides generators for Astarte Trigger Simple Event IncomingDataEvent struct.
22+
"""
23+
use ExUnitProperties
24+
25+
import Astarte.Generators.Utilities.ParamsGen
26+
27+
alias Astarte.Core.Triggers.SimpleEvents.IncomingDataEvent
28+
29+
alias Astarte.Core.Interface
30+
31+
alias Astarte.Core.Generators.Interface, as: InterfaceGenerator
32+
alias Astarte.Core.Generators.Mapping.Value, as: ValueGenerator
33+
34+
@spec incoming_data_event() :: StreamData.t(IncomingDataEvent.t())
35+
@spec incoming_data_event(keyword :: keyword()) :: StreamData.t(IncomingDataEvent.t())
36+
def incoming_data_event(params \\ []) do
37+
gen_fields =
38+
params gen all :interface,
39+
%Interface{name: interface_name} = interface <-
40+
InterfaceGenerator.interface(),
41+
value <- ValueGenerator.value(interface: interface),
42+
params: params do
43+
%{
44+
interface: interface_name,
45+
path: value.path,
46+
bson_value: value.value
47+
}
48+
end
49+
50+
gen_fields
51+
|> bind(fn fields ->
52+
fields
53+
|> Map.new(fn {k, v} -> {k, constant(v)} end)
54+
|> optional_map()
55+
end)
56+
|> map(&struct(IncomingDataEvent, &1))
57+
end
58+
end
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#
2+
# This file is part of Astarte.
3+
#
4+
# Copyright 2025 SECO Mind Srl
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
defmodule Astarte.Core.Generators.Triggers.SimpleEvents.IncomingDataEventTest do
20+
use ExUnit.Case, async: true
21+
use ExUnitProperties
22+
23+
alias Astarte.Core.Triggers.SimpleEvents.IncomingDataEvent
24+
25+
alias Astarte.Core.Generators.Interface, as: InterfaceGenerator
26+
alias Astarte.Core.Generators.Mapping.Value, as: ValueGenerator
27+
28+
alias Astarte.Core.Generators.Triggers.SimpleEvents.IncomingDataEvent,
29+
as: IncomingDataEventGenerator
30+
31+
@moduletag :trigger
32+
@moduletag :simple_event
33+
@moduletag :incoming_data_event
34+
35+
@doc false
36+
describe "triggers incoming_data_event generator" do
37+
@describetag :success
38+
@describetag :ut
39+
property "generates valid incoming_data_event" do
40+
check all incoming_data_event <- IncomingDataEventGenerator.incoming_data_event() do
41+
assert %IncomingDataEvent{} = incoming_data_event
42+
end
43+
end
44+
45+
property "generates valid incoming_data_event using interface" do
46+
check all interface <- InterfaceGenerator.interface(),
47+
incoming_data_event <-
48+
IncomingDataEventGenerator.incoming_data_event(interface: interface) do
49+
assert %IncomingDataEvent{} = incoming_data_event
50+
end
51+
end
52+
53+
property "generates valid incoming_data_event using interface and value" do
54+
check all interface <- InterfaceGenerator.interface(),
55+
value <- ValueGenerator.value(interface: interface),
56+
incoming_data_event <-
57+
IncomingDataEventGenerator.incoming_data_event(
58+
interface: interface,
59+
value: value
60+
) do
61+
assert %IncomingDataEvent{} = incoming_data_event
62+
end
63+
end
64+
end
65+
end

0 commit comments

Comments
 (0)