Use insta for testing.
This commit is contained in:
@@ -78,8 +78,8 @@ fn main() {
|
||||
let mut ctx = Context::new();
|
||||
|
||||
for probe in &mut probes {
|
||||
if probe.search(&mut ctx, &opt.number).is_ok() {
|
||||
println!();
|
||||
if let Ok(entry) = probe.search(&mut ctx, &opt.number) {
|
||||
print!("{}", entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
src/probe.rs
11
src/probe.rs
@@ -1,6 +1,7 @@
|
||||
use std::fmt;
|
||||
|
||||
use chrono::{DateTime, Local, Utc};
|
||||
use serde::Serialize;
|
||||
|
||||
mod eniro;
|
||||
mod hitta;
|
||||
@@ -8,15 +9,15 @@ mod konsument_info;
|
||||
mod telefonforsaljare;
|
||||
mod vem_ringde;
|
||||
|
||||
use crate::context::Context;
|
||||
|
||||
pub use self::eniro::Eniro;
|
||||
pub use self::hitta::Hitta;
|
||||
pub use self::konsument_info::KonsumentInfo;
|
||||
pub use self::telefonforsaljare::Telefonforsaljare;
|
||||
pub use self::vem_ringde::VemRingde;
|
||||
|
||||
use crate::context::Context;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize)]
|
||||
pub struct Entry {
|
||||
pub messages: Vec<String>,
|
||||
pub history: Vec<String>,
|
||||
@@ -47,7 +48,7 @@ impl fmt::Display for Entry {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Serialize)]
|
||||
pub struct Comment {
|
||||
pub datetime: DateTime<Utc>,
|
||||
pub title: Option<String>,
|
||||
@@ -79,5 +80,5 @@ impl fmt::Display for Comment {
|
||||
|
||||
pub trait Probe {
|
||||
fn uri(&self, _: &str) -> String;
|
||||
fn search(&mut self, _: &mut Context, _: &str) -> Result<(), ()>;
|
||||
fn search(&mut self, _: &mut Context, _: &str) -> Result<Entry, ()>;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ impl Probe for Eniro {
|
||||
format!("https://gulasidorna.eniro.se/hitta:{}", number)
|
||||
}
|
||||
|
||||
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<(), ()> {
|
||||
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<Entry, ()> {
|
||||
let body = if let Some(cache) = ctx.cache_get("eniro", &number) {
|
||||
String::from_utf8(cache.data).unwrap()
|
||||
} else {
|
||||
@@ -60,21 +60,13 @@ impl Probe for Eniro {
|
||||
body
|
||||
};
|
||||
|
||||
match from_html(&body) {
|
||||
Ok(entry) => {
|
||||
println!("eniro.se:");
|
||||
print!("{}", entry);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Err(_) => Err(()),
|
||||
}
|
||||
from_html(&body)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pretty_assertions::assert_eq;
|
||||
use insta::assert_yaml_snapshot_matches;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -82,93 +74,76 @@ mod tests {
|
||||
fn test_0104754350() {
|
||||
let document = include_str!("../../fixtures/eniro/0104754350.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![
|
||||
"Företaget bedriver telefonförsäljning eller marknadsundersökningar"
|
||||
.to_string(),
|
||||
],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages:
|
||||
- Företaget bedriver telefonförsäljning eller marknadsundersökningar
|
||||
history: []
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0313908905() {
|
||||
let document = include_str!("../../fixtures/eniro/0313908905.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec!["3464 denna vecka och 6637 totalt.".to_string()],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history:
|
||||
- 3464 denna vecka och 6637 totalt.
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0702269893() {
|
||||
let document = include_str!("../../fixtures/eniro/0702269893.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec!["Anonym Kund För Refill".to_string()],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages:
|
||||
- Anonym Kund För Refill
|
||||
history: []
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0726443387() {
|
||||
let document = include_str!("../../fixtures/eniro/0726443387.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec!["16 denna vecka och 98 totalt.".to_string()],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history:
|
||||
- 16 denna vecka och 98 totalt.
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0751793426() {
|
||||
let document = include_str!("../../fixtures/eniro/0751793426.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec!["20 denna vecka och 602 totalt.".to_string()],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history:
|
||||
- 20 denna vecka och 602 totalt.
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0751793483() {
|
||||
let document = include_str!("../../fixtures/eniro/0751793483.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec!["29 denna vecka och 900 totalt.".to_string()],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history:
|
||||
- 29 denna vecka och 900 totalt.
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0751793499() {
|
||||
let document = include_str!("../../fixtures/eniro/0751793499.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec!["303 denna vecka och 304 totalt.".to_string()],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history:
|
||||
- 303 denna vecka och 304 totalt.
|
||||
comments: []"###);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ impl Probe for Hitta {
|
||||
format!("https://www.hitta.se/vem-ringde/{}", number)
|
||||
}
|
||||
|
||||
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<(), ()> {
|
||||
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<Entry, ()> {
|
||||
let body = if let Some(cache) = ctx.cache_get("hitta", &number) {
|
||||
String::from_utf8(cache.data).unwrap()
|
||||
} else {
|
||||
@@ -113,22 +113,13 @@ impl Probe for Hitta {
|
||||
body
|
||||
};
|
||||
|
||||
match from_html(&body) {
|
||||
Ok(entry) => {
|
||||
println!("hitta.se:");
|
||||
print!("{}", entry);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Err(_) => Err(()),
|
||||
}
|
||||
from_html(&body)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use chrono::DateTime;
|
||||
use pretty_assertions::assert_eq;
|
||||
use insta::assert_yaml_snapshot_matches;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -136,236 +127,159 @@ mod tests {
|
||||
fn test_0104754350() {
|
||||
let document = include_str!("../../fixtures/hitta/0104754350.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec!["42 andra har rapporterat detta nummer".to_string()],
|
||||
comments: vec![
|
||||
probe::Comment {
|
||||
datetime: "2019-01-17T17:29:22Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Varmsälj från Folksam".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-12-14T13:45:28Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Folksam".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-11-28T07:30:18Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Höglandschskt".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-11-20T19:18:09Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Försäljare ".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-11-19T17:38:34Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "mögg från Folksam".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-11-12T16:00:41Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Folksam försäkringsförsäljare".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-10-25T10:28:36Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "folksam".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-10-10T07:30:40Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Telefonförsäljare".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-10-04T10:04:55Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Folksam säljare".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-10-03T13:55:19Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Sa inget.".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-08-24T16:56:46Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Folksam".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-08-24T09:42:43Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Achmati azmut från folksam".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-08-21T18:29:29Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Folksam".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-08-16T18:56:56Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Säljare från Folksam.".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-08-16T14:48:59Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Folksam ".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-08-09T16:30:28Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Folksam".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-08-02T16:29:32Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Folksam ".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-08-02T15:33:38Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Folksam ".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-07-25T08:28:27Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Säljare Folksam".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-07-17T21:20:51Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Inga Hansson ".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-07-16T18:11:46Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Folksam".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-07-06T15:45:46Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Folksam ".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-07-05T17:24:07Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "folksam".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-07-05T11:15:02Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Vesran".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-07-04T13:30:49Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Folksam".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-06-29T10:52:51Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "folksam".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-06-28T13:33:01Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Säljare folksam".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-06-28T07:42:42Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Folksam försäkringar".to_string(),
|
||||
},
|
||||
probe::Comment {
|
||||
datetime: "2018-06-26T12:59:33Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: None,
|
||||
message: "Säljare Folksam".to_string(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history:
|
||||
- 42 andra har rapporterat detta nummer
|
||||
comments:
|
||||
- datetime: "2019-01-17T17:29:22Z"
|
||||
title: ~
|
||||
message: Varmsälj från Folksam
|
||||
- datetime: "2018-12-14T13:45:28Z"
|
||||
title: ~
|
||||
message: Folksam
|
||||
- datetime: "2018-11-28T07:30:18Z"
|
||||
title: ~
|
||||
message: Höglandschskt
|
||||
- datetime: "2018-11-20T19:18:09Z"
|
||||
title: ~
|
||||
message: "Försäljare "
|
||||
- datetime: "2018-11-19T17:38:34Z"
|
||||
title: ~
|
||||
message: mögg från Folksam
|
||||
- datetime: "2018-11-12T16:00:41Z"
|
||||
title: ~
|
||||
message: Folksam försäkringsförsäljare
|
||||
- datetime: "2018-10-25T10:28:36Z"
|
||||
title: ~
|
||||
message: folksam
|
||||
- datetime: "2018-10-10T07:30:40Z"
|
||||
title: ~
|
||||
message: Telefonförsäljare
|
||||
- datetime: "2018-10-04T10:04:55Z"
|
||||
title: ~
|
||||
message: Folksam säljare
|
||||
- datetime: "2018-10-03T13:55:19Z"
|
||||
title: ~
|
||||
message: Sa inget.
|
||||
- datetime: "2018-08-24T16:56:46Z"
|
||||
title: ~
|
||||
message: Folksam
|
||||
- datetime: "2018-08-24T09:42:43Z"
|
||||
title: ~
|
||||
message: Achmati azmut från folksam
|
||||
- datetime: "2018-08-21T18:29:29Z"
|
||||
title: ~
|
||||
message: Folksam
|
||||
- datetime: "2018-08-16T18:56:56Z"
|
||||
title: ~
|
||||
message: Säljare från Folksam.
|
||||
- datetime: "2018-08-16T14:48:59Z"
|
||||
title: ~
|
||||
message: "Folksam "
|
||||
- datetime: "2018-08-09T16:30:28Z"
|
||||
title: ~
|
||||
message: Folksam
|
||||
- datetime: "2018-08-02T16:29:32Z"
|
||||
title: ~
|
||||
message: "Folksam "
|
||||
- datetime: "2018-08-02T15:33:38Z"
|
||||
title: ~
|
||||
message: "Folksam "
|
||||
- datetime: "2018-07-25T08:28:27Z"
|
||||
title: ~
|
||||
message: Säljare Folksam
|
||||
- datetime: "2018-07-17T21:20:51Z"
|
||||
title: ~
|
||||
message: "Inga Hansson "
|
||||
- datetime: "2018-07-16T18:11:46Z"
|
||||
title: ~
|
||||
message: Folksam
|
||||
- datetime: "2018-07-06T15:45:46Z"
|
||||
title: ~
|
||||
message: "Folksam "
|
||||
- datetime: "2018-07-05T17:24:07Z"
|
||||
title: ~
|
||||
message: folksam
|
||||
- datetime: "2018-07-05T11:15:02Z"
|
||||
title: ~
|
||||
message: Vesran
|
||||
- datetime: "2018-07-04T13:30:49Z"
|
||||
title: ~
|
||||
message: Folksam
|
||||
- datetime: "2018-06-29T10:52:51Z"
|
||||
title: ~
|
||||
message: folksam
|
||||
- datetime: "2018-06-28T13:33:01Z"
|
||||
title: ~
|
||||
message: Säljare folksam
|
||||
- datetime: "2018-06-28T07:42:42Z"
|
||||
title: ~
|
||||
message: Folksam försäkringar
|
||||
- datetime: "2018-06-26T12:59:33Z"
|
||||
title: ~
|
||||
message: Säljare Folksam"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0313908905() {
|
||||
let document = include_str!("../../fixtures/hitta/0313908905.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history: []
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0702269893() {
|
||||
let document = include_str!("../../fixtures/hitta/0702269893.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec!["Tre andra har också sökt på detta nummer".to_string()],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history:
|
||||
- Tre andra har också sökt på detta nummer
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0726443387() {
|
||||
let document = include_str!("../../fixtures/hitta/0726443387.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec!["1299 andra har också sökt på detta nummer".to_string()],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history:
|
||||
- 1299 andra har också sökt på detta nummer
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0751793426() {
|
||||
let document = include_str!("../../fixtures/hitta/0751793426.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history: []
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0751793483() {
|
||||
let document = include_str!("../../fixtures/hitta/0751793483.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history: []
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0751793499() {
|
||||
let document = include_str!("../../fixtures/hitta/0751793499.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history: []
|
||||
comments: []"###);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ impl Probe for KonsumentInfo {
|
||||
format!("http://konsumentinfo.se/telefonnummer/sverige/{}", number)
|
||||
}
|
||||
|
||||
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<(), ()> {
|
||||
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<Entry, ()> {
|
||||
let body = if let Some(cache) = ctx.cache_get("konsument_info", &number) {
|
||||
String::from_utf8(cache.data).unwrap()
|
||||
} else {
|
||||
@@ -49,21 +49,13 @@ impl Probe for KonsumentInfo {
|
||||
body
|
||||
};
|
||||
|
||||
match from_html(&body) {
|
||||
Ok(entry) => {
|
||||
println!("konsumentinfo.se:");
|
||||
print!("{}", entry);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Err(_) => Err(()),
|
||||
}
|
||||
from_html(&body)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pretty_assertions::assert_eq;
|
||||
use insta::assert_yaml_snapshot_matches;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -71,90 +63,52 @@ mod tests {
|
||||
fn test_0104754350() {
|
||||
let document = include_str!("../../fixtures/konsumentinfo/0104754350.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @"Err: ~");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0313908905() {
|
||||
let document = include_str!("../../fixtures/konsumentinfo/0313908905.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @"Err: ~");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0702269893() {
|
||||
let document = include_str!("../../fixtures/konsumentinfo/0702269893.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec!["Hydroscand AB".to_string()],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages:
|
||||
- Hydroscand AB
|
||||
history: []
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0726443387() {
|
||||
let document = include_str!("../../fixtures/konsumentinfo/0726443387.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @"Err: ~");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0751793426() {
|
||||
let document = include_str!("../../fixtures/konsumentinfo/0751793426.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @"Err: ~");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0751793483() {
|
||||
let document = include_str!("../../fixtures/konsumentinfo/0751793483.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @"Err: ~");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0751793499() {
|
||||
let document = include_str!("../../fixtures/konsumentinfo/0751793499.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @"Err: ~");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use chrono::offset::LocalResult;
|
||||
use chrono::{DateTime, NaiveDateTime, TimeZone, Utc};
|
||||
use chrono_tz::Europe::Stockholm;
|
||||
use log::debug;
|
||||
use scraper::{Html, Selector};
|
||||
|
||||
use crate::context::Context;
|
||||
@@ -98,7 +97,7 @@ impl Probe for Telefonforsaljare {
|
||||
format!("http://www.telefonforsaljare.nu/telefonnummer/{}/", number)
|
||||
}
|
||||
|
||||
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<(), ()> {
|
||||
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<Entry, ()> {
|
||||
let body = if let Some(cache) = ctx.cache_get("telefonforsaljare", &number) {
|
||||
String::from_utf8(cache.data).unwrap()
|
||||
} else {
|
||||
@@ -110,26 +109,13 @@ impl Probe for Telefonforsaljare {
|
||||
body
|
||||
};
|
||||
|
||||
println!("telefonforsaljare.nu:");
|
||||
|
||||
match from_html(&body) {
|
||||
Ok(entry) => {
|
||||
print!("{}", entry);
|
||||
}
|
||||
Err(_) => {
|
||||
debug!("telefonforsaljare: failed to parse page");
|
||||
|
||||
println!(" Failed to find any data");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
from_html(&body)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pretty_assertions::assert_eq;
|
||||
use insta::assert_yaml_snapshot_matches;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -137,133 +123,103 @@ mod tests {
|
||||
fn test_0104754350() {
|
||||
let document = include_str!("../../fixtures/telefonforsaljare/0104754350.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec!["Folksam".to_string()],
|
||||
history: vec!["De senaste 24 timmarna har 9 personer sökt efter numret 0104754350. Det kan tyda på att numret används av telefonförsäljare. Totalt har minst 4786 personer sökt efter numret.".to_string()],
|
||||
comments: vec![
|
||||
Comment {
|
||||
datetime: "2018-05-09T12:31:39Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: Some("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: Some("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: None,
|
||||
message: "Ringde och la på".to_string(),
|
||||
},
|
||||
Comment {
|
||||
datetime: "2017-11-20T14:53:16Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: Some("Folksam".to_string()),
|
||||
message: "färsäljare".to_string(),
|
||||
},
|
||||
Comment {
|
||||
datetime: "2017-11-16T12:38:07Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: Some("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: Some("Folksam".to_string()),
|
||||
message: "Försäljare".to_string(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages:
|
||||
- Folksam
|
||||
history:
|
||||
- De senaste 24 timmarna har 9 personer sökt efter numret 0104754350. Det kan tyda på att numret används av telefonförsäljare. Totalt har minst 4786 personer sökt efter numret.
|
||||
comments:
|
||||
- datetime: "2018-05-09T12:31:39Z"
|
||||
title: Folksam
|
||||
message: Svara inte på okända nummer. Blockerat!
|
||||
- datetime: "2017-12-05T16:33:10Z"
|
||||
title: Folksam
|
||||
message: Svarade aldrig men när jag ringde upp var det Folksam
|
||||
- datetime: "2017-11-28T10:30:10Z"
|
||||
title: ~
|
||||
message: Ringde och la på
|
||||
- datetime: "2017-11-20T14:53:16Z"
|
||||
title: Folksam
|
||||
message: färsäljare
|
||||
- datetime: "2017-11-16T12:38:07Z"
|
||||
title: Folksam
|
||||
message: "missat samtal, ringde tillbaka och automatsvar sa att det var folksam som sökt mig för att presentera ett erbjudande."
|
||||
- datetime: "2017-10-25T05:59:26Z"
|
||||
title: Folksam
|
||||
message: Försäljare"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0313908905() {
|
||||
let document = include_str!("../../fixtures/telefonforsaljare/0313908905.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec!["Du är den första de senaste 24 timmarna som söker efter detta nummer. Det tyder på att numret inte används av telefonförsäljare. Totalt har minst 301 personer sökt efter numret.".to_string()],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history:
|
||||
- Du är den första de senaste 24 timmarna som söker efter detta nummer. Det tyder på att numret inte används av telefonförsäljare. Totalt har minst 301 personer sökt efter numret.
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0702269893() {
|
||||
let document = include_str!("../../fixtures/telefonforsaljare/0702269893.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec!["Alnö Design & Produktion AB".to_string()],
|
||||
history: vec!["De senaste 24 timmarna har 3 personer sökt efter numret 0702269893. Det kan tyda på att numret används av telefonförsäljare. Totalt har minst 4 personer sökt efter numret.".to_string()],
|
||||
comments: vec![
|
||||
Comment {
|
||||
datetime: "2019-01-18T13:30:55Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: Some("Alnö Design & Produktion AB".to_string()),
|
||||
message: "Renhållning, service, kemprodukter".to_string(),
|
||||
}
|
||||
],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages:
|
||||
- Alnö Design & Produktion AB
|
||||
history:
|
||||
- De senaste 24 timmarna har 3 personer sökt efter numret 0702269893. Det kan tyda på att numret används av telefonförsäljare. Totalt har minst 4 personer sökt efter numret.
|
||||
comments:
|
||||
- datetime: "2019-01-18T13:30:55Z"
|
||||
title: Alnö Design & Produktion AB
|
||||
message: "Renhållning, service, kemprodukter""###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0726443387() {
|
||||
let document = include_str!("../../fixtures/telefonforsaljare/0726443387.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec!["Tele2".to_string()],
|
||||
history: vec!["De senaste 24 timmarna har 1 personer sökt efter numret 0726443387. Det kan tyda på att numret används av telefonförsäljare. Totalt har minst 231 personer sökt efter numret.".to_string()],
|
||||
comments: vec![
|
||||
Comment {
|
||||
datetime: "2018-10-31T17:48:27Z".parse::<DateTime<Utc>>().unwrap(),
|
||||
title: Some("Tele2".to_string()),
|
||||
message: "Bättre priser som inte finns online".to_string(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages:
|
||||
- Tele2
|
||||
history:
|
||||
- De senaste 24 timmarna har 1 personer sökt efter numret 0726443387. Det kan tyda på att numret används av telefonförsäljare. Totalt har minst 231 personer sökt efter numret.
|
||||
comments:
|
||||
- datetime: "2018-10-31T17:48:27Z"
|
||||
title: Tele2
|
||||
message: Bättre priser som inte finns online"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0751793426() {
|
||||
let document = include_str!("../../fixtures/telefonforsaljare/0751793426.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec!["Du är den första de senaste 24 timmarna som söker efter detta nummer. Det tyder på att numret inte används av telefonförsäljare. Totalt har minst 38 personer sökt efter numret.".to_string()],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history:
|
||||
- Du är den första de senaste 24 timmarna som söker efter detta nummer. Det tyder på att numret inte används av telefonförsäljare. Totalt har minst 38 personer sökt efter numret.
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0751793483() {
|
||||
let document = include_str!("../../fixtures/telefonforsaljare/0751793483.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec!["Du är den första de senaste 24 timmarna som söker efter detta nummer. Det tyder på att numret inte används av telefonförsäljare. Totalt har minst 25 personer sökt efter numret.".to_string()],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history:
|
||||
- Du är den första de senaste 24 timmarna som söker efter detta nummer. Det tyder på att numret inte används av telefonförsäljare. Totalt har minst 25 personer sökt efter numret.
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0751793499() {
|
||||
let document = include_str!("../../fixtures/telefonforsaljare/0751793499.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec!["Du är den första de senaste 24 timmarna som söker efter detta nummer. Det tyder på att numret inte används av telefonförsäljare. Totalt har minst 22 personer sökt efter numret.".to_string()],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history:
|
||||
- Du är den första de senaste 24 timmarna som söker efter detta nummer. Det tyder på att numret inte används av telefonförsäljare. Totalt har minst 22 personer sökt efter numret.
|
||||
comments: []"###);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ impl Probe for VemRingde {
|
||||
format!("http://vemringde.se/?q={}", number)
|
||||
}
|
||||
|
||||
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<(), ()> {
|
||||
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<Entry, ()> {
|
||||
let body = if let Some(cache) = ctx.cache_get("vem_ringde", &number) {
|
||||
String::from_utf8(cache.data).unwrap()
|
||||
} else {
|
||||
@@ -52,21 +52,13 @@ impl Probe for VemRingde {
|
||||
body
|
||||
};
|
||||
|
||||
match from_html(&body) {
|
||||
Ok(entry) => {
|
||||
println!("vemringde.se:");
|
||||
print!("{}", entry);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Err(_) => Err(()),
|
||||
}
|
||||
from_html(&body)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pretty_assertions::assert_eq;
|
||||
use insta::assert_yaml_snapshot_matches;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -74,90 +66,70 @@ mod tests {
|
||||
fn test_0104754350() {
|
||||
let document = include_str!("../../fixtures/vemringde/0104754350.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec!["Folksam (5 samtal)".to_string()],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages:
|
||||
- Folksam (5 samtal)
|
||||
history: []
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0313908905() {
|
||||
let document = include_str!("../../fixtures/vemringde/0313908905.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history: []
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0702269893() {
|
||||
let document = include_str!("../../fixtures/vemringde/0702269893.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history: []
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0726443387() {
|
||||
let document = include_str!("../../fixtures/vemringde/0726443387.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history: []
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0751793426() {
|
||||
let document = include_str!("../../fixtures/vemringde/0751793426.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history: []
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0751793483() {
|
||||
let document = include_str!("../../fixtures/vemringde/0751793483.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history: []
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0751793499() {
|
||||
let document = include_str!("../../fixtures/vemringde/0751793499.html");
|
||||
|
||||
let expected = Entry {
|
||||
messages: vec![],
|
||||
history: vec![],
|
||||
comments: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(from_html(&document), Ok(expected));
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @r###"Ok:
|
||||
messages: []
|
||||
history: []
|
||||
comments: []"###);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user