gitlab 0.1902.0

Gitlab API client.
Documentation
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use derive_builder::Builder;

use crate::api::endpoint_prelude::*;

/// Block a user.
///
/// Blocking a user prevents them from logging in or accessing the instance
/// while preserving their data, and frees up a license seat.
#[derive(Debug, Builder, Clone)]
pub struct BlockUser {
    /// The user to block.
    user: u64,
}

impl BlockUser {
    /// Create a builder for the endpoint.
    pub fn builder() -> BlockUserBuilder {
        BlockUserBuilder::default()
    }
}

impl Endpoint for BlockUser {
    fn method(&self) -> Method {
        Method::POST
    }

    fn endpoint(&self) -> Cow<'static, str> {
        format!("users/{}/block", self.user).into()
    }
}

#[cfg(test)]
mod tests {
    use http::Method;

    use crate::api::users::block::{BlockUser, BlockUserBuilderError};
    use crate::api::{self, Query};
    use crate::test::client::{ExpectedUrl, SingleTestClient};

    #[test]
    fn user_is_necessary() {
        let err = BlockUser::builder().build().unwrap_err();
        crate::test::assert_missing_field!(err, BlockUserBuilderError, "user");
    }

    #[test]
    fn user_is_sufficient() {
        BlockUser::builder().user(1).build().unwrap();
    }

    #[test]
    fn endpoint() {
        let endpoint = ExpectedUrl::builder()
            .method(Method::POST)
            .endpoint("users/1/block")
            .build()
            .unwrap();
        let client = SingleTestClient::new_raw(endpoint, "");

        let endpoint = BlockUser::builder().user(1).build().unwrap();
        api::ignore(endpoint).query(&client).unwrap();
    }
}