-
-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changing the user name from required to optional parameter (#650)
Changing the user name parameter from required to optional following the official API guidelines. See https://docs.github.com/en/rest/users/users?apiVersion=2022-11-28 for more
- Loading branch information
Showing
3 changed files
with
91 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"login": "octocat", | ||
"id": 583231, | ||
"node_id": "MDQ6VXNlcjU4MzIzMQ==", | ||
"avatar_url": "https://avatars.githubusercontent.com/u/583231?v=4", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/octocat", | ||
"html_url": "https://github.com/octocat", | ||
"followers_url": "https://api.github.com/users/octocat/followers", | ||
"following_url": "https://api.github.com/users/octocat/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions", | ||
"organizations_url": "https://api.github.com/users/octocat/orgs", | ||
"repos_url": "https://api.github.com/users/octocat/repos", | ||
"events_url": "https://api.github.com/users/octocat/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/octocat/received_events", | ||
"type": "User", | ||
"site_admin": false, | ||
"name": null, | ||
"company": "@github", | ||
"blog": "https://github.blog", | ||
"location": "San Francisco", | ||
"email": null, | ||
"hireable": null, | ||
"bio": null, | ||
"twitter_username": null, | ||
"public_repos": 8, | ||
"public_gists": 8, | ||
"followers": 13802, | ||
"following": 9, | ||
"created_at": "2011-01-25T18:44:36Z", | ||
"updated_at": "2024-05-22T11:18:34Z" | ||
} |
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,56 @@ | ||
/// Tests API calls related to check runs of a specific commit. | ||
mod mock_error; | ||
use mock_error::setup_error_handler; | ||
use octocrab::models::UserProfile; | ||
use octocrab::{Error, Octocrab}; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::{json, Value}; | ||
use wiremock::{ | ||
matchers::{method, path}, | ||
Mock, MockServer, ResponseTemplate, | ||
}; | ||
|
||
fn setup_octocrab(uri: &str) -> Octocrab { | ||
Octocrab::builder().base_uri(uri).unwrap().build().unwrap() | ||
} | ||
|
||
async fn setup_api(template: ResponseTemplate) -> MockServer { | ||
let mock_server = MockServer::start().await; | ||
|
||
let mocked_path = "/users/some-user"; | ||
|
||
Mock::given(method("GET")) | ||
.and(path(mocked_path)) | ||
.respond_with(template) | ||
.mount(&mock_server) | ||
.await; | ||
setup_error_handler( | ||
&mock_server, | ||
&format!("GET on {mocked_path} was not received"), | ||
) | ||
.await; | ||
mock_server | ||
} | ||
|
||
#[tokio::test] | ||
async fn should_return_desirialized_user() { | ||
let mocked_response: UserProfile = | ||
serde_json::from_str(include_str!("resources/user_data.json")).unwrap(); | ||
let template = ResponseTemplate::new(200).set_body_json(&mocked_response); | ||
let mock_server = setup_api(template).await; | ||
let client = setup_octocrab(&mock_server.uri()); | ||
let result = client.users("some-user").profile().await; | ||
|
||
assert!( | ||
result.is_ok(), | ||
"expected successful result, got error: {:#?}", | ||
result | ||
); | ||
|
||
let user = result.unwrap(); | ||
|
||
{ | ||
assert_eq!("octocat", user.login); | ||
assert_eq!(None, user.name.as_deref()); | ||
} | ||
} |