-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
102 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
defmodule ElasticsearchEx.DocumentTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias ElasticsearchEx.Document | ||
|
||
describe "new/1 with a map" do | ||
test "returns a struct with a map of atoms as key" do | ||
attrs = %{ | ||
_id: "rvO6H4wBhbFpuyekVIiV", | ||
_index: "residents-v20240223013056", | ||
_primary_term: 1, | ||
_score: 1.0, | ||
_seq_no: 26776, | ||
_source: %{"hello" => "world"}, | ||
_version: 1 | ||
} | ||
|
||
assert %Document{ | ||
_id: "rvO6H4wBhbFpuyekVIiV", | ||
_index: "residents-v20240223013056", | ||
_primary_term: 1, | ||
_score: 1.0, | ||
_seq_no: 26776, | ||
_source: %{"hello" => "world"}, | ||
_version: 1 | ||
} = Document.new(attrs) | ||
end | ||
|
||
test "returns a struct with a map of atoms as binary" do | ||
attrs = %{ | ||
"_id" => "rvO6H4wBhbFpuyekVIiV", | ||
"_index" => "residents-v20240223013056", | ||
"_primary_term" => 1, | ||
"_score" => 1.0, | ||
"_seq_no" => 26776, | ||
"_source" => %{"hello" => "world"}, | ||
"_version" => 1 | ||
} | ||
|
||
assert %Document{ | ||
_id: "rvO6H4wBhbFpuyekVIiV", | ||
_index: "residents-v20240223013056", | ||
_primary_term: 1, | ||
_score: 1.0, | ||
_seq_no: 26776, | ||
_source: %{"hello" => "world"}, | ||
_version: 1 | ||
} = Document.new(attrs) | ||
end | ||
|
||
test "returns a struct with a map of mixed key" do | ||
attrs = %{ | ||
"_id" => "rvO6H4wBhbFpuyekVIiV", | ||
"_index" => "residents-v20240223013056", | ||
"_primary_term" => 1, | ||
"_score" => 1.0, | ||
_seq_no: 26776, | ||
_source: %{"hello" => "world"}, | ||
_version: 1 | ||
} | ||
|
||
assert %Document{ | ||
_id: "rvO6H4wBhbFpuyekVIiV", | ||
_index: "residents-v20240223013056", | ||
_primary_term: 1, | ||
_score: 1.0, | ||
_seq_no: 26776, | ||
_source: %{"hello" => "world"}, | ||
_version: 1 | ||
} = Document.new(attrs) | ||
end | ||
|
||
test "returns a struct with _source as map of atoms as key" do | ||
attrs = %{_source: %{hello: "world"}} | ||
|
||
assert %Document{_source: %{hello: "world"}} = Document.new(attrs) | ||
end | ||
|
||
test "returns a struct with _source as map of atoms as binary" do | ||
attrs = %{_source: %{"hello" => "world"}} | ||
|
||
assert %Document{_source: %{"hello" => "world"}} = Document.new(attrs) | ||
end | ||
end | ||
end |