From 6df7630e9beaece47fa9b299e4887ffd1e75e74b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 14 Apr 2025 13:38:39 +0000 Subject: [PATCH 1/2] Update Rust crate mockito to 0.32.0 --- Cargo.lock | 222 ++++++++++++++++++++++++++++++++++++++++++++++++----- Cargo.toml | 2 +- 2 files changed, 203 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0381d18..cbc9742 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -247,6 +247,21 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.31" @@ -254,6 +269,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -262,6 +278,34 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "futures-sink" version = "0.3.31" @@ -280,10 +324,16 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ + "futures-channel", "futures-core", + "futures-io", + "futures-macro", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -319,6 +369,25 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +[[package]] +name = "h2" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.12", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "h2" version = "0.4.8" @@ -330,7 +399,7 @@ dependencies = [ "fnv", "futures-core", "futures-sink", - "http", + "http 1.3.1", "indexmap", "slab", "tokio", @@ -344,6 +413,17 @@ version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http" version = "1.3.1" @@ -355,6 +435,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http 0.2.12", + "pin-project-lite", +] + [[package]] name = "http-body" version = "1.0.1" @@ -362,7 +453,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", - "http", + "http 1.3.1", ] [[package]] @@ -373,8 +464,8 @@ checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" dependencies = [ "bytes", "futures-core", - "http", - "http-body", + "http 1.3.1", + "http-body 1.0.1", "pin-project-lite", ] @@ -384,6 +475,36 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "0.14.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2 0.3.26", + "http 0.2.12", + "http-body 0.4.6", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + [[package]] name = "hyper" version = "1.6.0" @@ -393,9 +514,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", - "http", - "http-body", + "h2 0.4.8", + "http 1.3.1", + "http-body 1.0.1", "httparse", "itoa", "pin-project-lite", @@ -411,8 +532,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d191583f3da1305256f22463b9bb0471acad48a4e534a5218b9963e9c1f59b2" dependencies = [ "futures-util", - "http", - "hyper", + "http 1.3.1", + "hyper 1.6.0", "hyper-util", "rustls", "rustls-pki-types", @@ -430,7 +551,7 @@ checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", "http-body-util", - "hyper", + "hyper 1.6.0", "hyper-util", "native-tls", "tokio", @@ -447,9 +568,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "http", - "http-body", - "hyper", + "http 1.3.1", + "http-body 1.0.1", + "hyper 1.6.0", "libc", "pin-project-lite", "socket2", @@ -677,6 +798,16 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23fb14cb19457329c82206317a5663005a4d404783dc74f4252769b0d5f42856" +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.27" @@ -723,13 +854,14 @@ dependencies = [ [[package]] name = "mockito" -version = "0.31.1" +version = "0.32.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80f9fece9bd97ab74339fe19f4bcaf52b76dcc18e5364c7977c1838f76b38de9" +checksum = "406f43768da5a859ce19bb0978fd8dc2167a7d9a52f3935c6a187242e1a4ff9f" dependencies = [ "assert-json-diff", "colored", - "httparse", + "futures", + "hyper 0.14.32", "lazy_static", "log", "rand 0.8.5", @@ -737,6 +869,7 @@ dependencies = [ "serde_json", "serde_urlencoded", "similar", + "tokio", ] [[package]] @@ -824,6 +957,29 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -1001,6 +1157,15 @@ dependencies = [ "getrandom 0.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3" +dependencies = [ + "bitflags", +] + [[package]] name = "regex" version = "1.11.1" @@ -1041,11 +1206,11 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2", - "http", - "http-body", + "h2 0.4.8", + "http 1.3.1", + "http-body 1.0.1", "http-body-util", - "hyper", + "hyper 1.6.0", "hyper-rustls", "hyper-tls", "hyper-util", @@ -1182,6 +1347,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "security-framework" version = "2.11.1" @@ -1255,6 +1426,15 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + [[package]] name = "similar" version = "2.7.0" @@ -1418,7 +1598,9 @@ dependencies = [ "bytes", "libc", "mio", + "parking_lot", "pin-project-lite", + "signal-hook-registry", "socket2", "tokio-macros", "windows-sys 0.52.0", diff --git a/Cargo.toml b/Cargo.toml index 123bd65..3126146 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ url = "2.5.4" [dev-dependencies] matches = "0.1.10" -mockito = "0.31.1" +mockito = "0.32.0" tokio = { version = "1.44.2", default-features = false, features = [ "macros", "rt-multi-thread", From 929aa626e46e4b6d119778931db0fb8488defb27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABlle=20Huisman?= Date: Mon, 14 Apr 2025 16:15:40 +0200 Subject: [PATCH 2/2] Use `Server::new_async` and `Mock::create_async` --- .../operations/generate_portal_link.rs | 9 +- src/core/types/url_encodable_vec.rs | 22 +++-- .../operations/delete_directory.rs | 21 +++-- .../operations/get_directory.rs | 21 +++-- .../operations/get_directory_group.rs | 41 +++++---- .../operations/get_directory_user.rs | 91 ++++++++++--------- .../operations/list_directories.rs | 22 +++-- .../operations/list_directory_groups.rs | 22 +++-- .../operations/list_directory_users.rs | 22 +++-- src/mfa/operations/challenge_factor.rs | 89 +++++++++--------- src/mfa/operations/enroll_factor.rs | 19 ++-- src/mfa/operations/verify_challenge.rs | 51 ++++++----- .../operations/create_organization.rs | 11 ++- .../operations/delete_organization.rs | 11 ++- .../operations/get_organization.rs | 11 ++- .../operations/list_organizations.rs | 22 +++-- .../operations/update_organization.rs | 11 ++- .../operations/create_passwordless_session.rs | 11 ++- .../operations/send_passwordless_session.rs | 23 +++-- src/sso/operations/delete_connection.rs | 11 ++- src/sso/operations/get_connection.rs | 21 +++-- src/sso/operations/get_profile.rs | 11 ++- src/sso/operations/get_profile_and_token.rs | 42 ++++++--- src/sso/operations/list_connections.rs | 22 +++-- src/workos.rs | 12 ++- 25 files changed, 392 insertions(+), 257 deletions(-) diff --git a/src/admin_portal/operations/generate_portal_link.rs b/src/admin_portal/operations/generate_portal_link.rs index e2f456c..f9e6466 100644 --- a/src/admin_portal/operations/generate_portal_link.rs +++ b/src/admin_portal/operations/generate_portal_link.rs @@ -118,7 +118,6 @@ impl GeneratePortalLink for AdminPortal<'_> { #[cfg(test)] mod test { - use mockito::{self, mock}; use serde_json::json; use tokio; @@ -129,12 +128,14 @@ mod test { #[tokio::test] async fn it_calls_the_generate_portal_link_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&dbg!(mockito::server_url())) + .base_url(&dbg!(server.url())) .unwrap() .build(); - let _mock = mock("POST", "/portal/generate_link") + let _mock = server.mock("POST", "/portal/generate_link") .match_header("Authorization", "Bearer sk_example_123456789") .match_body(r#"{"organization":"org_01EHZNVPK3SFK441A1RGBFSHRT","intent":"sso"}"#) .with_status(201) @@ -144,7 +145,7 @@ mod test { }) .to_string(), ) - .create(); + .create_async().await; let GeneratePortalLinkResponse { link } = workos .admin_portal() diff --git a/src/core/types/url_encodable_vec.rs b/src/core/types/url_encodable_vec.rs index 63406b3..2216422 100644 --- a/src/core/types/url_encodable_vec.rs +++ b/src/core/types/url_encodable_vec.rs @@ -43,7 +43,7 @@ where #[cfg(test)] mod test { - use mockito::{self, mock, Matcher}; + use mockito::Matcher; use reqwest::StatusCode; use serde::Serialize; @@ -57,18 +57,22 @@ mod test { pub items: UrlEncodableVec<&'a str>, } - let _mock = mock("GET", "/") + let mut server = mockito::Server::new_async().await; + + let _mock = server + .mock("GET", "/") .match_query(Matcher::UrlEncoded( "items[]".to_string(), "one,two,three".to_string(), )) .with_status(200) - .create(); + .create_async() + .await; let client = reqwest::Client::new(); let response = client - .get(mockito::server_url()) + .get(server.url()) .query(&List { items: UrlEncodableVec(vec!["one", "two", "three"]), }) @@ -87,18 +91,22 @@ mod test { pub items: Option>, } - let _mock = mock("GET", "/") + let mut server = mockito::Server::new_async().await; + + let _mock = server + .mock("GET", "/") .match_query(Matcher::UrlEncoded( "items[]".to_string(), "one,two,three".to_string(), )) .with_status(200) - .create(); + .create_async() + .await; let client = reqwest::Client::new(); let response = client - .get(mockito::server_url()) + .get(server.url()) .query(&List { items: Some(UrlEncodableVec(vec!["one", "two", "three"])), }) diff --git a/src/directory_sync/operations/delete_directory.rs b/src/directory_sync/operations/delete_directory.rs index 98081ca..3cccac7 100644 --- a/src/directory_sync/operations/delete_directory.rs +++ b/src/directory_sync/operations/delete_directory.rs @@ -79,7 +79,6 @@ impl DeleteDirectory for DirectorySync<'_> { #[cfg(test)] mod test { use matches::assert_matches; - use mockito::{self, mock}; use tokio; use crate::directory_sync::DirectoryId; @@ -89,18 +88,22 @@ mod test { #[tokio::test] async fn it_calls_the_delete_directory_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock( - "DELETE", - "/directories/directory_01ECAZ4NV9QMV47GW873HDCX74", - ) - .match_header("Authorization", "Bearer sk_example_123456789") - .with_status(202) - .create(); + let _mock = server + .mock( + "DELETE", + "/directories/directory_01ECAZ4NV9QMV47GW873HDCX74", + ) + .match_header("Authorization", "Bearer sk_example_123456789") + .with_status(202) + .create_async() + .await; let result = workos .directory_sync() diff --git a/src/directory_sync/operations/get_directory.rs b/src/directory_sync/operations/get_directory.rs index f9a6faf..438cbe8 100644 --- a/src/directory_sync/operations/get_directory.rs +++ b/src/directory_sync/operations/get_directory.rs @@ -66,7 +66,6 @@ impl GetDirectory for DirectorySync<'_> { #[cfg(test)] mod test { use matches::assert_matches; - use mockito::{self, mock}; use serde_json::json; use tokio; @@ -76,12 +75,15 @@ mod test { #[tokio::test] async fn it_calls_the_get_directory_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/directories/directory_01ECAZ4NV9QMV47GW873HDCX74") + let _mock = server + .mock("GET", "/directories/directory_01ECAZ4NV9QMV47GW873HDCX74") .match_header("Authorization", "Bearer sk_example_123456789") .with_status(200) .with_body( @@ -97,7 +99,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let directory = workos .directory_sync() @@ -113,12 +116,15 @@ mod test { #[tokio::test] async fn it_returns_an_error_when_the_get_directory_endpoint_returns_unauthorized() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/directories/directory_01ECAZ4NV9QMV47GW873HDCX74") + let _mock = server + .mock("GET", "/directories/directory_01ECAZ4NV9QMV47GW873HDCX74") .match_header("Authorization", "Bearer sk_example_123456789") .with_status(401) .with_body( @@ -127,7 +133,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let result = workos .directory_sync() diff --git a/src/directory_sync/operations/get_directory_group.rs b/src/directory_sync/operations/get_directory_group.rs index 4e3e174..e1ee1b9 100644 --- a/src/directory_sync/operations/get_directory_group.rs +++ b/src/directory_sync/operations/get_directory_group.rs @@ -74,7 +74,6 @@ impl GetDirectoryGroup for DirectorySync<'_> { #[cfg(test)] mod test { use matches::assert_matches; - use mockito::{self, mock}; use serde_json::json; use tokio; @@ -84,12 +83,14 @@ mod test { #[tokio::test] async fn it_calls_the_get_directory_group_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock( + let _mock = server.mock( "GET", "/directory_groups/directory_group_01E64QTDNS0EGJ0FMCVY9BWGZT", ) @@ -107,7 +108,7 @@ mod test { }) .to_string(), ) - .create(); + .create_async().await; let directory = workos .directory_sync() @@ -125,24 +126,28 @@ mod test { #[tokio::test] async fn it_returns_an_error_when_the_get_directory_group_endpoint_returns_unauthorized() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock( - "GET", - "/directory_groups/directory_group_01E64QTDNS0EGJ0FMCVY9BWGZT", - ) - .match_header("Authorization", "Bearer sk_example_123456789") - .with_status(401) - .with_body( - json!({ - "message": "Unauthorized" - }) - .to_string(), - ) - .create(); + let _mock = server + .mock( + "GET", + "/directory_groups/directory_group_01E64QTDNS0EGJ0FMCVY9BWGZT", + ) + .match_header("Authorization", "Bearer sk_example_123456789") + .with_status(401) + .with_body( + json!({ + "message": "Unauthorized" + }) + .to_string(), + ) + .create_async() + .await; let result = workos .directory_sync() diff --git a/src/directory_sync/operations/get_directory_user.rs b/src/directory_sync/operations/get_directory_user.rs index acd1da1..0375827 100644 --- a/src/directory_sync/operations/get_directory_user.rs +++ b/src/directory_sync/operations/get_directory_user.rs @@ -74,7 +74,6 @@ impl GetDirectoryUser for DirectorySync<'_> { #[cfg(test)] mod test { use matches::assert_matches; - use mockito::{self, mock}; use serde_json::json; use tokio; @@ -84,48 +83,52 @@ mod test { #[tokio::test] async fn it_calls_the_get_directory_user_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock( - "GET", - "/directory_users/directory_user_01E1JG7J09H96KYP8HM9B0G5SJ", - ) - .match_header("Authorization", "Bearer sk_example_123456789") - .with_status(200) - .with_body( - json!({ - "id": "directory_user_01E1JG7J09H96KYP8HM9B0G5SJ", - "idp_id": "2836", - "directory_id": "directory_01ECAZ4NV9QMV47GW873HDCX74", - "emails": [{ - "primary": true, - "type": "work", - "value": "marcelina@foo-corp.com" - }], - "first_name": "Marcelina", - "last_name": "Davis", - "username": "marcelina@foo-corp.com", - "groups": [{ - "id": "", - "name": "Engineering", - "created_at": "2021-06-25T19:07:33.155Z", - "updated_at": "2021-06-25T19:07:33.155Z", - "raw_attributes": {"id": ""} - }], - "state": "active", - "created_at": "2021-06-25T19:07:33.155Z", - "updated_at": "2021-06-25T19:07:33.155Z", - "custom_attributes": { - "department": "Engineering" - }, - "raw_attributes": {"department": "Engineering"} - }) - .to_string(), - ) - .create(); + let _mock = server + .mock( + "GET", + "/directory_users/directory_user_01E1JG7J09H96KYP8HM9B0G5SJ", + ) + .match_header("Authorization", "Bearer sk_example_123456789") + .with_status(200) + .with_body( + json!({ + "id": "directory_user_01E1JG7J09H96KYP8HM9B0G5SJ", + "idp_id": "2836", + "directory_id": "directory_01ECAZ4NV9QMV47GW873HDCX74", + "emails": [{ + "primary": true, + "type": "work", + "value": "marcelina@foo-corp.com" + }], + "first_name": "Marcelina", + "last_name": "Davis", + "username": "marcelina@foo-corp.com", + "groups": [{ + "id": "", + "name": "Engineering", + "created_at": "2021-06-25T19:07:33.155Z", + "updated_at": "2021-06-25T19:07:33.155Z", + "raw_attributes": {"id": ""} + }], + "state": "active", + "created_at": "2021-06-25T19:07:33.155Z", + "updated_at": "2021-06-25T19:07:33.155Z", + "custom_attributes": { + "department": "Engineering" + }, + "raw_attributes": {"department": "Engineering"} + }) + .to_string(), + ) + .create_async() + .await; let directory_user = workos .directory_sync() @@ -143,12 +146,15 @@ mod test { #[tokio::test] async fn it_returns_an_error_when_the_get_directory_user_endpoint_returns_unauthorized() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/directory_users/") + let _mock = server + .mock("GET", "/directory_users/") .match_header("Authorization", "Bearer sk_example_123456789") .with_status(401) .with_body( @@ -157,7 +163,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let result = workos .directory_sync() diff --git a/src/directory_sync/operations/list_directories.rs b/src/directory_sync/operations/list_directories.rs index 5db2b48..77f0fd8 100644 --- a/src/directory_sync/operations/list_directories.rs +++ b/src/directory_sync/operations/list_directories.rs @@ -83,7 +83,7 @@ impl ListDirectories for DirectorySync<'_> { #[cfg(test)] mod test { - use mockito::{self, mock, Matcher}; + use mockito::Matcher; use serde_json::json; use tokio; @@ -94,12 +94,15 @@ mod test { #[tokio::test] async fn it_calls_the_list_directories_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/directories") + let _mock = server + .mock("GET", "/directories") .match_query(Matcher::UrlEncoded("order".to_string(), "desc".to_string())) .match_header("Authorization", "Bearer sk_example_123456789") .with_status(200) @@ -135,7 +138,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let paginated_list = workos .directory_sync() @@ -151,12 +155,15 @@ mod test { #[tokio::test] async fn it_calls_the_list_directories_endpoint_with_the_directory_type() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/directories") + let _mock = server + .mock("GET", "/directories") .match_query(Matcher::UrlEncoded( "directory_type".to_string(), "gsuite directory".to_string(), @@ -184,7 +191,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let paginated_list = workos .directory_sync() diff --git a/src/directory_sync/operations/list_directory_groups.rs b/src/directory_sync/operations/list_directory_groups.rs index df9dac2..3708e3d 100644 --- a/src/directory_sync/operations/list_directory_groups.rs +++ b/src/directory_sync/operations/list_directory_groups.rs @@ -91,7 +91,7 @@ impl ListDirectoryGroups for DirectorySync<'_> { #[cfg(test)] mod test { - use mockito::{self, mock, Matcher}; + use mockito::Matcher; use serde_json::json; use tokio; @@ -102,12 +102,15 @@ mod test { #[tokio::test] async fn it_calls_the_list_directory_groups_endpoint_with_a_directory_id() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/directory_groups") + let _mock = server + .mock("GET", "/directory_groups") .match_query(Matcher::AllOf(vec![ Matcher::UrlEncoded("order".to_string(), "desc".to_string()), Matcher::UrlEncoded( @@ -136,7 +139,8 @@ mod test { ) .to_string(), ) - .create(); + .create_async() + .await; let paginated_list = workos .directory_sync() @@ -163,12 +167,15 @@ mod test { #[tokio::test] async fn it_calls_the_list_directory_groups_endpoint_with_a_directory_user_id() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/directory_groups") + let _mock = server + .mock("GET", "/directory_groups") .match_query(Matcher::AllOf(vec![ Matcher::UrlEncoded("order".to_string(), "desc".to_string()), Matcher::UrlEncoded( @@ -208,7 +215,8 @@ mod test { }}) .to_string(), ) - .create(); + .create_async() + .await; let paginated_list = workos .directory_sync() diff --git a/src/directory_sync/operations/list_directory_users.rs b/src/directory_sync/operations/list_directory_users.rs index e25b5f5..52f8a92 100644 --- a/src/directory_sync/operations/list_directory_users.rs +++ b/src/directory_sync/operations/list_directory_users.rs @@ -91,7 +91,7 @@ impl ListDirectoryUsers for DirectorySync<'_> { #[cfg(test)] mod test { - use mockito::{self, mock, Matcher}; + use mockito::Matcher; use serde_json::json; use tokio; @@ -102,12 +102,15 @@ mod test { #[tokio::test] async fn it_calls_the_list_directory_users_endpoint_with_a_directory_id() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/directory_users") + let _mock = server + .mock("GET", "/directory_users") .match_query(Matcher::AllOf(vec![ Matcher::UrlEncoded("order".to_string(), "desc".to_string()), Matcher::UrlEncoded( @@ -193,7 +196,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let paginated_list = workos .directory_sync() @@ -220,12 +224,15 @@ mod test { #[tokio::test] async fn it_calls_the_list_directory_users_endpoint_with_a_directory_group_id() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/directory_users") + let _mock = server + .mock("GET", "/directory_users") .match_query(Matcher::AllOf(vec![ Matcher::UrlEncoded("order".to_string(), "desc".to_string()), Matcher::UrlEncoded( @@ -311,7 +318,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let paginated_list = workos .directory_sync() diff --git a/src/mfa/operations/challenge_factor.rs b/src/mfa/operations/challenge_factor.rs index 6d17104..bd49eb4 100644 --- a/src/mfa/operations/challenge_factor.rs +++ b/src/mfa/operations/challenge_factor.rs @@ -102,7 +102,6 @@ impl ChallengeFactor for Mfa<'_> { #[cfg(test)] mod test { - use mockito::{self, mock}; use serde_json::json; use tokio; @@ -113,30 +112,34 @@ mod test { #[tokio::test] async fn it_calls_the_challenge_factor_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock( - "POST", - "/auth/factors/auth_factor_01FVYZ5QM8N98T9ME5BCB2BBMJ/challenge", - ) - .match_header("Authorization", "Bearer sk_example_123456789") - .match_body("{}") - .with_status(201) - .with_body( - json!({ - "object": "authentication_challenge", - "id": "auth_challenge_01FVYZWQTZQ5VB6BC5MPG2EYC5", - "authentication_factor_id": "auth_factor_01FVYZ5QM8N98T9ME5BCB2BBMJ", - "expires_at": "2022-02-15T15:36:53.279Z", - "created_at": "2022-02-15T15:26:53.274Z", - "updated_at": "2022-02-15T15:26:53.274Z" - }) - .to_string(), - ) - .create(); + let _mock = server + .mock( + "POST", + "/auth/factors/auth_factor_01FVYZ5QM8N98T9ME5BCB2BBMJ/challenge", + ) + .match_header("Authorization", "Bearer sk_example_123456789") + .match_body("{}") + .with_status(201) + .with_body( + json!({ + "object": "authentication_challenge", + "id": "auth_challenge_01FVYZWQTZQ5VB6BC5MPG2EYC5", + "authentication_factor_id": "auth_factor_01FVYZ5QM8N98T9ME5BCB2BBMJ", + "expires_at": "2022-02-15T15:36:53.279Z", + "created_at": "2022-02-15T15:26:53.274Z", + "updated_at": "2022-02-15T15:26:53.274Z" + }) + .to_string(), + ) + .create_async() + .await; let challenge = workos .mfa() @@ -157,30 +160,34 @@ mod test { #[tokio::test] async fn it_calls_the_challenge_factor_endpoint_with_an_sms_template() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock( - "POST", - "/auth/factors/auth_factor_01FVYZ5QM8N98T9ME5BCB2BBMJ/challenge", - ) - .match_header("Authorization", "Bearer sk_example_123456789") - .match_body(r#"{"sms_template":"Here's your one-time code: {{code}}"}"#) - .with_status(201) - .with_body( - json!({ - "object": "authentication_challenge", - "id": "auth_challenge_01FVYZWQTZQ5VB6BC5MPG2EYC5", - "authentication_factor_id": "auth_factor_01FVYZ5QM8N98T9ME5BCB2BBMJ", - "expires_at": "2022-02-15T15:36:53.279Z", - "created_at": "2022-02-15T15:26:53.274Z", - "updated_at": "2022-02-15T15:26:53.274Z" - }) - .to_string(), - ) - .create(); + let _mock = server + .mock( + "POST", + "/auth/factors/auth_factor_01FVYZ5QM8N98T9ME5BCB2BBMJ/challenge", + ) + .match_header("Authorization", "Bearer sk_example_123456789") + .match_body(r#"{"sms_template":"Here's your one-time code: {{code}}"}"#) + .with_status(201) + .with_body( + json!({ + "object": "authentication_challenge", + "id": "auth_challenge_01FVYZWQTZQ5VB6BC5MPG2EYC5", + "authentication_factor_id": "auth_factor_01FVYZ5QM8N98T9ME5BCB2BBMJ", + "expires_at": "2022-02-15T15:36:53.279Z", + "created_at": "2022-02-15T15:26:53.274Z", + "updated_at": "2022-02-15T15:26:53.274Z" + }) + .to_string(), + ) + .create_async() + .await; let challenge = workos .mfa() diff --git a/src/mfa/operations/enroll_factor.rs b/src/mfa/operations/enroll_factor.rs index 94e5220..75952cc 100644 --- a/src/mfa/operations/enroll_factor.rs +++ b/src/mfa/operations/enroll_factor.rs @@ -149,7 +149,6 @@ impl EnrollFactor for Mfa<'_> { #[cfg(test)] mod test { use matches::assert_matches; - use mockito::{self, mock}; use serde_json::json; use tokio; @@ -160,12 +159,14 @@ mod test { #[tokio::test] async fn it_calls_the_enroll_factor_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("POST", "/auth/factors/enroll") + let _mock = server.mock("POST", "/auth/factors/enroll") .match_header("Authorization", "Bearer sk_example_123456789") .match_body(r#"{"type":"totp","totp_user":"alan.turing@foo-corp.com","totp_issuer":"Foo Corp"}"#) .with_status(201) @@ -184,7 +185,7 @@ mod test { }) .to_string(), ) - .create(); + .create_async().await; let factor = workos .mfa() @@ -203,12 +204,15 @@ mod test { #[tokio::test] async fn it_returns_an_error_when_the_phone_number_is_invalid() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("POST", "/auth/factors/enroll") + let _mock = server + .mock("POST", "/auth/factors/enroll") .match_header("Authorization", "Bearer sk_example_123456789") .match_body(r#"{"type":"sms","phone_number":"73"}"#) .with_status(422) @@ -219,7 +223,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let result = workos .mfa() diff --git a/src/mfa/operations/verify_challenge.rs b/src/mfa/operations/verify_challenge.rs index 34f1c26..e6b33be 100644 --- a/src/mfa/operations/verify_challenge.rs +++ b/src/mfa/operations/verify_challenge.rs @@ -94,7 +94,6 @@ impl VerifyChallenge for Mfa<'_> { #[cfg(test)] mod test { - use mockito::{self, mock}; use serde_json::json; use tokio; @@ -105,33 +104,37 @@ mod test { #[tokio::test] async fn it_calls_the_verify_challenge_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock( - "POST", - "/auth/challenges/auth_challenge_01FVYZWQTZQ5VB6BC5MPG2EYC5/verify", - ) - .match_header("Authorization", "Bearer sk_example_123456789") - .match_body(r#"{"code":"123456"}"#) - .with_status(201) - .with_body( - json!({ - "challenge": { - "object": "authentication_challenge", - "id": "auth_challenge_01FVYZWQTZQ5VB6BC5MPG2EYC5", - "created_at": "2022-02-15T15:26:53.274Z", - "updated_at": "2022-02-15T15:26:53.274Z", - "expires_at": "2022-02-15T15:36:53.279Z", - "authentication_factor_id": "auth_factor_01FVYZ5QM8N98T9ME5BCB2BBMJ" - }, - "valid": true - }) - .to_string(), - ) - .create(); + let _mock = server + .mock( + "POST", + "/auth/challenges/auth_challenge_01FVYZWQTZQ5VB6BC5MPG2EYC5/verify", + ) + .match_header("Authorization", "Bearer sk_example_123456789") + .match_body(r#"{"code":"123456"}"#) + .with_status(201) + .with_body( + json!({ + "challenge": { + "object": "authentication_challenge", + "id": "auth_challenge_01FVYZWQTZQ5VB6BC5MPG2EYC5", + "created_at": "2022-02-15T15:26:53.274Z", + "updated_at": "2022-02-15T15:26:53.274Z", + "expires_at": "2022-02-15T15:36:53.279Z", + "authentication_factor_id": "auth_factor_01FVYZ5QM8N98T9ME5BCB2BBMJ" + }, + "valid": true + }) + .to_string(), + ) + .create_async() + .await; let verify = workos .mfa() diff --git a/src/organizations/operations/create_organization.rs b/src/organizations/operations/create_organization.rs index 80e1f20..efbf931 100644 --- a/src/organizations/operations/create_organization.rs +++ b/src/organizations/operations/create_organization.rs @@ -98,7 +98,6 @@ impl CreateOrganization for Organizations<'_> { #[cfg(test)] mod test { - use mockito::{self, mock}; use serde_json::json; use tokio; @@ -109,12 +108,15 @@ mod test { #[tokio::test] async fn it_calls_the_create_organization_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("POST", "/organizations") + let _mock = server + .mock("POST", "/organizations") .match_header("Authorization", "Bearer sk_example_123456789") .with_status(201) .with_body( @@ -135,7 +137,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let organization = workos .organizations() diff --git a/src/organizations/operations/delete_organization.rs b/src/organizations/operations/delete_organization.rs index 75b360e..9cd5b8f 100644 --- a/src/organizations/operations/delete_organization.rs +++ b/src/organizations/operations/delete_organization.rs @@ -78,7 +78,6 @@ impl DeleteOrganization for Organizations<'_> { #[cfg(test)] mod test { - use mockito::{self, mock}; use tokio; use super::*; @@ -87,15 +86,19 @@ mod test { #[tokio::test] async fn it_calls_the_delete_organization_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("DELETE", "/organizations/org_01EHZNVPK3SFK441A1RGBFSHRT") + let _mock = server + .mock("DELETE", "/organizations/org_01EHZNVPK3SFK441A1RGBFSHRT") .match_header("Authorization", "Bearer sk_example_123456789") .with_status(202) - .create(); + .create_async() + .await; let result = workos .organizations() diff --git a/src/organizations/operations/get_organization.rs b/src/organizations/operations/get_organization.rs index 209572a..a3dedf6 100644 --- a/src/organizations/operations/get_organization.rs +++ b/src/organizations/operations/get_organization.rs @@ -71,7 +71,6 @@ impl GetOrganization for Organizations<'_> { #[cfg(test)] mod test { - use mockito::{self, mock}; use serde_json::json; use tokio; @@ -81,12 +80,15 @@ mod test { #[tokio::test] async fn it_calls_the_get_organization_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/organizations/org_01EHZNVPK3SFK441A1RGBFSHRT") + let _mock = server + .mock("GET", "/organizations/org_01EHZNVPK3SFK441A1RGBFSHRT") .match_header("Authorization", "Bearer sk_example_123456789") .with_status(200) .with_body( @@ -112,7 +114,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let organization = workos .organizations() diff --git a/src/organizations/operations/list_organizations.rs b/src/organizations/operations/list_organizations.rs index 89ce643..ffa2a36 100644 --- a/src/organizations/operations/list_organizations.rs +++ b/src/organizations/operations/list_organizations.rs @@ -97,7 +97,7 @@ impl ListOrganizations for Organizations<'_> { #[cfg(test)] mod test { - use mockito::{self, mock, Matcher}; + use mockito::Matcher; use serde_json::json; use tokio; @@ -108,12 +108,15 @@ mod test { #[tokio::test] async fn it_calls_the_list_organizations_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/organizations") + let _mock = server + .mock("GET", "/organizations") .match_query(Matcher::UrlEncoded("order".to_string(), "desc".to_string())) .match_header("Authorization", "Bearer sk_example_123456789") .with_status(200) @@ -148,7 +151,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let paginated_list = workos .organizations() @@ -164,12 +168,15 @@ mod test { #[tokio::test] async fn it_calls_the_list_organizations_endpoint_with_the_domain() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/organizations") + let _mock = server + .mock("GET", "/organizations") .match_query(Matcher::AllOf(vec![ Matcher::UrlEncoded("order".to_string(), "desc".to_string()), Matcher::UrlEncoded("domains[]".to_string(), "foo-corp.com".to_string()), @@ -202,7 +209,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let paginated_list = workos .organizations() diff --git a/src/organizations/operations/update_organization.rs b/src/organizations/operations/update_organization.rs index 397c96d..28db8bb 100644 --- a/src/organizations/operations/update_organization.rs +++ b/src/organizations/operations/update_organization.rs @@ -106,7 +106,6 @@ impl UpdateOrganization for Organizations<'_> { #[cfg(test)] mod test { - use mockito::{self, mock}; use serde_json::json; use tokio; @@ -117,12 +116,15 @@ mod test { #[tokio::test] async fn it_calls_the_update_organization_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("PUT", "/organizations/org_01EHZNVPK3SFK441A1RGBFSHRT") + let _mock = server + .mock("PUT", "/organizations/org_01EHZNVPK3SFK441A1RGBFSHRT") .match_header("Authorization", "Bearer sk_example_123456789") .with_status(201) .with_body( @@ -143,7 +145,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let organization = workos .organizations() diff --git a/src/passwordless/operations/create_passwordless_session.rs b/src/passwordless/operations/create_passwordless_session.rs index 125eb60..89524e4 100644 --- a/src/passwordless/operations/create_passwordless_session.rs +++ b/src/passwordless/operations/create_passwordless_session.rs @@ -99,7 +99,6 @@ impl CreatePasswordlessSession for Passwordless<'_> { #[cfg(test)] mod test { - use mockito::{self, mock}; use serde_json::json; use tokio; @@ -110,12 +109,15 @@ mod test { #[tokio::test] async fn it_calls_the_create_passwordless_session_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("POST", "/passwordless/sessions") + let _mock = server + .mock("POST", "/passwordless/sessions") .match_header("Authorization", "Bearer sk_example_123456789") .match_body(r#"{"type":"MagicLink","email":"marcelina@foo-corp.com"}"#) .with_status(201) @@ -129,7 +131,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let passwordless_session = workos .passwordless() diff --git a/src/passwordless/operations/send_passwordless_session.rs b/src/passwordless/operations/send_passwordless_session.rs index c175064..05c8a46 100644 --- a/src/passwordless/operations/send_passwordless_session.rs +++ b/src/passwordless/operations/send_passwordless_session.rs @@ -73,7 +73,6 @@ impl SendPasswordlessSession for Passwordless<'_> { #[cfg(test)] mod test { use matches::assert_matches; - use mockito::{self, mock}; use serde_json::json; use tokio; @@ -84,19 +83,23 @@ mod test { #[tokio::test] async fn it_calls_the_send_passwordless_session_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock( - "POST", - "/passwordless/sessions/passwordless_session_01EG1BHJMVYMFBQYZTTC0N73CR/send", - ) - .match_header("Authorization", "Bearer sk_example_123456789") - .with_status(201) - .with_body(json!({ "success": true}).to_string()) - .create(); + let _mock = server + .mock( + "POST", + "/passwordless/sessions/passwordless_session_01EG1BHJMVYMFBQYZTTC0N73CR/send", + ) + .match_header("Authorization", "Bearer sk_example_123456789") + .with_status(201) + .with_body(json!({ "success": true}).to_string()) + .create_async() + .await; let result = workos .passwordless() diff --git a/src/sso/operations/delete_connection.rs b/src/sso/operations/delete_connection.rs index 42f4dd6..d90fa72 100644 --- a/src/sso/operations/delete_connection.rs +++ b/src/sso/operations/delete_connection.rs @@ -79,7 +79,6 @@ impl DeleteConnection for Sso<'_> { #[cfg(test)] mod test { use matches::assert_matches; - use mockito::{self, mock}; use tokio; use crate::sso::ConnectionId; @@ -89,15 +88,19 @@ mod test { #[tokio::test] async fn it_calls_the_delete_connection_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("DELETE", "/connections/conn_01E2NPPCT7XQ2MVVYDHWGK1WN4") + let _mock = server + .mock("DELETE", "/connections/conn_01E2NPPCT7XQ2MVVYDHWGK1WN4") .match_header("Authorization", "Bearer sk_example_123456789") .with_status(202) - .create(); + .create_async() + .await; let result = workos .sso() diff --git a/src/sso/operations/get_connection.rs b/src/sso/operations/get_connection.rs index 8dbe443..5f25373 100644 --- a/src/sso/operations/get_connection.rs +++ b/src/sso/operations/get_connection.rs @@ -72,7 +72,6 @@ impl GetConnection for Sso<'_> { #[cfg(test)] mod test { use matches::assert_matches; - use mockito::{self, mock}; use serde_json::json; use tokio; @@ -82,12 +81,15 @@ mod test { #[tokio::test] async fn it_calls_the_get_connection_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/connections/conn_01E4ZCR3C56J083X43JQXF3JK5") + let _mock = server + .mock("GET", "/connections/conn_01E4ZCR3C56J083X43JQXF3JK5") .match_header("Authorization", "Bearer sk_example_123456789") .with_status(200) .with_body( @@ -110,7 +112,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let connection = workos .sso() @@ -126,12 +129,15 @@ mod test { #[tokio::test] async fn it_returns_an_error_when_the_get_connection_endpoint_returns_unauthorized() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/connections/conn_01E4ZCR3C56J083X43JQXF3JK5") + let _mock = server + .mock("GET", "/connections/conn_01E4ZCR3C56J083X43JQXF3JK5") .match_header("Authorization", "Bearer sk_example_123456789") .with_status(401) .with_body( @@ -140,7 +146,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let result = workos .sso() diff --git a/src/sso/operations/get_profile.rs b/src/sso/operations/get_profile.rs index 2a08903..90f7226 100644 --- a/src/sso/operations/get_profile.rs +++ b/src/sso/operations/get_profile.rs @@ -60,7 +60,6 @@ impl GetProfile for Sso<'_> { #[cfg(test)] mod test { - use mockito::{self, mock}; use serde_json::json; use tokio; @@ -71,12 +70,15 @@ mod test { #[tokio::test] async fn it_calls_the_get_profile_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/sso/profile") + let _mock = server + .mock("GET", "/sso/profile") .match_header("Authorization", "Bearer 01DMEK0J53CVMC32CK5SE0KZ8Q") .with_status(200) .with_body( @@ -93,7 +95,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let profile = workos .sso() diff --git a/src/sso/operations/get_profile_and_token.rs b/src/sso/operations/get_profile_and_token.rs index ce0a88e..b8fcd93 100644 --- a/src/sso/operations/get_profile_and_token.rs +++ b/src/sso/operations/get_profile_and_token.rs @@ -135,7 +135,7 @@ impl GetProfileAndToken for Sso<'_> { #[cfg(test)] mod test { use matches::assert_matches; - use mockito::{self, mock, Matcher}; + use mockito::Matcher; use serde_json::json; use tokio; @@ -146,12 +146,15 @@ mod test { #[tokio::test] async fn it_calls_the_token_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("POST", "/sso/token") + let _mock = server + .mock("POST", "/sso/token") .match_body(Matcher::AllOf(vec![ Matcher::UrlEncoded("client_id".to_string(), "client_1234".to_string()), Matcher::UrlEncoded( @@ -179,7 +182,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let response = workos .sso() @@ -202,12 +206,15 @@ mod test { #[tokio::test] async fn it_returns_an_unauthorized_error_with_an_invalid_client() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("POST", "/sso/token") + let _mock = server + .mock("POST", "/sso/token") .with_status(400) .with_body( json!({ @@ -216,7 +223,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let result = workos .sso() @@ -231,12 +239,15 @@ mod test { #[tokio::test] async fn it_returns_an_unauthorized_error_with_an_unauthorized_client() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("POST", "/sso/token") + let _mock = server + .mock("POST", "/sso/token") .with_status(400) .with_body( json!({ @@ -245,7 +256,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let result = workos .sso() @@ -260,12 +272,15 @@ mod test { #[tokio::test] async fn it_returns_an_error_when_the_authorization_code_is_invalid() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("POST", "/sso/token") + let _mock = server + .mock("POST", "/sso/token") .with_status(400) .with_body( json!({ @@ -274,7 +289,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let result = workos .sso() diff --git a/src/sso/operations/list_connections.rs b/src/sso/operations/list_connections.rs index 45e707b..c1ab598 100644 --- a/src/sso/operations/list_connections.rs +++ b/src/sso/operations/list_connections.rs @@ -77,7 +77,7 @@ impl ListConnections for Sso<'_> { #[cfg(test)] mod test { - use mockito::{self, mock, Matcher}; + use mockito::Matcher; use serde_json::json; use tokio; @@ -88,12 +88,15 @@ mod test { #[tokio::test] async fn it_calls_the_list_connections_endpoint() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/connections") + let _mock = server + .mock("GET", "/connections") .match_query(Matcher::UrlEncoded("order".to_string(), "desc".to_string())) .match_header("Authorization", "Bearer sk_example_123456789") .with_status(200) @@ -128,7 +131,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let paginated_list = workos .sso() @@ -144,12 +148,15 @@ mod test { #[tokio::test] async fn it_calls_the_list_connections_endpoint_with_the_connection_type() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/connections") + let _mock = server + .mock("GET", "/connections") .match_query(Matcher::UrlEncoded( "connection_type".to_string(), "OktaSAML".to_string(), @@ -177,7 +184,8 @@ mod test { }) .to_string(), ) - .create(); + .create_async() + .await; let paginated_list = workos .sso() diff --git a/src/workos.rs b/src/workos.rs index 8515833..de82121 100644 --- a/src/workos.rs +++ b/src/workos.rs @@ -113,8 +113,6 @@ impl<'a> WorkOsBuilder<'a> { #[cfg(test)] mod test { - use mockito::mock; - use super::*; #[test] @@ -141,19 +139,23 @@ mod test { #[tokio::test] async fn it_sets_the_user_agent_header_on_the_client() { + let mut server = mockito::Server::new_async().await; + let workos = WorkOs::builder(&ApiKey::from("sk_example_123456789")) - .base_url(&mockito::server_url()) + .base_url(&server.url()) .unwrap() .build(); - let _mock = mock("GET", "/health") + let _mock = server + .mock("GET", "/health") .match_header( "User-Agent", concat!("workos-rust/", env!("CARGO_PKG_VERSION")), ) .with_status(200) .with_body("User-Agent correctly set") - .create(); + .create_async() + .await; let url = workos.base_url().join("/health").unwrap(); let response = workos.client().get(url).send().await.unwrap();