gitlab/api/groups/
unshare.rs

1// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4// option. This file may not be copied, modified, or distributed
5// except according to those terms.
6
7use derive_builder::Builder;
8
9use crate::api::common::NameOrId;
10use crate::api::endpoint_prelude::*;
11
12/// Unshare a group from another group.
13#[derive(Debug, Builder, Clone)]
14pub struct UnshareGroup<'a> {
15    /// The ID or URL-encoded path of the group
16    #[builder(setter(into))]
17    id: NameOrId<'a>,
18    /// The ID of the group to unlink sharing with.
19    group_id: u64,
20}
21
22impl<'a> UnshareGroup<'a> {
23    /// Create a builder for the endpoint.
24    pub fn builder() -> UnshareGroupBuilder<'a> {
25        UnshareGroupBuilder::default()
26    }
27}
28
29impl Endpoint for UnshareGroup<'_> {
30    fn method(&self) -> Method {
31        Method::DELETE
32    }
33
34    fn endpoint(&self) -> Cow<'static, str> {
35        format!("groups/{}/share/{}", self.id, self.group_id).into()
36    }
37}
38
39#[cfg(test)]
40mod tests {
41    use http::Method;
42
43    use crate::api::groups::{UnshareGroup, UnshareGroupBuilderError};
44    use crate::api::{self, Query};
45    use crate::test::client::{ExpectedUrl, SingleTestClient};
46
47    #[test]
48    fn all_parameters_are_needed() {
49        let err = UnshareGroup::builder().build().unwrap_err();
50        crate::test::assert_missing_field!(err, UnshareGroupBuilderError, "id");
51    }
52
53    #[test]
54    fn id_is_necessary() {
55        let err = UnshareGroup::builder().group_id(1).build().unwrap_err();
56        crate::test::assert_missing_field!(err, UnshareGroupBuilderError, "id");
57    }
58
59    #[test]
60    fn group_id_is_necessary() {
61        let err = UnshareGroup::builder().id(1).build().unwrap_err();
62        crate::test::assert_missing_field!(err, UnshareGroupBuilderError, "group_id");
63    }
64
65    #[test]
66    fn sufficient_parameters() {
67        UnshareGroup::builder().id(1).group_id(1).build().unwrap();
68    }
69
70    #[test]
71    fn endpoint() {
72        let endpoint = ExpectedUrl::builder()
73            .method(Method::DELETE)
74            .endpoint("groups/group%2Fsubgroup/share/1")
75            .build()
76            .unwrap();
77        let client = SingleTestClient::new_raw(endpoint, "");
78
79        let endpoint = UnshareGroup::builder()
80            .id("group/subgroup")
81            .group_id(1)
82            .build()
83            .unwrap();
84        api::ignore(endpoint).query(&client).unwrap();
85    }
86}