bitwarden_encrypted_migrator/
encrypted_migrator_client.rs1use bitwarden_core::{Client, FromClient};
2
3use crate::migration::{Migration, run_migrations};
4
5#[bitwarden_ffi::wasm_object]
7pub struct EncryptedMigratorClient {
8 migrations: Vec<Migration>,
9}
10
11impl FromClient for EncryptedMigratorClient {
12 fn from_client(client: &Client) -> Self {
13 Self {
14 migrations: Migration::all(client),
15 }
16 }
17}
18
19#[bitwarden_ffi::wasm_export]
20impl EncryptedMigratorClient {
21 pub async fn run_migrations(&self) {
27 run_migrations(&self.migrations).await;
28 }
29}
30
31pub trait EncryptedMigratorClientExt {
33 fn encrypted_migrator(&self) -> EncryptedMigratorClient;
35}
36
37impl EncryptedMigratorClientExt for Client {
38 fn encrypted_migrator(&self) -> EncryptedMigratorClient {
39 EncryptedMigratorClient::from_client(self)
40 }
41}
42
43#[cfg(test)]
44mod tests {
45 use bitwarden_organizations::OrganizationUserType;
46
47 use super::*;
48 use crate::migrations::account_recovery_v2_upgrade::tests::{
49 client, expect_no_pending, organization,
50 };
51
52 #[tokio::test]
54 async fn test_run_migrations_runs_each_migration() {
55 let owner = organization(OrganizationUserType::Owner);
56 let owner_id = owner.details.id;
57 let client = client(&[owner], &[owner_id], |mock| {
58 expect_no_pending(mock, owner_id);
59 })
60 .await;
61
62 client.encrypted_migrator().run_migrations().await;
63 }
64}