Lines
100 %
Functions
Branches
use std::collections::HashMap;
use finance::tag::Tag;
use server::command::FinanceEntity;
use sqlx::types::Uuid;
use super::commodity_labels;
fn tags(pairs: &[(&str, &str)]) -> HashMap<String, FinanceEntity> {
pairs
.iter()
.map(|(name, value)| {
let tag = Tag {
id: Uuid::new_v4(),
tag_name: (*name).to_owned(),
tag_value: (*value).to_owned(),
description: None,
};
((*name).to_owned(), FinanceEntity::Tag(tag))
})
.collect()
}
#[test]
fn both_tags_present_are_used_verbatim() {
let labels = commodity_labels(
Uuid::new_v4(),
&tags(&[("symbol", "USD"), ("name", "Dollar")]),
);
assert_eq!(labels, ("USD".to_owned(), "Dollar".to_owned()));
fn a_missing_symbol_falls_back_to_the_name() {
let labels = commodity_labels(Uuid::new_v4(), &tags(&[("name", "Dollar")]));
assert_eq!(labels, ("Dollar".to_owned(), "Dollar".to_owned()));
fn a_missing_name_falls_back_to_the_symbol() {
let labels = commodity_labels(Uuid::new_v4(), &tags(&[("symbol", "USD")]));
assert_eq!(labels, ("USD".to_owned(), "USD".to_owned()));
fn no_tags_fall_back_to_the_id() {
let id = Uuid::new_v4();
let labels = commodity_labels(id, &HashMap::new());
assert_eq!(labels, (id.to_string(), id.to_string()));