use super::{BonusTrack, PushContext, Reward, Tier};
pub struct BigPush;
const BIG_PUSH_COMMIT_COUNT: usize = 10;
static TIERS: &[Tier] = &[
Tier {
cost: 50,
reward: Reward::FlatPoints(10),
},
Tier {
cost: 500,
reward: Reward::FlatPoints(20),
},
Tier {
cost: 3000,
reward: Reward::FlatPoints(50),
},
Tier {
cost: 20000,
reward: Reward::FlatPoints(100),
},
Tier {
cost: 120000,
reward: Reward::FlatPoints(200),
},
];
impl BonusTrack for BigPush {
fn id(&self) -> &'static str {
"big_push"
}
fn name(&self) -> &'static str {
"Big Push"
}
fn description(&self) -> &'static str {
"More points for pushing 10+ commits at once."
}
fn tiers(&self) -> &'static [Tier] {
TIERS
}
fn applies(&self, ctx: &PushContext) -> u32 {
if ctx.push.commits().len() >= BIG_PUSH_COMMIT_COUNT {
1
} else {
0
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{
bonus_track::Clock,
git::{Commit, Push},
storage::{DbConnection, PushHistory},
};
#[test]
fn applies_to_big_pushes() {
let conn = DbConnection::create_in_memory().unwrap();
let bonus = BigPush;
let history = PushHistory::new(&conn);
let clock = Clock::default();
let push = Push::new(vec![Commit::default(); BIG_PUSH_COMMIT_COUNT]);
let ctx = PushContext {
push: &push,
history: &history,
clock: &clock,
};
assert_eq!(bonus.applies(&ctx), 1);
let push = Push::new(vec![Commit::default(); 1_000]);
let ctx = PushContext {
push: &push,
history: &history,
clock: &clock,
};
assert_eq!(bonus.applies(&ctx), 1);
}
#[test]
fn does_not_apply_to_small_pushes() {
let conn = DbConnection::create_in_memory().unwrap();
let bonus = BigPush;
let history = PushHistory::new(&conn);
let clock = Clock::default();
let push = Push::new(vec![Commit::default(); BIG_PUSH_COMMIT_COUNT - 1]);
let ctx = PushContext {
push: &push,
history: &history,
clock: &clock,
};
assert_eq!(bonus.applies(&ctx), 0);
let push = Push::new(vec![Commit::default(); 1]);
let ctx = PushContext {
push: &push,
history: &history,
clock: &clock,
};
assert_eq!(bonus.applies(&ctx), 0);
}
}