A lot more fixtures, use chrono for date.

This commit is contained in:
2019-01-22 10:27:38 +01:00
parent 94fa03d45c
commit 8e0563b463
44 changed files with 6493 additions and 17 deletions

View File

@@ -1,3 +1,4 @@
use chrono::{TimeZone, Utc};
use log::debug;
use regex::Regex;
use serde::Deserialize;
@@ -50,6 +51,13 @@ fn from_html(document: &str) -> Result<Entry, ()> {
let json = result.get(1).unwrap().as_str();
/*
println!(
"json: {:#?}",
serde_json::from_str::<serde_json::Value>(&json)
);
*/
if let Ok(data) = serde_json::from_str::<Data>(&json) {
let messages = Vec::new();
let mut history = Vec::new();
@@ -60,11 +68,16 @@ fn from_html(document: &str) -> Result<Entry, ()> {
for comment in phone_data.comments {
comments.push(probe::Comment {
datetime: "".to_string(),
datetime: Utc.timestamp(
(comment.timestamp / 1000) as i64,
(comment.timestamp % 1000) as u32,
),
title: "".to_string(),
message: comment.comment,
});
}
comments.sort_by(|a, b| b.datetime.cmp(&a.datetime));
}
Ok(Entry {
@@ -114,8 +127,36 @@ impl Probe for Hitta {
#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;
use super::*;
#[test]
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![],
};
assert_eq!(from_html(&document), Ok(expected));
}
#[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));
}
#[test]
fn test_0702269893() {
let document = include_str!("../../fixtures/hitta/0702269893.html");
@@ -128,4 +169,56 @@ mod tests {
assert_eq!(from_html(&document), Ok(expected));
}
#[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));
}
#[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));
}
#[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));
}
#[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));
}
}