bitwarden_test/play/
scene.rs

1//! Scene wrapper for test data
2
3use std::collections::HashMap;
4
5use super::SceneTemplate;
6
7/// A scene containing test data created by the seeder
8///
9/// The scene wraps a template instance with the server response data.
10/// Cleanup is handled by the owning `Play` instance when it is dropped.
11pub struct Scene<T: SceneTemplate> {
12    /// The result data from the server
13    result: T::Result,
14    /// Map of original IDs to mangled IDs for test isolation
15    mangle_map: HashMap<String, String>,
16}
17
18impl<T: SceneTemplate> Scene<T> {
19    /// Create a new scene wrapper
20    pub(crate) fn new(result: T::Result, mangle_map: HashMap<String, String>) -> Self {
21        Self { result, mangle_map }
22    }
23
24    /// Access the result data
25    pub fn result(&self) -> &T::Result {
26        &self.result
27    }
28
29    /// Get the mangled value for a given key, or return the key if not found
30    pub fn get_mangled<'a>(&'a self, key: &'a str) -> &'a str {
31        self.mangle_map.get(key).map(|s| s.as_str()).unwrap_or(key)
32    }
33}