Skip to content

Commit 2da5c3a

Browse files
committed
add: additional AIP#6 test cases
1 parent 5e2137f commit 2da5c3a

File tree

1 file changed

+102
-1
lines changed

1 file changed

+102
-1
lines changed

sentry/src/payout.rs

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn price_bounds(channel: &Channel, event: &Event) -> (BigNum, BigNum) {
119119
mod tests {
120120
use super::*;
121121
use primitives::channel::{Pricing, PricingBounds};
122-
use primitives::util::tests::prep_db::{AUTH, DUMMY_CHANNEL, IDS};
122+
use primitives::util::tests::prep_db::{DUMMY_CHANNEL, IDS};
123123

124124
#[test]
125125
fn test_plain_events() {
@@ -336,4 +336,105 @@ mod tests {
336336
"fixedAmount (country, pulisher): should choose first fixedAmount rule"
337337
);
338338
}
339+
340+
#[test]
341+
fn test_pick_fixed_amount_rule_over_multiplier_event() {
342+
let mut channel: Channel = DUMMY_CHANNEL.clone();
343+
channel.spec.pricing_bounds = Some(PricingBounds {
344+
click: Some(Pricing {
345+
min: BigNum::from(23),
346+
max: BigNum::from(100),
347+
}),
348+
impression: None,
349+
});
350+
channel.spec.price_multiplication_rules = vec![
351+
PriceMultiplicationRules {
352+
multiplier: Some(1.2),
353+
amount: None,
354+
os_type: Some(vec!["android".to_string()]),
355+
ev_type: Some(vec!["CLICK".to_string()]),
356+
publisher: Some(vec![IDS["publisher"].clone()]),
357+
country: Some(vec!["us".to_string()]),
358+
},
359+
PriceMultiplicationRules {
360+
multiplier: None,
361+
amount: Some(BigNum::from(12)),
362+
os_type: None,
363+
ev_type: Some(vec!["CLICK".to_string()]),
364+
publisher: Some(vec![IDS["publisher"].clone()]),
365+
country: Some(vec!["us".to_string()]),
366+
},
367+
];
368+
369+
let session = Session {
370+
ip: None,
371+
country: Some("us".to_string()),
372+
referrer_header: None,
373+
os: None,
374+
};
375+
376+
let event = Event::Click {
377+
publisher: IDS["publisher"].clone(),
378+
ad_slot: None,
379+
ad_unit: None,
380+
referrer: None,
381+
};
382+
383+
let payout = get_payout(&channel, &event, &session);
384+
assert!(
385+
payout == BigNum::from(12),
386+
"fixedAmount (country, osType, publisher): choose fixedAmount rule over multiplier if present"
387+
);
388+
}
389+
390+
#[test]
391+
fn test_apply_all_mutliplier_rules() {
392+
let mut channel: Channel = DUMMY_CHANNEL.clone();
393+
394+
channel.spec.pricing_bounds = Some(PricingBounds {
395+
click: Some(Pricing {
396+
min: BigNum::from(100),
397+
max: BigNum::from(1000)
398+
}),
399+
impression: None,
400+
});
401+
channel.spec.price_multiplication_rules = vec![
402+
PriceMultiplicationRules {
403+
multiplier: Some(1.2),
404+
amount: None,
405+
os_type: Some(vec!["android".to_string()]),
406+
ev_type: Some(vec!["CLICK".to_string()]),
407+
publisher: Some(vec![IDS["publisher"].clone()]),
408+
country: Some(vec!["us".to_string()]),
409+
},
410+
PriceMultiplicationRules {
411+
multiplier: Some(1.2),
412+
amount: None,
413+
os_type: None,
414+
ev_type: None,
415+
publisher: None,
416+
country: None,
417+
},
418+
];
419+
420+
let session = Session {
421+
ip: None,
422+
country: Some("us".to_string()),
423+
referrer_header: None,
424+
os: None,
425+
};
426+
427+
let event = Event::Click {
428+
publisher: IDS["publisher"].clone(),
429+
ad_slot: None,
430+
ad_unit: None,
431+
referrer: None,
432+
};
433+
434+
let payout = get_payout(&channel, &event, &session);
435+
assert!(
436+
payout == BigNum::from(144),
437+
"fixedAmount (country, osType, publisher): choose fixedAmount rule over multiplier if present"
438+
);
439+
}
339440
}

0 commit comments

Comments
 (0)