Skip to content

Commit d1e534f

Browse files
committed
Added tests around parent node not existing and still forming a tree structure.
1 parent 0c9fb99 commit d1e534f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

crates/bitwarden-vault/src/tree.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,41 @@ mod tests {
235235
panic!("Node not found");
236236
}
237237
}
238+
239+
#[test]
240+
fn given_collection_with_two_children_where_there_parent_node_does_not_exist_children_are_returned_correctly() {
241+
let child_1_id = Uuid::new_v4();
242+
let grandparent_id = Uuid::new_v4();
243+
let mut items = vec![
244+
TestItem {
245+
id: child_1_id,
246+
name: "grandparent/parent/child1".to_string()
247+
},
248+
TestItem {
249+
id: Uuid::new_v4(),
250+
name: "grandparent/parent/child2".to_string()
251+
},
252+
TestItem {
253+
id: grandparent_id,
254+
name: "grandparent".to_string()
255+
},
256+
];
257+
258+
let node_option = Tree::from_items(&mut items)
259+
.get_item_by_id(child_1_id);
260+
261+
if let Some(node) = node_option {
262+
let item = node.item;
263+
let parent = node.parent;
264+
let children = node.children;
265+
266+
assert_eq!(children.len(), 0);
267+
assert_eq!(item.id(), Some(child_1_id));
268+
assert_eq!(item.short_name(), "child1");
269+
assert_eq!(item.path(), ["grandparent", "parent", "child1"]);
270+
assert!(parent.is_none());
271+
} else {
272+
panic!("Node not found");
273+
}
274+
}
238275
}

0 commit comments

Comments
 (0)