-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatch_phrase_query_test.go
138 lines (113 loc) · 3.53 KB
/
match_phrase_query_test.go
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package es_test
import (
"testing"
ZeroTermsQuery "github.com/Trendyol/es-query-builder/es/enums/zero-terms-query"
"github.com/Trendyol/es-query-builder/es"
"github.com/Trendyol/es-query-builder/test/assert"
)
//// Match Phrase ////
func Test_MatchPhrase_should_exist_on_es_package(t *testing.T) {
t.Parallel()
// Given When Then
assert.NotNil(t, es.MatchPhrase[any])
}
func Test_MatchPhrase_method_should_create_matchPhraseType(t *testing.T) {
t.Parallel()
// Given
b := es.MatchPhrase("key", "value")
// Then
assert.NotNil(t, b)
assert.IsTypeString(t, "es.matchPhraseType", b)
}
func Test_MatchPhrase_should_have_Analyzer_method(t *testing.T) {
t.Parallel()
// Given
match := es.MatchPhrase("key", "value")
// When Then
assert.NotNil(t, match.Analyzer)
}
func Test_MatchPhrase_Analyzer_should_create_json_with_analyzer_field_inside_match_phrase(t *testing.T) {
t.Parallel()
// Given
query := es.NewQuery(
es.MatchPhrase("type", "Folder").
Analyzer("standart"),
)
// When Then
assert.NotNil(t, query)
bodyJSON := assert.MarshalWithoutError(t, query)
assert.Equal(t, "{\"query\":{\"match_phrase\":{\"type\":{\"analyzer\":\"standart\",\"query\":\"Folder\"}}}}", bodyJSON)
}
func Test_MatchPhrase_should_have_Boost_method(t *testing.T) {
t.Parallel()
// Given
match := es.MatchPhrase("key", "value")
// When Then
assert.NotNil(t, match.Boost)
}
func Test_MatchPhrase_Boost_should_create_json_with_boost_field_inside_match_phrase(t *testing.T) {
t.Parallel()
// Given
query := es.NewQuery(
es.MatchPhrase("type", "Folder").
Boost(3.14),
)
// When Then
assert.NotNil(t, query)
bodyJSON := assert.MarshalWithoutError(t, query)
assert.Equal(t, "{\"query\":{\"match_phrase\":{\"type\":{\"boost\":3.14,\"query\":\"Folder\"}}}}", bodyJSON)
}
func Test_MatchPhrase_should_have_Slop_method(t *testing.T) {
t.Parallel()
// Given
match := es.MatchPhrase("key", "value")
// When Then
assert.NotNil(t, match.Slop)
}
func Test_MatchPhrase_Slop_should_create_json_with_slop_field_inside_match_phrase(t *testing.T) {
t.Parallel()
// Given
query := es.NewQuery(
es.MatchPhrase("type", "Folder").
Slop(3),
)
// When Then
assert.NotNil(t, query)
bodyJSON := assert.MarshalWithoutError(t, query)
assert.Equal(t, "{\"query\":{\"match_phrase\":{\"type\":{\"query\":\"Folder\",\"slop\":3}}}}", bodyJSON)
}
func Test_MatchPhrase_should_have_ZeroTermsQuery_method(t *testing.T) {
t.Parallel()
// Given
match := es.MatchPhrase("key", "value")
// When Then
assert.NotNil(t, match.ZeroTermsQuery)
}
func Test_MatchPhrase_ZeroTermsQuery_should_create_json_with_zero_terms_query_field_inside_match_phrase(t *testing.T) {
t.Parallel()
// Given
query := es.NewQuery(
es.MatchPhrase("type", "Folder").
ZeroTermsQuery(ZeroTermsQuery.All),
)
// When Then
assert.NotNil(t, query)
bodyJSON := assert.MarshalWithoutError(t, query)
assert.Equal(t, "{\"query\":{\"match_phrase\":{\"type\":{\"query\":\"Folder\",\"zero_terms_query\":\"all\"}}}}", bodyJSON)
}
func Test_MatchPhrase_should_create_json_with_match_phrase_field_inside_query(t *testing.T) {
t.Parallel()
// Given
query := es.NewQuery(
es.MatchPhrase("message", "this is a test").
Analyzer("standart").
Boost(2.14).
Slop(9).
ZeroTermsQuery(ZeroTermsQuery.None),
)
// When Then
assert.NotNil(t, query)
bodyJSON := assert.MarshalWithoutError(t, query)
// nolint:golint,lll
assert.Equal(t, "{\"query\":{\"match_phrase\":{\"message\":{\"analyzer\":\"standart\",\"boost\":2.14,\"query\":\"this is a test\",\"slop\":9,\"zero_terms_query\":\"none\"}}}}", bodyJSON)
}