This repository has been archived by the owner on May 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
technical_test.exs
87 lines (74 loc) · 2.39 KB
/
technical_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
defmodule SmartCity.Dataset.TechnicalTest do
use ExUnit.Case
import Checkov
alias SmartCity.Dataset.Technical
setup do
message = %{
"dataName" => "dataset",
"orgName" => "org",
"systemName" => "org__dataset",
"sourceUrl" => "https://example.com",
"sourceType" => "batch",
"cadence" => 30_000,
"sourceFormat" => "gtfs",
"sourceHeaders" => %{
"foo" => "bar"
},
"authHeaders" => %{
"afoo" => "abar"
},
"transformations" => [%{"foo" => %{"bar" => 1}}],
"validations" => [1, 2, 3]
}
{:ok, message: message}
end
describe "new/1" do
test "returns Technical struct" do
actual =
Technical.new(%{
dataName: "dataset",
orgName: "org",
systemName: "org__dataset",
sourceUrl: "https://example.com",
sourceFormat: "gtfs"
})
assert actual.dataName == "dataset"
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
actual = Technical.new(tech)
assert actual.systemName == "org__dataset"
assert actual.sourceQueryParams == %{}
assert actual.cadence == 30_000
assert actual.sourceType == "batch"
end
test "converts deeply nested string keys to atoms", %{message: tech} do
actual = Technical.new(tech)
assert actual.sourceHeaders.foo == "bar"
assert actual.authHeaders.afoo == "abar"
assert List.first(actual.transformations).foo.bar == 1
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
describe "struct" do
test "can be encoded to JSON", %{message: message} do
json = Jason.encode!(message)
assert is_binary(json)
end
end
end