Skip to content

Commit

Permalink
add conversion transformation (#1596)
Browse files Browse the repository at this point in the history
* add conversion transformation

* version bump

Co-authored-by: Ian Abbott <ij.abbott2306@gmail.com>
  • Loading branch information
ian-j-abbott-accenture and ijabbott authored Jan 25, 2023
1 parent 4512711 commit 6d34bb9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
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.5.50",
version: "2.5.51",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,43 @@ defmodule AndiWeb.IngestionLiveView.Transformations.TransformationFormTest do
assert element(view, "##{target_format_id}") |> has_element?()
end

test "after selecting conversion transformation, conversion fields appear" do
transformation_changeset = Transformation.changeset_for_draft(%{})
assert {:ok, view, html} = render_transformation_form(transformation_changeset)

select_type("conversion", view)

target_field_id = build_field_id("field")
source_field_type = build_field_id("sourceType")
target_field_type = build_field_id("targetType")

assert has_element?(view, ".transformation-field")
assert element(view, "label[for=#{target_field_id}]", "Field to Convert") |> has_element?()
assert element(view, "label[for=#{source_field_type}]", "Source Data Type") |> has_element?()
assert element(view, "label[for=#{target_field_type}]", "Target Data Type") |> has_element?()
assert element(view, "##{target_field_id}") |> has_element?()
assert element(view, "##{source_field_type}") |> has_element?()
assert element(view, "##{target_field_type}") |> has_element?()
end

test "if conversion transformation is selected show fields on load" do
transformation_changeset = Transformation.changeset_for_draft(%{type: "conversion"})

assert {:ok, view, html} = render_transformation_form(transformation_changeset)

target_field_id = build_field_id("field")
source_field_type = build_field_id("sourceType")
target_field_type = build_field_id("targetType")

assert has_element?(view, ".transformation-field")
assert element(view, "label[for=#{target_field_id}]", "Field to Convert") |> has_element?()
assert element(view, "label[for=#{source_field_type}]", "Source Data Type") |> has_element?()
assert element(view, "label[for=#{target_field_type}]", "Target Data Type") |> has_element?()
assert element(view, "##{target_field_id}") |> has_element?()
assert element(view, "##{source_field_type}") |> has_element?()
assert element(view, "##{target_field_type}") |> has_element?()
end

test "shows error message if field missing" do
transformation_changeset = Transformation.changeset_for_draft(%{type: "remove"})
assert {:ok, view, html} = render_transformation_form(transformation_changeset)
Expand Down
4 changes: 4 additions & 0 deletions apps/transformers/lib/transformation_fields.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ defmodule Transformers.TransformationFields do
Transformers.DateTime.fields()
end

def fields_for("conversion") do
Transformers.TypeConversion.fields()
end

def fields_for(_unsupported) do
[]
end
Expand Down
23 changes: 23 additions & 0 deletions apps/transformers/lib/transformations/type_conversion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,27 @@ defmodule Transformers.TypeConversion do
_ -> {:error, "Cannot parse field #{field} with value #{value} into #{target_type}"}
end
end

def fields() do
[
%{
field_name: @field,
field_type: "string",
field_label: "Field to Convert",
options: nil
},
%{
field_name: @source_type,
field_type: "string",
field_label: "Source Data Type",
options: ["integer", "string", "float"]
},
%{
field_name: @target_type,
field_type: "string",
field_label: "Target Data Type",
options: ["integer", "string", "float"]
}
]
end
end

0 comments on commit 6d34bb9

Please sign in to comment.