@@ -29,6 +29,22 @@ defmodule AdService.Query.ForDisplayTest do
2929 topic_categories: [ "Development" ]
3030 } )
3131
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+
3248 campaign =
3349 insert (
3450 :campaign ,
@@ -40,6 +56,10 @@ defmodule AdService.Query.ForDisplayTest do
4056 end_date: Timex . now ( ) |> Timex . shift ( days: 1 ) |> DateTime . to_naive ( ) ,
4157 creative: creative ,
4258 audience: audience ,
59+ included_programming_languages: [ "Ruby" ] ,
60+ included_topic_categories: [ "Programming" ] ,
61+ excluded_programming_languages: [ "Rust" ] ,
62+ excluded_topic_categories: [ "Development" ] ,
4363 included_countries: [ "US" ] ,
4464 user: insert ( :user , company: "Acme" )
4565 )
@@ -54,6 +74,10 @@ defmodule AdService.Query.ForDisplayTest do
5474 end_date: Timex . now ( ) |> Timex . shift ( days: - 1 ) |> DateTime . to_naive ( ) ,
5575 creative: creative ,
5676 audience: audience ,
77+ included_programming_languages: [ "Rust" ] ,
78+ included_topic_categories: [ "Development" ] ,
79+ excluded_programming_languages: [ "Ruby" ] ,
80+ excluded_topic_categories: [ "Programming" ] ,
5781 included_countries: [ "US" ]
5882 )
5983
@@ -66,6 +90,10 @@ defmodule AdService.Query.ForDisplayTest do
6690 end_date: Timex . now ( ) |> Timex . shift ( days: 1 ) |> DateTime . to_naive ( ) ,
6791 total_spend: Decimal . new ( 100 ) ,
6892 creative: creative ,
93+ included_programming_languages: [ "Rust" ] ,
94+ included_topic_categories: [ "Development" ] ,
95+ excluded_programming_languages: [ "Ruby" ] ,
96+ excluded_topic_categories: [ "Programming" ] ,
6997 included_countries: [ "IN" ] ,
7098 audience: insert ( :audience , % { programming_languages: [ "Java" , "Rust" ] } )
7199 )
@@ -80,12 +108,23 @@ defmodule AdService.Query.ForDisplayTest do
80108 end_date: Timex . now ( ) |> Timex . shift ( days: 1 ) |> DateTime . to_naive ( ) ,
81109 creative: creative ,
82110 audience: audience ,
111+ included_programming_languages: [ "Rust" ] ,
112+ included_topic_categories: [ "Development" ] ,
113+ excluded_programming_languages: [ "Ruby" ] ,
114+ excluded_topic_categories: [ "Programming" ] ,
83115 included_countries: [ "CN" ]
84116 )
85117
86118 [ cdn_host: cdn_host ] = Application . get_env ( :code_fund , Framework.FileStorage )
87119
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+ } }
89128 end
90129
91130 describe "fallback_ad_by_property_id/1" do
@@ -122,13 +161,13 @@ defmodule AdService.Query.ForDisplayTest do
122161 end
123162
124163 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" ] )
127166 |> CodeFund.Repo . one ( )
128167 end
129168
130169 test "it returns advertisements by audience, included country and excluded advertisers" , % {
131- audience: audience ,
170+ property: property ,
132171 campaign: campaign ,
133172 creative: creative
134173 } do
@@ -141,13 +180,16 @@ defmodule AdService.Query.ForDisplayTest do
141180 start_date: Timex . now ( ) |> Timex . shift ( days: - 1 ) |> DateTime . to_naive ( ) ,
142181 end_date: Timex . now ( ) |> Timex . shift ( days: 1 ) |> DateTime . to_naive ( ) ,
143182 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" ] ,
145187 included_countries: [ "US" ] ,
146188 user: insert ( :user , company: "Foobar" )
147189 )
148190
149191 advertisement =
150- AdService.Query.ForDisplay . build ( audience , "US" , nil , [ "Foobar" ] )
192+ AdService.Query.ForDisplay . build ( property , "US" , nil , [ "Foobar" ] )
151193 |> CodeFund.Repo . one ( )
152194
153195 small_image_asset = CodeFund.Schema.Asset |> Repo . get! ( creative . small_image_asset . id )
@@ -178,7 +220,7 @@ defmodule AdService.Query.ForDisplayTest do
178220 end
179221
180222 test "it excludes campaigns which are not allowed on the weekends when its a weekend" , % {
181- audience: audience ,
223+ property: property ,
182224 creative: creative
183225 } do
184226 CodeFund.Schema.Campaign
@@ -195,22 +237,25 @@ defmodule AdService.Query.ForDisplayTest do
195237 end_date: Timex . now ( ) |> Timex . shift ( days: 1 ) |> DateTime . to_naive ( ) ,
196238 creative: creative ,
197239 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" ] ,
199244 included_countries: [ "US" ] ,
200245 user: insert ( :user , company: "Acme" )
201246 )
202247
203248 TimeMachinex.ManagedClock . set ( DateTime . from_naive! ( ~N[ 2018-09-22 11:00:00] , "Etc/UTC" ) )
204249
205250 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" ] )
207252 |> CodeFund.Repo . one ( )
208253
209254 refute advertisement
210255 end
211256
212257 test "it will exclude campaigns that are over their daily budget" , % {
213- audience: audience ,
258+ property: property ,
214259 creative: creative
215260 } do
216261 CodeFund.Schema.Campaign
@@ -227,15 +272,18 @@ defmodule AdService.Query.ForDisplayTest do
227272 start_date: Timex . now ( ) |> Timex . shift ( days: - 1 ) |> DateTime . to_naive ( ) ,
228273 end_date: Timex . now ( ) |> Timex . shift ( days: 1 ) |> DateTime . to_naive ( ) ,
229274 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" ] ,
231279 included_countries: [ "US" ] ,
232280 user: insert ( :user , company: "Acme" )
233281 )
234282
235283 insert ( :impression , campaign: campaign , revenue_amount: Decimal . new ( 9.5 ) )
236284
237285 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 ( )
239287
240288 refute advertisement
241289 end
0 commit comments