-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-16908][TEST] Add some test functions
- Loading branch information
1 parent
d01d841
commit 5e433c9
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::rc::Rc; | ||
|
||
use bitwarden_core::Client; | ||
use js_sys::Promise; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen] | ||
pub struct TestClient(Rc<Client>); | ||
|
||
impl TestClient { | ||
pub fn new(client: Rc<Client>) -> Self { | ||
Self(client) | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub struct TestSub1Client(Rc<Client>); | ||
|
||
#[wasm_bindgen] | ||
pub struct TestSub2Client(Rc<Client>); | ||
|
||
#[allow(clippy::unused_async)] | ||
#[wasm_bindgen] | ||
impl TestClient { | ||
pub fn sub1(&self) -> TestSub1Client { | ||
TestSub1Client(self.0.clone()) | ||
} | ||
|
||
#[allow(clippy::unused_async)] | ||
pub async fn async_echo(&self, msg: String) -> String { | ||
format!("ECHOED: '{}'", msg.to_uppercase()) | ||
} | ||
} | ||
|
||
#[allow(clippy::unused_async)] | ||
#[wasm_bindgen] | ||
impl TestSub1Client { | ||
pub fn sub2(&self) -> TestSub2Client { | ||
TestSub2Client(self.0.clone()) | ||
} | ||
|
||
pub async fn async_echo_cb( | ||
&self, | ||
#[wasm_bindgen(unchecked_param_type = "(text: string) => Promise<string>")] | ||
f: &js_sys::Function, | ||
) -> Result<String, JsValue> { | ||
let this = JsValue::null(); | ||
let val = f.call1(&this, &"hello".into())?; | ||
|
||
let pr: Promise = val.dyn_into()?; | ||
let fut = wasm_bindgen_futures::JsFuture::from(pr); | ||
let val = fut | ||
.await? | ||
.as_string() | ||
.ok_or_else(|| js_sys::Error::new("result is not a string"))?; | ||
|
||
Ok(format!("Result async: '{}'", val.to_uppercase())) | ||
} | ||
} | ||
|
||
#[allow(clippy::unused_async)] | ||
#[wasm_bindgen] | ||
impl TestSub2Client { | ||
#[allow(clippy::unused_async)] | ||
pub async fn get_flags(&self) -> String { | ||
format!("{:?}", self.0.internal.get_flags()) | ||
} | ||
} |