Skip to content

Commit 762ee3f

Browse files
author
Shubham Gupta
committed
Add validation for Structured Event
1 parent b07439e commit 762ee3f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/snowplow_tracker/events/structured.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ defmodule SnowplowTracker.Events.Structured do
8181
raise Errors.InvalidParam, "action cannot be blank"
8282
end
8383

84+
def validate(%Structured{value: ""}) do
85+
raise Errors.InvalidParam, "value cannot be blank"
86+
end
87+
88+
def validate(%Structured{value: nil}) do
89+
raise Errors.InvalidParam, "value cannot be blank"
90+
end
91+
8492
def validate(%Structured{} = event), do: event
8593

8694
@spec get(t()) :: Payload.t()

test/snowplow_tracker/events/structured_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ defmodule SnowplowTracker.Events.StructuredTest do
4848
end
4949

5050
test "returns the event if it is valid" do
51-
event = %Events.Structured{category: "animal", action: "pet"}
51+
event = Events.Structured.new(%{category: "animal", action: "pet"})
5252
assert event == Events.Structured.validate(event)
5353
end
5454
end

0 commit comments

Comments
 (0)