Skip to content

Commit

Permalink
add not equals operation option and add string operation mapper for c…
Browse files Browse the repository at this point in the history
…onditional transform (#1641)
  • Loading branch information
accenture-mikeyc authored Mar 31, 2023
1 parent 674df10 commit dd8b01a
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 5 deletions.
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.24",
version: "0.2.25",
elixir: "~> 1.10",
build_path: "../../_build",
config_path: "../../config/config.exs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule AndiWeb.IngestionLiveView.Transformations.TransformationFieldBuilder d
</div>
<div>
<%= label(form, :conditionOperation, "Comparison", class: "label label--required", for: "transformation_condition_#{@id}__comparison") %>
<%= select(form, :conditionOperation, ["", "Is Equal To", "Is Greater Than", "Is Less Than"], [value: get_in(form.source.changes, [:parameters, :conditionOperation]), id: "transformation_condition_#{@id}__comparison", class: "select transformation-type", required: true]) %>
<%= select(form, :conditionOperation, ["", "Is Equal To", "Is Not Equal To", "Is Greater Than", "Is Less Than"], [value: get_in(form.source.changes, [:parameters, :conditionOperation]), id: "transformation_condition_#{@id}__comparison", class: "select transformation-type", required: true]) %>
<%= ErrorHelpers.error_tag(form.source, :conditionOperation, bind_to_input: false, id: "#{@id}_transformation_condition_comparison_error") %>
</div>
<div>
Expand Down
2 changes: 1 addition & 1 deletion apps/andi/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Andi.MixProject do
def project do
[
app: :andi,
version: "2.6.5",
version: "2.6.51",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
Expand Down
12 changes: 11 additions & 1 deletion apps/transformers/lib/transformation_conditions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ defmodule Transformers.Conditions do
do: try_parse(Map.fetch!(payload, target_field), data_type, target_format),
else: try_parse(target_value, data_type, target_format)

case operation do
case map_operation(operation) do
"=" -> {:ok, left_value == right_value}
"!=" -> {:ok, left_value != right_value}
">" -> {:ok, left_value > right_value}
Expand Down Expand Up @@ -160,4 +160,14 @@ defmodule Transformers.Conditions do
raise "unsupported parse type"
end
end

def map_operation(value) do
case value do
"Is Equal To" -> "="
"Is Not Equal To" -> "!="
"Is Greater Than" -> ">"
"Is Less Than" -> "<"
_ -> value
end
end
end
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.19",
version: "1.0.20",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
Expand Down
89 changes: 89 additions & 0 deletions apps/transformers/test/unit/conditions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,29 @@ defmodule Transformers.ConditionsTest do
result = Conditions.check(payload, parameters)
assert result == {:ok, false}
end

test "maps operation string 'Is Equal To'" do
parameters = %{
"targetField" => "testField",
"newValue" => "new value",
"valueType" => "string",
"condition" => "true",
"conditionCompareTo" => "Target Field",
"conditionDataType" => "string",
"sourceConditionField" => "testField",
"conditionOperation" => "Is Equal To",
"targetConditionField" => "compareField",
"targetConditionValue" => nil
}

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

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

describe "not equals" do
Expand Down Expand Up @@ -237,6 +260,28 @@ defmodule Transformers.ConditionsTest do
result = Conditions.check(payload, parameters)
assert result == {:ok, false}
end

test "maps operation string 'Is Not Equal To'" do
parameters = %{
"targetField" => "testField",
"newValue" => "new value",
"valueType" => "string",
"condition" => "true",
"conditionCompareTo" => "Static Value",
"conditionDataType" => "string",
"sourceConditionField" => "testField",
"conditionOperation" => "Is Not Equal To",
"targetConditionField" => nil,
"targetConditionValue" => "othervalue"
}

payload = %{
"testField" => "value"
}

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

describe "greater than" do
Expand Down Expand Up @@ -329,6 +374,28 @@ defmodule Transformers.ConditionsTest do
result = Conditions.check(payload, parameters)
assert result == {:ok, false}
end

test "maps operation string 'Is Greater Than'" do
parameters = %{
"targetField" => "testField",
"newValue" => "new value",
"valueType" => "string",
"condition" => "true",
"conditionCompareTo" => "Static Value",
"conditionDataType" => "number",
"sourceConditionField" => "testField",
"conditionOperation" => "Is Greater Than",
"targetConditionField" => nil,
"targetConditionValue" => "1"
}

payload = %{
"testField" => 2
}

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

describe "less than" do
Expand Down Expand Up @@ -421,6 +488,28 @@ defmodule Transformers.ConditionsTest do
result = Conditions.check(payload, parameters)
assert result == {:ok, false}
end

test "maps operation string 'Is Less Than'" do
parameters = %{
"targetField" => "testField",
"newValue" => "new value",
"valueType" => "string",
"condition" => "true",
"conditionCompareTo" => "Static Value",
"conditionDataType" => "number",
"sourceConditionField" => "testField",
"conditionOperation" => "Is Less Than",
"targetConditionField" => nil,
"targetConditionValue" => "3"
}

payload = %{
"testField" => 2
}

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

describe "datetime" do
Expand Down

0 comments on commit dd8b01a

Please sign in to comment.