Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use post request and correct content type #1

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Cargo.lock

# Auth
user-auth.json
user-credentials.json
4 changes: 4 additions & 0 deletions src/query/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ impl Queryable<NoAuthentication, ResponseDataWrapper<UserAuth>> for AuthType {
fn body(&self, _: &NoAuthentication) -> Option<serde_json::Result<Vec<u8>>> {
Some(serde_json::to_vec(self))
}

fn method(&self, _state: &NoAuthentication) -> racal::RequestMethod {
racal::RequestMethod::Post
}
}

/// Adds an user to the blocked users list
Expand Down
9 changes: 8 additions & 1 deletion tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Something's funky with checking if these are used or not.
#![allow(dead_code)]
use chilloutvr::{
api_client::{ApiConfiguration, AuthenticatedCVR},
api_client::{ApiConfiguration, AuthenticatedCVR, UnauthenticatedCVR},
model::{ResponseDataWrapper, UserAuth},
query::SavedLoginCredentials,
};
Expand Down Expand Up @@ -39,3 +39,10 @@ pub fn api_client() -> AuthenticatedCVR {
)
.unwrap()
}

pub fn unauthenticated_api_client() -> UnauthenticatedCVR {
UnauthenticatedCVR::new(
ApiConfiguration::new(USER_AGENT.to_owned())
)
.unwrap()
}
40 changes: 40 additions & 0 deletions tests/login.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#![cfg(feature = "http_client")]

use chilloutvr::{
api_client::{ApiClient, ApiError},
query::AuthType,
};

mod common;

#[tokio::test]
#[ignore]
async fn login() -> Result<(), ApiError> {
let client = common::unauthenticated_api_client();

/*
example credentials file:

{
"auth_type": "loginProfile",
"username": "[email protected]",
"password": "hunter2"
}

*/

let credentials = serde_json::from_slice::<AuthType>(
&std::fs::read("user-credentials.json").expect(
"must have a prepared `user-credentials.json` file for live API testing",
),
)
.expect("`user-credentials.json` file to parse into auth type");

let results = client.query(credentials).await?.data;

dbg!(&results);

assert!(!results.access_key.is_empty());

Ok(())
}
Loading