Skip to main content

bitwarden_vault/cipher/blob/conversions/
bank_account.rs

1use super::{BankAccountDataV1, BankAccountView};
2
3impl_bidirectional_from!(
4    BankAccountView,
5    BankAccountDataV1,
6    [
7        bank_name,
8        name_on_account,
9        account_type,
10        account_number,
11        routing_number,
12        branch_number,
13        pin,
14        swift_code,
15        iban,
16        bank_contact_phone,
17    ]
18);
19
20#[cfg(test)]
21mod tests {
22    use super::super::{CipherBlobV1, test_support::*};
23    use crate::cipher::{bank_account::BankAccountView, cipher::CipherType};
24
25    #[test]
26    fn test_bank_account_cipher_round_trip() {
27        let original = crate::CipherView {
28            name: "My Bank Account".to_string(),
29            notes: None,
30            r#type: CipherType::BankAccount,
31            bank_account: Some(BankAccountView {
32                bank_name: Some("Test Bank".to_string()),
33                name_on_account: Some("John Doe".to_string()),
34                account_type: Some("Checking".to_string()),
35                account_number: Some("1234567890".to_string()),
36                routing_number: Some("021000021".to_string()),
37                branch_number: Some("001".to_string()),
38                pin: Some("1234".to_string()),
39                swift_code: Some("TESTUS33".to_string()),
40                iban: Some("US12345678901234567890".to_string()),
41                bank_contact_phone: Some("555-0123".to_string()),
42            }),
43            ..create_shell_cipher_view(CipherType::BankAccount)
44        };
45
46        let blob = CipherBlobV1::from_cipher_view(&original).unwrap();
47        let mut restored = create_shell_cipher_view(CipherType::BankAccount);
48        blob.apply_to_cipher_view(&mut restored).unwrap();
49
50        assert_eq!(restored.name, "My Bank Account");
51        assert_eq!(restored.r#type, CipherType::BankAccount);
52        let bank_account = restored.bank_account.unwrap();
53        assert_eq!(bank_account.bank_name, Some("Test Bank".to_string()));
54        assert_eq!(bank_account.account_number, Some("1234567890".to_string()));
55        assert_eq!(bank_account.pin, Some("1234".to_string()));
56        assert!(restored.login.is_none());
57    }
58}