@@ -29,6 +29,22 @@ defmodule AdService.Query.ForDisplayTest do
29
29
topic_categories: [ "Development" ]
30
30
} )
31
31
32
+ property =
33
+ insert ( :property , % {
34
+ programming_languages: [ "Ruby" , "C" ] ,
35
+ topic_categories: [ "Programming" ]
36
+ } )
37
+
38
+ insert ( :property , % {
39
+ programming_languages: [ "Ruby" , "C" ] ,
40
+ topic_categories: [ "Development" ]
41
+ } )
42
+
43
+ insert ( :property , % {
44
+ programming_languages: [ "Ruby" , "Rust" ] ,
45
+ topic_categories: [ "Programming" ]
46
+ } )
47
+
32
48
campaign =
33
49
insert (
34
50
:campaign ,
@@ -40,6 +56,10 @@ defmodule AdService.Query.ForDisplayTest do
40
56
end_date: Timex . now ( ) |> Timex . shift ( days: 1 ) |> DateTime . to_naive ( ) ,
41
57
creative: creative ,
42
58
audience: audience ,
59
+ included_programming_languages: [ "Ruby" ] ,
60
+ included_topic_categories: [ "Programming" ] ,
61
+ excluded_programming_languages: [ "Rust" ] ,
62
+ excluded_topic_categories: [ "Development" ] ,
43
63
included_countries: [ "US" ] ,
44
64
user: insert ( :user , company: "Acme" )
45
65
)
@@ -54,6 +74,10 @@ defmodule AdService.Query.ForDisplayTest do
54
74
end_date: Timex . now ( ) |> Timex . shift ( days: - 1 ) |> DateTime . to_naive ( ) ,
55
75
creative: creative ,
56
76
audience: audience ,
77
+ included_programming_languages: [ "Rust" ] ,
78
+ included_topic_categories: [ "Development" ] ,
79
+ excluded_programming_languages: [ "Ruby" ] ,
80
+ excluded_topic_categories: [ "Programming" ] ,
57
81
included_countries: [ "US" ]
58
82
)
59
83
@@ -66,6 +90,10 @@ defmodule AdService.Query.ForDisplayTest do
66
90
end_date: Timex . now ( ) |> Timex . shift ( days: 1 ) |> DateTime . to_naive ( ) ,
67
91
total_spend: Decimal . new ( 100 ) ,
68
92
creative: creative ,
93
+ included_programming_languages: [ "Rust" ] ,
94
+ included_topic_categories: [ "Development" ] ,
95
+ excluded_programming_languages: [ "Ruby" ] ,
96
+ excluded_topic_categories: [ "Programming" ] ,
69
97
included_countries: [ "IN" ] ,
70
98
audience: insert ( :audience , % { programming_languages: [ "Java" , "Rust" ] } )
71
99
)
@@ -80,12 +108,23 @@ defmodule AdService.Query.ForDisplayTest do
80
108
end_date: Timex . now ( ) |> Timex . shift ( days: 1 ) |> DateTime . to_naive ( ) ,
81
109
creative: creative ,
82
110
audience: audience ,
111
+ included_programming_languages: [ "Rust" ] ,
112
+ included_topic_categories: [ "Development" ] ,
113
+ excluded_programming_languages: [ "Ruby" ] ,
114
+ excluded_topic_categories: [ "Programming" ] ,
83
115
included_countries: [ "CN" ]
84
116
)
85
117
86
118
[ cdn_host: cdn_host ] = Application . get_env ( :code_fund , Framework.FileStorage )
87
119
88
- { :ok , % { audience: audience , creative: creative , campaign: campaign , cdn_host: cdn_host } }
120
+ { :ok ,
121
+ % {
122
+ audience: audience ,
123
+ creative: creative ,
124
+ campaign: campaign ,
125
+ cdn_host: cdn_host ,
126
+ property: property
127
+ } }
89
128
end
90
129
91
130
describe "fallback_ad_by_property_id/1" do
@@ -122,13 +161,13 @@ defmodule AdService.Query.ForDisplayTest do
122
161
end
123
162
124
163
describe "build/1" do
125
- test "get_by_property_filters excludes indicated countries" , % { audience: audience } do
126
- refute AdService.Query.ForDisplay . build ( audience , "CN" , nil , [ "Foobar" ] )
164
+ test "get_by_property_filters excludes indicated countries" , % { property: property } do
165
+ refute AdService.Query.ForDisplay . build ( property , "CN" , nil , [ "Foobar" ] )
127
166
|> CodeFund.Repo . one ( )
128
167
end
129
168
130
169
test "it returns advertisements by audience, included country and excluded advertisers" , % {
131
- audience: audience ,
170
+ property: property ,
132
171
campaign: campaign ,
133
172
creative: creative
134
173
} do
@@ -141,13 +180,16 @@ defmodule AdService.Query.ForDisplayTest do
141
180
start_date: Timex . now ( ) |> Timex . shift ( days: - 1 ) |> DateTime . to_naive ( ) ,
142
181
end_date: Timex . now ( ) |> Timex . shift ( days: 1 ) |> DateTime . to_naive ( ) ,
143
182
creative: creative ,
144
- audience: audience ,
183
+ included_programming_languages: [ "Ruby" ] ,
184
+ included_topic_categories: [ "Programming" ] ,
185
+ excluded_programming_languages: [ "Rust" ] ,
186
+ excluded_topic_categories: [ "Development" ] ,
145
187
included_countries: [ "US" ] ,
146
188
user: insert ( :user , company: "Foobar" )
147
189
)
148
190
149
191
advertisement =
150
- AdService.Query.ForDisplay . build ( audience , "US" , nil , [ "Foobar" ] )
192
+ AdService.Query.ForDisplay . build ( property , "US" , nil , [ "Foobar" ] )
151
193
|> CodeFund.Repo . one ( )
152
194
153
195
small_image_asset = CodeFund.Schema.Asset |> Repo . get! ( creative . small_image_asset . id )
@@ -178,7 +220,7 @@ defmodule AdService.Query.ForDisplayTest do
178
220
end
179
221
180
222
test "it excludes campaigns which are not allowed on the weekends when its a weekend" , % {
181
- audience: audience ,
223
+ property: property ,
182
224
creative: creative
183
225
} do
184
226
CodeFund.Schema.Campaign
@@ -195,22 +237,25 @@ defmodule AdService.Query.ForDisplayTest do
195
237
end_date: Timex . now ( ) |> Timex . shift ( days: 1 ) |> DateTime . to_naive ( ) ,
196
238
creative: creative ,
197
239
weekdays_only: true ,
198
- audience: audience ,
240
+ included_programming_languages: [ "Ruby" ] ,
241
+ included_topic_categories: [ "Programming" ] ,
242
+ excluded_programming_languages: [ "Rust" ] ,
243
+ excluded_topic_categories: [ "Development" ] ,
199
244
included_countries: [ "US" ] ,
200
245
user: insert ( :user , company: "Acme" )
201
246
)
202
247
203
248
TimeMachinex.ManagedClock . set ( DateTime . from_naive! ( ~N[ 2018-09-22 11:00:00] , "Etc/UTC" ) )
204
249
205
250
advertisement =
206
- AdService.Query.ForDisplay . build ( audience , "US" , { 72 , 229 , 28 , 185 } , [ "Foobar" ] )
251
+ AdService.Query.ForDisplay . build ( property , "US" , { 72 , 229 , 28 , 185 } , [ "Foobar" ] )
207
252
|> CodeFund.Repo . one ( )
208
253
209
254
refute advertisement
210
255
end
211
256
212
257
test "it will exclude campaigns that are over their daily budget" , % {
213
- audience: audience ,
258
+ property: property ,
214
259
creative: creative
215
260
} do
216
261
CodeFund.Schema.Campaign
@@ -227,15 +272,18 @@ defmodule AdService.Query.ForDisplayTest do
227
272
start_date: Timex . now ( ) |> Timex . shift ( days: - 1 ) |> DateTime . to_naive ( ) ,
228
273
end_date: Timex . now ( ) |> Timex . shift ( days: 1 ) |> DateTime . to_naive ( ) ,
229
274
creative: creative ,
230
- audience: audience ,
275
+ included_programming_languages: [ "Ruby" ] ,
276
+ included_topic_categories: [ "Programming" ] ,
277
+ excluded_programming_languages: [ "Rust" ] ,
278
+ excluded_topic_categories: [ "Development" ] ,
231
279
included_countries: [ "US" ] ,
232
280
user: insert ( :user , company: "Acme" )
233
281
)
234
282
235
283
insert ( :impression , campaign: campaign , revenue_amount: Decimal . new ( 9.5 ) )
236
284
237
285
advertisement =
238
- AdService.Query.ForDisplay . build ( audience , "US" , nil , [ "Foobar" ] ) |> CodeFund.Repo . one ( )
286
+ AdService.Query.ForDisplay . build ( property , "US" , nil , [ "Foobar" ] ) |> CodeFund.Repo . one ( )
239
287
240
288
refute advertisement
241
289
end
0 commit comments