Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #36 from smartcitiesdata/optional_deduping
Browse files Browse the repository at this point in the history
reaper#79 - Add allow_duplicates to technical struct with default val…
  • Loading branch information
bbalser committed Jun 28, 2019
2 parents c631ce7 + 3d639ad commit 658cd44
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .formatter.exs
Expand Up @@ -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: :*]
]
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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
```

Expand Down
6 changes: 4 additions & 2 deletions lib/smart_city/dataset/technical.ex
Expand Up @@ -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: %{},
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Expand Up @@ -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(),
Expand Down
31 changes: 22 additions & 9 deletions 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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 658cd44

Please sign in to comment.