File: org_installations_test.rs

package info (click to toggle)
rust-octocrab 0.43.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,532 kB
  • sloc: makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,631 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Tests for calls to the /orgs/{org}/installation endpoint.
mod mock_error;

use mock_error::setup_error_handler;
use octocrab::models::{Author, Installation, InstallationId};
use octocrab::Octocrab;
use wiremock::{
    matchers::{method, path},
    Mock, MockServer, ResponseTemplate,
};

async fn setup_api(template: ResponseTemplate) -> MockServer {
    let mock_server = MockServer::start().await;

    Mock::given(method("GET"))
        .and(path("/orgs/github/installation"))
        .respond_with(template)
        .mount(&mock_server)
        .await;
    setup_error_handler(
        &mock_server,
        "GET on /orgs/github/installation was not received",
    )
    .await;
    mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
    Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

#[tokio::test]
async fn should_return_org_installation() {
    let org_installation_response: Installation =
        serde_json::from_str(include_str!("resources/orgs_installation_event.json")).unwrap();
    let template = ResponseTemplate::new(200).set_body_json(&org_installation_response);
    let mock_server = setup_api(template).await;
    let client = setup_octocrab(&mock_server.uri());

    let result = client.apps().get_org_installation("github").await;

    assert!(
        result.is_ok(),
        "expected successful result, got error: {:#?}",
        result
    );

    let Installation {
        id: installation_id,
        account: Author { login, .. },
        ..
    } = result.unwrap();
    {
        assert_eq!(installation_id, InstallationId(1));
        assert_eq!(login, "github");
    }
}