Skip to content

Commit 4555134

Browse files
committed
add wp_com_e2e package
1 parent 666a5d5 commit 4555134

File tree

7 files changed

+229
-0
lines changed

7 files changed

+229
-0
lines changed

Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ members = [
44
"wp_api_integration_tests",
55
"wp_api_integration_tests_backend",
66
"wp_cli",
7+
"wp_com_e2e",
78
"wp_contextual",
89
"wp_derive",
910
"wp_derive_request_builder",

wp_com_e2e/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "wp_com_e2e"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
anyhow = { workspace = true }
8+
async-trait = { workspace = true }
9+
clap = { workspace = true, features = ["derive", "env"] }
10+
colored = { workspace = true }
11+
csv = { workspace = true }
12+
futures = { workspace = true }
13+
serde = { workspace = true, features = ["derive"] }
14+
serde_json = { workspace = true }
15+
tokio = { workspace = true, features = ["full"] }
16+
tokio-stream = { workspace = true }
17+
wp_api = { path = "../wp_api", features = [ "reqwest-request-executor" ] }
18+
19+
[[bin]]
20+
name = "wp_com_e2e"

wp_com_e2e/src/main.rs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
use anyhow::Result;
2+
use async_trait::async_trait;
3+
use clap::{Parser, Subcommand};
4+
use oauth2_tests::Oauth2Test;
5+
use std::sync::Arc;
6+
use support_eligibility_test::SupportEligibilityTest;
7+
use support_tickets_test::SupportTicketsTest;
8+
use wp_api::{
9+
WpApiClientDelegate, WpAppNotifier,
10+
auth::{WpAuthentication, WpAuthenticationProvider},
11+
middleware::WpApiMiddlewarePipeline,
12+
reqwest_request_executor::ReqwestRequestExecutor,
13+
wp_com::client::WpComApiClient,
14+
};
15+
16+
mod oauth2_tests;
17+
mod support_eligibility_test;
18+
mod support_tickets_test;
19+
20+
#[derive(Parser)]
21+
#[command(author, version, about, long_about = None)]
22+
struct Cli {
23+
#[command(subcommand)]
24+
command: Commands,
25+
}
26+
27+
#[derive(Subcommand)]
28+
enum Commands {
29+
Test {
30+
#[arg(short = 't', long = "token", env = "WP_COM_API_KEY")]
31+
token: String,
32+
},
33+
}
34+
35+
#[async_trait]
36+
trait Testable {
37+
async fn test(&self) -> Result<(), anyhow::Error>;
38+
}
39+
40+
#[derive(Debug)]
41+
pub struct EmptyAppNotifier;
42+
43+
#[async_trait]
44+
impl WpAppNotifier for EmptyAppNotifier {
45+
async fn requested_with_invalid_authentication(&self) {
46+
// no-op
47+
}
48+
}
49+
50+
#[tokio::main]
51+
async fn main() -> Result<(), anyhow::Error> {
52+
let cli = Cli::parse();
53+
54+
match cli.command {
55+
Commands::Test { token } => {
56+
let delegate = WpApiClientDelegate {
57+
auth_provider: WpAuthenticationProvider::static_with_auth(
58+
WpAuthentication::Bearer {
59+
token: token.clone(),
60+
},
61+
)
62+
.into(),
63+
request_executor: Arc::new(ReqwestRequestExecutor::default()),
64+
middleware_pipeline: Arc::new(WpApiMiddlewarePipeline::default()),
65+
app_notifier: Arc::new(EmptyAppNotifier),
66+
};
67+
68+
let client = WpComApiClient::new(delegate);
69+
70+
Oauth2Test {
71+
client: &client,
72+
token: &token,
73+
}
74+
.test()
75+
.await?;
76+
SupportTicketsTest { client: &client }.test().await?;
77+
SupportEligibilityTest { client: &client }.test().await?;
78+
}
79+
}
80+
81+
Ok(())
82+
}

wp_com_e2e/src/oauth2_tests.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use anyhow::{Ok, Result};
2+
use async_trait::async_trait;
3+
use wp_api::wp_com::{client::WpComApiClient, oauth2::TokenValidationParameters};
4+
5+
use crate::Testable;
6+
7+
pub struct Oauth2Test<'a> {
8+
pub token: &'a String,
9+
pub client: &'a WpComApiClient,
10+
}
11+
12+
#[async_trait]
13+
impl Testable for Oauth2Test<'_> {
14+
async fn test(&self) -> Result<(), anyhow::Error> {
15+
println!("== OAuth 2 Token Test ==");
16+
self.client
17+
.oauth2()
18+
.fetch_info(&TokenValidationParameters {
19+
client_id: "11".to_string(),
20+
token: self.token.clone(),
21+
})
22+
.await?;
23+
println!("✅ Get OAuth 2 Token Info");
24+
25+
Ok(())
26+
}
27+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use anyhow::{Ok, Result};
2+
use async_trait::async_trait;
3+
use wp_api::wp_com::client::WpComApiClient;
4+
5+
use crate::Testable;
6+
7+
pub struct SupportEligibilityTest<'a> {
8+
pub client: &'a WpComApiClient,
9+
}
10+
11+
#[async_trait]
12+
impl Testable for SupportEligibilityTest<'_> {
13+
async fn test(&self) -> Result<(), anyhow::Error> {
14+
println!("== Support Eligibility Test ==");
15+
self.client
16+
.support_eligibility()
17+
.get_support_eligibility()
18+
.await?;
19+
println!("✅ Get Support Eligibility");
20+
21+
Ok(())
22+
}
23+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use anyhow::{Ok, Result};
2+
use async_trait::async_trait;
3+
use wp_api::wp_com::{
4+
client::WpComApiClient,
5+
support_tickets::{AddMessageToSupportConversationParams, CreateSupportTicketParams},
6+
};
7+
8+
use crate::Testable;
9+
10+
pub struct SupportTicketsTest<'a> {
11+
pub client: &'a WpComApiClient,
12+
}
13+
14+
#[async_trait]
15+
impl Testable for SupportTicketsTest<'_> {
16+
async fn test(&self) -> Result<(), anyhow::Error> {
17+
println!("== Support Tickets Test ==");
18+
let new_conversation = self
19+
.client
20+
.support_tickets()
21+
.create_support_ticket(&CreateSupportTicketParams {
22+
subject: "Mobile Support Test Message".to_string(),
23+
message: "This is a test – it can be deleted without replying.".to_string(),
24+
application: "jetpack".to_string(),
25+
wpcom_site_id: None,
26+
tags: vec!["jetpack_mobile".to_string(), "test".to_string()],
27+
attachments: vec![],
28+
})
29+
.await?
30+
.data;
31+
println!("✅ Create Conversation");
32+
33+
self.client
34+
.support_tickets()
35+
.add_message_to_support_conversation(
36+
&new_conversation.id,
37+
&AddMessageToSupportConversationParams {
38+
message: "Test Message".to_string(),
39+
attachments: vec![],
40+
},
41+
)
42+
.await?;
43+
println!("✅ Add Message to Conversation");
44+
45+
self.client
46+
.support_tickets()
47+
.get_support_conversation(&new_conversation.id)
48+
.await?;
49+
println!("✅ Fetch Conversation");
50+
51+
self.client
52+
.support_tickets()
53+
.get_support_conversation_list()
54+
.await?;
55+
println!("✅ Fetch Conversation List");
56+
57+
Ok(())
58+
}
59+
}

0 commit comments

Comments
 (0)