Fix more tests.

This commit is contained in:
2019-01-22 11:16:04 +01:00
parent 8e0563b463
commit 0e32e8fa9c
8 changed files with 196 additions and 874 deletions

View File

@@ -127,6 +127,7 @@ impl Probe for Hitta {
#[cfg(test)]
mod tests {
use chrono::DateTime;
use pretty_assertions::assert_eq;
use super::*;
@@ -138,7 +139,153 @@ mod tests {
let expected = Entry {
messages: vec![],
history: vec!["42 andra har rapporterat detta nummer".to_string()],
comments: vec![],
comments: vec![
probe::Comment {
datetime: "2019-01-17T17:29:22Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Varmsälj från Folksam".to_string(),
},
probe::Comment {
datetime: "2018-12-14T13:45:28Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Folksam".to_string(),
},
probe::Comment {
datetime: "2018-11-28T07:30:18Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Höglandschskt".to_string(),
},
probe::Comment {
datetime: "2018-11-20T19:18:09Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Försäljare ".to_string(),
},
probe::Comment {
datetime: "2018-11-19T17:38:34Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "mögg från Folksam".to_string(),
},
probe::Comment {
datetime: "2018-11-12T16:00:41Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Folksam försäkringsförsäljare".to_string(),
},
probe::Comment {
datetime: "2018-10-25T10:28:36Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "folksam".to_string(),
},
probe::Comment {
datetime: "2018-10-10T07:30:40Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Telefonförsäljare".to_string(),
},
probe::Comment {
datetime: "2018-10-04T10:04:55Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Folksam säljare".to_string(),
},
probe::Comment {
datetime: "2018-10-03T13:55:19Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Sa inget.".to_string(),
},
probe::Comment {
datetime: "2018-08-24T16:56:46Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Folksam".to_string(),
},
probe::Comment {
datetime: "2018-08-24T09:42:43Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Achmati azmut från folksam".to_string(),
},
probe::Comment {
datetime: "2018-08-21T18:29:29Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Folksam".to_string(),
},
probe::Comment {
datetime: "2018-08-16T18:56:56Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Säljare från Folksam.".to_string(),
},
probe::Comment {
datetime: "2018-08-16T14:48:59Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Folksam ".to_string(),
},
probe::Comment {
datetime: "2018-08-09T16:30:28Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Folksam".to_string(),
},
probe::Comment {
datetime: "2018-08-02T16:29:32Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Folksam ".to_string(),
},
probe::Comment {
datetime: "2018-08-02T15:33:38Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Folksam ".to_string(),
},
probe::Comment {
datetime: "2018-07-25T08:28:27Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Säljare Folksam".to_string(),
},
probe::Comment {
datetime: "2018-07-17T21:20:51Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Inga Hansson ".to_string(),
},
probe::Comment {
datetime: "2018-07-16T18:11:46Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Folksam".to_string(),
},
probe::Comment {
datetime: "2018-07-06T15:45:46Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Folksam ".to_string(),
},
probe::Comment {
datetime: "2018-07-05T17:24:07Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "folksam".to_string(),
},
probe::Comment {
datetime: "2018-07-05T11:15:02Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Vesran".to_string(),
},
probe::Comment {
datetime: "2018-07-04T13:30:49Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Folksam".to_string(),
},
probe::Comment {
datetime: "2018-06-29T10:52:51Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "folksam".to_string(),
},
probe::Comment {
datetime: "2018-06-28T13:33:01Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Säljare folksam".to_string(),
},
probe::Comment {
datetime: "2018-06-28T07:42:42Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Folksam försäkringar".to_string(),
},
probe::Comment {
datetime: "2018-06-26T12:59:33Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Säljare Folksam".to_string(),
},
],
};
assert_eq!(from_html(&document), Ok(expected));

View File

@@ -127,9 +127,40 @@ mod tests {
let document = include_str!("../../fixtures/telefonforsaljare/0104754350.html");
let expected = Entry {
messages: vec![],
history: vec![],
comments: vec![],
messages: vec!["Folksam".to_string()],
history: vec!["De senaste 24 timmarna har <strong>9 personer</strong> sökt efter numret 0104754350. Det kan tyda på att numret används av telefonförsäljare. Totalt har minst <strong>4786 personer</strong> sökt efter numret.".to_string()],
comments: vec![
Comment {
datetime: "2018-05-09T12:31:39Z".parse::<DateTime<Utc>>().unwrap(),
title: "Folksam".to_string(),
message: "Svara inte på okända nummer. Blockerat!".to_string(),
},
Comment {
datetime: "2017-12-05T16:33:10Z".parse::<DateTime<Utc>>().unwrap(),
title: "Folksam".to_string(),
message: "Svarade aldrig men när jag ringde upp var det Folksam".to_string(),
},
Comment {
datetime: "2017-11-28T10:30:10Z".parse::<DateTime<Utc>>().unwrap(),
title: "".to_string(),
message: "Ringde och la på".to_string(),
},
Comment {
datetime: "2017-11-20T14:53:16Z".parse::<DateTime<Utc>>().unwrap(),
title: "Folksam".to_string(),
message: "färsäljare".to_string(),
},
Comment {
datetime: "2017-11-16T12:38:07Z".parse::<DateTime<Utc>>().unwrap(),
title: "Folksam".to_string(),
message: "missat samtal, ringde tillbaka och automatsvar sa att det var folksam som sökt mig för att presentera ett erbjudande.".to_string(),
},
Comment {
datetime: "2017-10-25T05:59:26Z".parse::<DateTime<Utc>>().unwrap(),
title: "Folksam".to_string(),
message: "Försäljare".to_string(),
},
],
};
assert_eq!(from_html(&document), Ok(expected));
@@ -157,7 +188,7 @@ mod tests {
history: vec!["De senaste 24 timmarna har <strong>3 personer</strong> sökt efter numret 0702269893. Det kan tyda på att numret används av telefonförsäljare. Totalt har minst <strong>4 personer</strong> sökt efter numret.".to_string()],
comments: vec![
Comment {
datetime: stockholm_to_utc("2019-01-18 14:30:55", "%Y-%m-%d %H:%M:%S").unwrap(),
datetime: "2019-01-18T13:30:55Z".parse::<DateTime<Utc>>().unwrap(),
title: "Alnö Design & Produktion AB".to_string(),
message: "Renhållning, service, kemprodukter".to_string(),
}
@@ -172,9 +203,15 @@ mod tests {
let document = include_str!("../../fixtures/telefonforsaljare/0726443387.html");
let expected = Entry {
messages: vec![],
history: vec![],
comments: vec![],
messages: vec!["Tele2".to_string()],
history: vec!["De senaste 24 timmarna har <strong>1 personer</strong> sökt efter numret 0726443387. Det kan tyda på att numret används av telefonförsäljare. Totalt har minst <strong>231 personer</strong> sökt efter numret.".to_string()],
comments: vec![
Comment {
datetime: "2018-10-31T17:48:27Z".parse::<DateTime<Utc>>().unwrap(),
title: "Tele2".to_string(),
message: "Bättre priser som inte finns online".to_string(),
},
],
};
assert_eq!(from_html(&document), Ok(expected));

View File

@@ -1,10 +1,10 @@
use log::debug;
use scraper::{Html, Selector};
// use log::debug;
// use scraper::{Html, Selector};
use crate::context::Context;
use crate::probe::{Comment, Entry, Probe};
use crate::probe::{Entry, Probe};
fn from_html(document: &str) -> Result<Entry, ()> {
fn from_html(_document: &str) -> Result<Entry, ()> {
/*
let html = Html::parse_document(document);