Skip to content

Commit 7dc66a5

Browse files
committed
Fix edit_as_admin tests
1 parent 0a558c1 commit 7dc66a5

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

crates/bitwarden-vault/src/cipher/cipher_client/create.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,13 @@ impl CiphersClient {
342342
#[cfg(test)]
343343
mod tests {
344344
use bitwarden_api_api::{apis::ApiClient, models::CipherResponseModel};
345-
use bitwarden_core::Client;
346345
use bitwarden_core::{
347-
ClientSettings, DeviceType, UserId,
346+
Client, ClientSettings, DeviceType, UserId,
348347
key_management::crypto::{
349348
InitOrgCryptoRequest, InitUserCryptoMethod, InitUserCryptoRequest,
350349
},
351350
};
352-
use bitwarden_crypto::SymmetricCryptoKey;
353-
use bitwarden_crypto::{EncString, Kdf};
351+
use bitwarden_crypto::{EncString, Kdf, SymmetricCryptoKey};
354352
use bitwarden_test::{MemoryRepository, start_api_mock};
355353
use chrono::Utc;
356354
use wiremock::{

crates/bitwarden-vault/src/cipher/cipher_client/delete.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ impl CiphersClient {
4141
Ok(())
4242
}
4343

44-
/// Deletes all [Cipher] objects with a matching [CipherId] from the server, using the admin endpoint.
44+
/// Deletes all [Cipher] objects with a matching [CipherId] from the server, using the admin
45+
/// endpoint.
4546
pub async fn delete_many_as_admin(
4647
&self,
4748
cipher_ids: Vec<CipherId>,
@@ -97,7 +98,8 @@ impl CiphersClient {
9798
Ok(())
9899
}
99100

100-
/// Soft-deletes the [Cipher] with the matching [CipherId] from the server, using the admin endpoint.
101+
/// Soft-deletes the [Cipher] with the matching [CipherId] from the server, using the admin
102+
/// endpoint.
101103
pub async fn soft_delete_as_admin(&self, cipher_id: CipherId) -> Result<(), DeleteCipherError> {
102104
let configs = self.get_api_configurations().await;
103105
let api = configs.api_client.ciphers_api();
@@ -124,7 +126,8 @@ impl CiphersClient {
124126
Ok(())
125127
}
126128

127-
/// Soft-deletes all [Cipher] objects for the given [CipherId]s from the server, using the admin endpoint.
129+
/// Soft-deletes all [Cipher] objects for the given [CipherId]s from the server, using the admin
130+
/// endpoint.
128131
pub async fn soft_delete_many_as_admin(
129132
&self,
130133
cipher_ids: Vec<CipherId>,
@@ -151,7 +154,6 @@ mod tests {
151154
};
152155
use bitwarden_crypto::{EncString, Kdf};
153156
use bitwarden_test::{MemoryRepository, start_api_mock};
154-
155157
use chrono::Utc;
156158
use wiremock::{
157159
Mock, MockServer, ResponseTemplate,

crates/bitwarden-vault/src/cipher/cipher_client/edit.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,16 +758,25 @@ mod tests {
758758
])
759759
.await;
760760
let client = create_client_with_wiremock(&mock_server).await;
761+
let repository = client.get_repository().unwrap();
761762

762763
let cipher_view = generate_test_cipher();
763-
let request = cipher_view.try_into().unwrap();
764+
repository
765+
.set(
766+
TEST_CIPHER_ID.to_string(),
767+
client.encrypt(cipher_view.clone()).unwrap().cipher,
768+
)
769+
.await
770+
.unwrap();
764771

772+
let request = cipher_view.try_into().unwrap();
773+
let start_time = Utc::now();
765774
let result = client.edit_as_admin(request).await.unwrap();
766775

767-
let repository = client.get_repository().unwrap();
768776
let cipher = repository.get(TEST_CIPHER_ID.to_string()).await.unwrap();
769777
// Should not update local repository for admin endpoints.
770-
assert!(matches!(cipher, None));
778+
assert!(result.revision_date > start_time);
779+
assert!(cipher.unwrap().revision_date < start_time);
771780

772781
assert_eq!(result.id, TEST_CIPHER_ID.parse().ok());
773782
assert_eq!(result.name, "Test Login");

crates/bitwarden-vault/src/cipher/cipher_client/restore.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ mod tests {
124124
};
125125
use bitwarden_crypto::{EncString, Kdf};
126126
use bitwarden_test::{MemoryRepository, start_api_mock};
127-
128127
use chrono::Utc;
129128
use wiremock::{
130129
Mock, MockServer, ResponseTemplate,

0 commit comments

Comments
 (0)