diff --git a/.formatter.exs b/.formatter.exs index 5a100fd..3bad048 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -2,5 +2,6 @@ [ inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"], line_length: 120, - import_deps: [:placebo] + import_deps: [:placebo], + locals_without_parens: [where: :*] ] diff --git a/README.md b/README.md index b88ef98..1468e4d 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This package can be installed by adding `smart_city_registry` to your list of de ```elixir def deps do - [{:smart_city_registry, "~> 2.6.6"}] + [{:smart_city_registry, "~> 3.3.0"}] end ``` diff --git a/lib/smart_city/dataset/technical.ex b/lib/smart_city/dataset/technical.ex index 23f4aaf..4db6fa5 100644 --- a/lib/smart_city/dataset/technical.ex +++ b/lib/smart_city/dataset/technical.ex @@ -24,11 +24,13 @@ defmodule SmartCity.Dataset.Technical do authHeaders: not_required(map()), protocol: not_required(list(String.t())), partitioner: not_required(%{type: String.t(), query: String.t()}), - private: not_required(boolean()) + private: not_required(boolean()), + allow_duplicates: not_required(boolean()) } @derive Jason.Encoder - defstruct cadence: "never", + defstruct allow_duplicates: true, + cadence: "never", credentials: false, dataName: nil, sourceHeaders: %{}, diff --git a/mix.exs b/mix.exs index e510e98..2ef9c76 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule SmartCity.Registry.MixProject do def project do [ app: :smart_city_registry, - version: "3.2.2", + version: "3.3.0", elixir: "~> 1.8", start_permanent: Mix.env() == :prod, deps: deps(), diff --git a/test/unit/smart_city/dataset/technical_test.exs b/test/unit/smart_city/dataset/technical_test.exs index e7ba136..569bd5b 100644 --- a/test/unit/smart_city/dataset/technical_test.exs +++ b/test/unit/smart_city/dataset/technical_test.exs @@ -1,6 +1,7 @@ defmodule SmartCity.Dataset.TechnicalTest do use ExUnit.Case - doctest SmartCity.Dataset.Technical + import Checkov + alias SmartCity.Dataset.Technical setup do @@ -37,9 +38,22 @@ defmodule SmartCity.Dataset.TechnicalTest do }) assert actual.dataName == "dataset" - assert actual.schema == [] - assert actual.cadence == "never" - assert actual.sourceType == "remote" + end + + data_test "field #{field} has a default value of #{default}" do + actual = + Technical.new(%{ + dataName: "dataset", + orgName: "org", + systemName: "org__dataset", + sourceUrl: "https://example.com", + sourceFormat: "gtfs" + }) + + assert Map.get(actual, field) == default + + where field: [:schema, :cadence, :sourceType, :allow_duplicates], + default: [[], "never", "remote", true] end test "returns Technical struct when given string keys", %{message: tech} do @@ -57,11 +71,10 @@ defmodule SmartCity.Dataset.TechnicalTest do assert List.first(actual.transformations).foo.bar == 1 end - test "throws error when creating Technical struct without required fields", %{message: tech} do - assert_raise ArgumentError, fn -> Technical.new(tech |> Map.delete("dataName")) end - assert_raise ArgumentError, fn -> Technical.new(tech |> Map.delete("orgName")) end - assert_raise ArgumentError, fn -> Technical.new(tech |> Map.delete("systemName")) end - assert_raise ArgumentError, fn -> Technical.new(tech |> Map.delete("sourceUrl")) end + data_test "throws error when creating Technical struct without required field: #{field}", %{message: tech} do + assert_raise ArgumentError, fn -> Technical.new(tech |> Map.delete(field)) end + + where field: ["dataName", "orgName", "systemName", "sourceUrl"] end end