darkwing/server/services/browser_profile_services/config/
synchronize.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! Module for handling browser synchronization configurations across different
//! platforms.

use crate::server::{
  dtos::{
    browser_profile_dto::BrowserProfileFullData, start_dto::StartRequest,
  },
  error::Error,
};
use serde::{Deserialize, Serialize};

use super::{screen::Screen, FromStartRequest, Navigator};

/// Represents the synchronization configuration for a browser profile.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct Synchronize {
  /// Name of the session.
  #[serde(rename = "name_session")]
  pub(super) session_name: String,

  /// Indicates if the session is owned by the user.
  pub(crate) is_owned: bool,
}

impl FromStartRequest<Synchronize> for Synchronize {
  /// Creates a new `Synchronize` instance from the start request parameters.
  ///
  /// # Arguments
  /// * `_bp` - Browser profile data containing platform information
  /// * `request` - Start request parameters
  /// * `_navigator` - Navigator configuration
  /// * `_screen` - Screen configuration
  /// * `_token` - Authentication token
  ///
  /// # Returns
  /// * `Result<Self, Error>` - A new Synchronize instance
  fn from_start_request(
    _bp: &BrowserProfileFullData,
    request: &StartRequest,
    _navigator: &Navigator,
    _screen: &Screen,
    _token: &str,
  ) -> Result<Self, Error> {
    Ok(Self {
      session_name: match &request.action_synchronizator_session_name {
        Some(name) => name.clone(),
        None => String::new(),
      },
      is_owned: request.action_synchronizator_is_owned.unwrap_or(false),
    })
  }
}

#[cfg(test)]
mod tests {
  use crate::server::services::browser_profile_services::config::consts::LINUX_MOCK_PROFILE;

  use super::*;

  #[test]
  fn test_with_no_session_name() -> Result<(), Error> {
    let profile = LINUX_MOCK_PROFILE.clone();
    let request = StartRequest::get_mock();
    let navigator = Navigator::default();
    let screen = Screen::default();
    let token = String::new();

    let result = Synchronize::from_start_request(
      &profile, &request, &navigator, &screen, &token,
    )?;

    assert_eq!(result.session_name, "");

    Ok(())
  }

  #[test]
  fn test_with_session_name() -> Result<(), Error> {
    let profile = LINUX_MOCK_PROFILE.clone();
    let mut request = StartRequest::get_mock();
    request.action_synchronizator_session_name = Some("test".to_string());
    let navigator = Navigator::default();
    let screen = Screen::default();
    let token = String::new();

    let result = Synchronize::from_start_request(
      &profile, &request, &navigator, &screen, &token,
    )?;
    assert_eq!(result.session_name, "test");
    Ok(())
  }
}