gitlab/api/projects/pages/
unpublish.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/// Remove Pages.
13#[derive(Debug, Builder, Clone)]
14pub struct UnpublishPages<'a> {
15    /// The ID or URL-encoded path of the project.
16    #[builder(setter(into))]
17    project: NameOrId<'a>,
18}
19
20impl<'a> UnpublishPages<'a> {
21    /// Create a builder for the endpoint.
22    pub fn builder() -> UnpublishPagesBuilder<'a> {
23        UnpublishPagesBuilder::default()
24    }
25}
26
27impl Endpoint for UnpublishPages<'_> {
28    fn method(&self) -> Method {
29        Method::DELETE
30    }
31
32    fn endpoint(&self) -> Cow<'static, str> {
33        format!("projects/{}/pages", self.project).into()
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use http::Method;
40
41    use crate::api::projects::pages::{UnpublishPages, UnpublishPagesBuilderError};
42    use crate::api::{self, Query};
43    use crate::test::client::{ExpectedUrl, SingleTestClient};
44
45    #[test]
46    fn project_is_required() {
47        let err = UnpublishPages::builder().build().unwrap_err();
48        crate::test::assert_missing_field!(err, UnpublishPagesBuilderError, "project");
49    }
50
51    #[test]
52    fn project_is_sufficient() {
53        UnpublishPages::builder().project("blah").build().unwrap();
54    }
55
56    #[test]
57    fn endpoint() {
58        let endpoint = ExpectedUrl::builder()
59            .method(Method::DELETE)
60            .endpoint("projects/blah/pages")
61            .build()
62            .unwrap();
63        let client = SingleTestClient::new_raw(endpoint, "");
64
65        let endpoint = UnpublishPages::builder().project("blah").build().unwrap();
66        api::ignore(endpoint).query(&client).unwrap();
67    }
68}