Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1137 - Conditional booleans #1664

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/alchemist/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Alchemist.MixProject do
def project do
[
app: :alchemist,
version: "0.2.31",
version: "0.2.32",
elixir: "~> 1.10",
build_path: "../../_build",
config_path: "../../config/config.exs",
Expand Down
2 changes: 1 addition & 1 deletion apps/transformers/lib/transformation_conditions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ defmodule Transformers.Conditions do
defp try_parse(value, type, format) do
case String.downcase(type) do
"string" ->
value
if is_binary(value), do: value, else: Kernel.inspect(value)

"number" ->
if not is_number(value) do
Expand Down
2 changes: 1 addition & 1 deletion apps/transformers/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Transformers.MixProject do
def project do
[
app: :transformers,
version: "1.0.26",
version: "1.0.27",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
Expand Down
68 changes: 68 additions & 0 deletions apps/transformers/test/unit/conditions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,74 @@ defmodule Transformers.ConditionsTest do
result = Conditions.check(payload, parameters)
assert result == {:ok, true}
end

test "returns true when source field is a boolean and provided value are equal" do
parameters = %{
"targetField" => "testField",
"newValue" => "new value",
"valueType" => "string",
"condition" => "true",
"conditionCompareTo" => "Static Value",
"conditionDataType" => "string",
"sourceConditionField" => "testField",
"conditionOperation" => "=",
"targetConditionField" => nil,
"targetConditionValue" => "true"
}

payload = %{
"testField" => true
}

result = Conditions.check(payload, parameters)
assert result == {:ok, true}
end

test "returns true when source field and target field are boolean and they are equal" do
parameters = %{
"targetField" => "testField",
"newValue" => "new value",
"valueType" => "string",
"condition" => "true",
"conditionCompareTo" => "Target Field",
"conditionDataType" => "string",
"sourceConditionField" => "testField",
"conditionOperation" => "=",
"targetConditionField" => "compareField",
"targetConditionValue" => nil
}

payload = %{
"testField" => true,
"compareField" => true
}

result = Conditions.check(payload, parameters)
assert result == {:ok, true}
end

test "returns true when source field is string boolean and target field is boolean and they are equal" do
parameters = %{
"targetField" => "testField",
"newValue" => "new value",
"valueType" => "string",
"condition" => "true",
"conditionCompareTo" => "Target Field",
"conditionDataType" => "string",
"sourceConditionField" => "testField",
"conditionOperation" => "=",
"targetConditionField" => "compareField",
"targetConditionValue" => nil
}

payload = %{
"testField" => "true",
"compareField" => true
}

result = Conditions.check(payload, parameters)
assert result == {:ok, true}
end
end

describe "not equals" do
Expand Down