66use std:: sync:: Arc ;
77
88use ads_client:: {
9- MozAdsClientBuilder , MozAdsEnvironment , MozAdsPlacementRequest , MozAdsPlacementRequestWithCount ,
9+ MozAdsClientBuilder , MozAdsEnvironment , MozAdsPlacementRequest ,
10+ MozAdsPlacementRequestWithCount , MozAdsReportReason ,
1011} ;
1112
1213fn init_backend ( ) {
1314 // Err means the backend is already initialized.
1415 let _ = viaduct_hyper:: viaduct_init_backend_hyper ( ) ;
1516}
1617
17- fn staging_client ( ) -> ads_client:: MozAdsClient {
18+ fn prod_client ( ) -> ads_client:: MozAdsClient {
1819 Arc :: new ( MozAdsClientBuilder :: new ( ) )
19- . environment ( MozAdsEnvironment :: Staging )
20+ . environment ( MozAdsEnvironment :: Prod )
2021 . build ( )
2122}
2223
2324#[ test]
2425#[ ignore = "integration test: run manually with -- --ignored" ]
25- fn test_contract_image_staging ( ) {
26+ fn test_contract_image_prod ( ) {
2627 init_backend ( ) ;
2728
28- let client = staging_client ( ) ;
29+ let client = prod_client ( ) ;
2930 let result = client. request_image_ads (
3031 vec ! [ MozAdsPlacementRequest {
3132 placement_id: "mock_billboard_1" . to_string( ) ,
@@ -45,10 +46,10 @@ fn test_contract_image_staging() {
4546
4647#[ test]
4748#[ ignore = "integration test: run manually with -- --ignored" ]
48- fn test_contract_spoc_staging ( ) {
49+ fn test_contract_spoc_prod ( ) {
4950 init_backend ( ) ;
5051
51- let client = staging_client ( ) ;
52+ let client = prod_client ( ) ;
5253 let result = client. request_spoc_ads (
5354 vec ! [ MozAdsPlacementRequestWithCount {
5455 placement_id: "mock_spoc_1" . to_string( ) ,
@@ -66,10 +67,10 @@ fn test_contract_spoc_staging() {
6667
6768#[ test]
6869#[ ignore = "integration test: run manually with -- --ignored" ]
69- fn test_contract_tile_staging ( ) {
70+ fn test_contract_tile_prod ( ) {
7071 init_backend ( ) ;
7172
72- let client = staging_client ( ) ;
73+ let client = prod_client ( ) ;
7374 let result = client. request_tile_ads (
7475 vec ! [ MozAdsPlacementRequest {
7576 placement_id: "mock_tile_1" . to_string( ) ,
@@ -82,3 +83,81 @@ fn test_contract_tile_staging() {
8283 let placements = result. unwrap ( ) ;
8384 assert ! ( placements. contains_key( "mock_tile_1" ) ) ;
8485}
86+
87+ #[ test]
88+ #[ ignore = "integration test: run manually with -- --ignored" ]
89+ fn test_record_impression ( ) {
90+ init_backend ( ) ;
91+
92+ let client = prod_client ( ) ;
93+ let placements = client
94+ . request_tile_ads (
95+ vec ! [ MozAdsPlacementRequest {
96+ placement_id: "mock_tile_1" . to_string( ) ,
97+ iab_content: None ,
98+ } ] ,
99+ None ,
100+ )
101+ . expect ( "tile ad request should succeed" ) ;
102+
103+ let ad = placements
104+ . get ( "mock_tile_1" )
105+ . expect ( "mock_tile_1 placement should be present" ) ;
106+
107+ let result = client. record_impression ( ad. callbacks . impression . to_string ( ) ) ;
108+ assert ! ( result. is_ok( ) , "record_impression failed: {:?}" , result. err( ) ) ;
109+ }
110+
111+ #[ test]
112+ #[ ignore = "integration test: run manually with -- --ignored" ]
113+ fn test_record_click ( ) {
114+ init_backend ( ) ;
115+
116+ let client = prod_client ( ) ;
117+ let placements = client
118+ . request_tile_ads (
119+ vec ! [ MozAdsPlacementRequest {
120+ placement_id: "mock_tile_1" . to_string( ) ,
121+ iab_content: None ,
122+ } ] ,
123+ None ,
124+ )
125+ . expect ( "tile ad request should succeed" ) ;
126+
127+ let ad = placements
128+ . get ( "mock_tile_1" )
129+ . expect ( "mock_tile_1 placement should be present" ) ;
130+
131+ let result = client. record_click ( ad. callbacks . click . to_string ( ) ) ;
132+ assert ! ( result. is_ok( ) , "record_click failed: {:?}" , result. err( ) ) ;
133+ }
134+
135+ #[ test]
136+ #[ ignore = "integration test: run manually with -- --ignored" ]
137+ fn test_report_ad ( ) {
138+ init_backend ( ) ;
139+
140+ let client = prod_client ( ) ;
141+ let placements = client
142+ . request_tile_ads (
143+ vec ! [ MozAdsPlacementRequest {
144+ placement_id: "mock_tile_1" . to_string( ) ,
145+ iab_content: None ,
146+ } ] ,
147+ None ,
148+ )
149+ . expect ( "tile ad request should succeed" ) ;
150+
151+ let ad = placements
152+ . get ( "mock_tile_1" )
153+ . expect ( "mock_tile_1 placement should be present" ) ;
154+
155+ let report_url = ad
156+ . callbacks
157+ . report
158+ . as_ref ( )
159+ . expect ( "mock_tile_1 should have a report URL" ) ;
160+
161+ let result = client. report_ad ( report_url. to_string ( ) , MozAdsReportReason :: NotInterested ) ;
162+ assert ! ( result. is_ok( ) , "report_ad failed: {:?}" , result. err( ) ) ;
163+ }
0 commit comments