Skip to content

Commit

Permalink
trigger_payload: accept trigger_name key
Browse files Browse the repository at this point in the history
Astarte >= 1.2.0 sends an additional trigger_name key in the trigger payload.
This was making Edgehog crash since Ash doesn't accept additional input keys
by default.
  • Loading branch information
rbino committed Oct 28, 2024
1 parent 6845d45 commit e60799a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.9.1] - Unreleased
### Fixed
- Allow receiving `trigger_name` key in trigger payload, which is sent by Astarte >= 1.2.0.

## [0.9.0] - 2024-10-25
### Fixed
- Correctly support automatic login attempts on the frontend regardless of existing auth sessions ([#596](https://github.com/edgehog-device-manager/edgehog/pull/596)).
Expand Down
5 changes: 5 additions & 0 deletions backend/lib/edgehog/triggers/trigger_payload.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@ defmodule Edgehog.Triggers.TriggerPayload do
public? true
allow_nil? false
end

# This is sent in Astarte >= 1.2.0, so it can be nil
attribute :trigger_name, :string do
public? true
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,34 @@ defmodule EdgehogWeb.Controllers.AstarteTriggerControllerTest do
} = device
end

test "accepts `trigger_name` key in trigger payload (Astarte >= 1.2.0)", ctx do
%{
conn: conn,
path: path,
realm: realm,
tenant: tenant
} = ctx

%Device{device_id: device_id} =
device_fixture(
tenant: tenant,
realm_id: realm.id,
online: false,
last_connection: DateTime.add(utc_now_second(), -50, :minute),
last_disconnection: DateTime.add(utc_now_second(), -10, :minute)
)

timestamp = utc_now_second()

astarte_1_2_0_event =
device_id
|> connection_trigger(timestamp)
|> Map.put(:trigger_name, "connection_trigger")

expect(DeviceStatusMock, :get, 0, fn _client, _device_id -> flunk() end)
assert conn |> post(path, astarte_1_2_0_event) |> response(200)
end

test "disconnection events update an existing device, not calling Astarte", ctx do
%{
conn: conn,
Expand Down

0 comments on commit e60799a

Please sign in to comment.