bitwarden_vault/cipher/blob/conversions/
card.rs1use super::{CardDataV1, CardView};
2
3impl_bidirectional_from!(
4 CardView,
5 CardDataV1,
6 [cardholder_name, exp_month, exp_year, code, brand, number,]
7);
8
9#[cfg(test)]
10mod tests {
11 use super::super::{CipherBlobV1, test_support::*};
12 use crate::cipher::{card::CardView, cipher::CipherType};
13
14 #[test]
15 fn test_card_cipher_round_trip() {
16 let (key_store, key_id) = create_test_key_store();
17 let mut ctx = key_store.context_mut();
18
19 let original = crate::CipherView {
20 name: "My Card".to_string(),
21 notes: None,
22 r#type: CipherType::Card,
23 card: Some(CardView {
24 cardholder_name: Some("John Doe".to_string()),
25 exp_month: Some("12".to_string()),
26 exp_year: Some("2028".to_string()),
27 code: Some("123".to_string()),
28 brand: Some("Visa".to_string()),
29 number: Some("4111111111111111".to_string()),
30 }),
31 ..create_shell_cipher_view(CipherType::Card)
32 };
33
34 let blob = CipherBlobV1::from_cipher_view(&original, &mut ctx, key_id).unwrap();
35 let mut restored = create_shell_cipher_view(CipherType::Card);
36 blob.apply_to_cipher_view(&mut restored, &mut ctx, key_id)
37 .unwrap();
38
39 assert_eq!(restored.name, "My Card");
40 assert_eq!(restored.r#type, CipherType::Card);
41 let card = restored.card.unwrap();
42 assert_eq!(card.cardholder_name, Some("John Doe".to_string()));
43 assert_eq!(card.number, Some("4111111111111111".to_string()));
44 assert!(restored.login.is_none());
45 }
46}