-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add data_detector_types attribute to FieldContent struct
- Loading branch information
Showing
3 changed files
with
152 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,4 +146,62 @@ defmodule ExPass.Structs.FieldContentTest do | |
assert Jason.encode!(result) == ~s({"currencyCode":"USD"}) | ||
end | ||
end | ||
|
||
describe "data_detector_types" do | ||
test "new/1 creates a valid FieldContent struct with valid data_detector_types" do | ||
input = %{ | ||
attributed_value: "Contact us at [email protected]", | ||
data_detector_types: ["PKDataDetectorTypePhoneNumber", "PKDataDetectorTypeLink"] | ||
} | ||
|
||
result = FieldContent.new(input) | ||
|
||
assert %FieldContent{ | ||
attributed_value: "Contact us at [email protected]", | ||
data_detector_types: ["PKDataDetectorTypePhoneNumber", "PKDataDetectorTypeLink"] | ||
} = result | ||
|
||
assert Jason.encode!(result) == | ||
~s({"attributedValue":"Contact us at [email protected]","dataDetectorTypes":["PKDataDetectorTypePhoneNumber","PKDataDetectorTypeLink"]}) | ||
end | ||
|
||
test "new/1 creates a valid FieldContent struct with empty data_detector_types" do | ||
input = %{attributed_value: "No detectors", data_detector_types: []} | ||
result = FieldContent.new(input) | ||
|
||
assert %FieldContent{attributed_value: "No detectors", data_detector_types: []} = result | ||
|
||
assert Jason.encode!(result) == | ||
~s({"attributedValue":"No detectors","dataDetectorTypes":[]}) | ||
end | ||
|
||
test "new/1 allows nil data_detector_types" do | ||
result = FieldContent.new(%{attributed_value: "Default detectors"}) | ||
|
||
assert %FieldContent{attributed_value: "Default detectors", data_detector_types: nil} = | ||
result | ||
|
||
assert Jason.encode!(result) == ~s({"attributedValue":"Default detectors"}) | ||
end | ||
|
||
test "new/1 raises ArgumentError for invalid data_detector_types" do | ||
assert_raise ArgumentError, | ||
~r/Invalid data detector type: InvalidDetector. Supported types are: PKDataDetectorTypePhoneNumber, PKDataDetectorTypeLink, PKDataDetectorTypeAddress, PKDataDetectorTypeCalendarEvent/, | ||
fn -> | ||
FieldContent.new(%{ | ||
attributed_value: "Invalid", | ||
data_detector_types: ["InvalidDetector"] | ||
}) | ||
end | ||
end | ||
|
||
test "new/1 raises ArgumentError when data_detector_types is not a list" do | ||
assert_raise ArgumentError, ~r/data_detector_types must be a list/, fn -> | ||
FieldContent.new(%{ | ||
attributed_value: "Invalid", | ||
data_detector_types: "PKDataDetectorTypePhoneNumber" | ||
}) | ||
end | ||
end | ||
end | ||
end |