Skip to main content

redmine_api/api/
wiki_pages.rs

1//! Wiki Pages Rest API Endpoint definitions
2//!
3//! [Redmine Documentation](https://www.redmine.org/projects/redmine/wiki/Rest_WikiPages)
4//!
5//! - [X] project specific wiki page endpoint
6//! - [X] specific wiki page endpoint
7//! - [X] specific wiki page old version endpoint
8//! - [X] create or update wiki page endpoint
9//! - [X] delete wiki page endpoint
10//! - [ ] attachments
11//!
12//! The following endpoints always return 403 and are apparently not exposed in a usable way:
13//! - GetProjectWikiPageHistory
14//! - GetProjectWikiPageDiff
15//! - RenameProjectWikiPage
16//! - ProtectProjectWikiPage
17//! - AddAttachmentToProjectWikiPage
18
19use derive_builder::Builder;
20use reqwest::Method;
21use serde::Serialize;
22use std::borrow::Cow;
23
24use crate::api::attachments::Attachment;
25use crate::api::projects::ProjectEssentials;
26use crate::api::users::UserEssentials;
27use crate::api::{Endpoint, NoPagination, QueryParams, ReturnsJsonResponse};
28
29/// The types of associated data which can be fetched along with a wiki page
30#[derive(Debug, Clone)]
31pub enum WikiPageInclude {
32    /// Wiki Page Attachments
33    Attachments,
34}
35
36impl std::fmt::Display for WikiPageInclude {
37    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38        match self {
39            Self::Attachments => {
40                write!(f, "attachments")
41            }
42        }
43    }
44}
45
46/// The parent of a wiki page
47#[derive(Debug, Clone, PartialEq, Eq, Serialize, serde::Deserialize)]
48pub struct WikiPageParent {
49    /// title
50    pub title: String,
51}
52
53/// a type for wiki pages to use as an API return type for the list call
54///
55/// alternatively you can use your own type limited to the fields you need
56#[derive(Debug, Clone, PartialEq, Eq, Serialize, serde::Deserialize)]
57pub struct WikiPageEssentials {
58    /// title
59    pub title: String,
60    /// the parent of this page
61    #[serde(default, skip_serializing_if = "Option::is_none")]
62    pub parent: Option<WikiPageParent>,
63    /// the version number of the wiki page
64    pub version: u64,
65    /// the project this wiki page belongs to (Redmine 7.0 and later)
66    #[serde(default, skip_serializing_if = "Option::is_none")]
67    pub project: Option<ProjectEssentials>,
68    /// The time when this wiki page was created
69    #[serde(
70        serialize_with = "crate::api::serialize_rfc3339",
71        deserialize_with = "crate::api::deserialize_rfc3339"
72    )]
73    pub created_on: time::OffsetDateTime,
74    /// The time when this wiki page was last updated
75    #[serde(
76        serialize_with = "crate::api::serialize_rfc3339",
77        deserialize_with = "crate::api::deserialize_rfc3339"
78    )]
79    pub updated_on: time::OffsetDateTime,
80    /// wiki page attachments (only when include parameter is used)
81    #[serde(default, skip_serializing_if = "Option::is_none")]
82    pub attachments: Option<Vec<Attachment>>,
83    /// is the wiki page protected
84    #[serde(default, skip_serializing_if = "Option::is_none")]
85    pub protected: Option<bool>,
86}
87
88/// a type for wiki pages to use as an API return type
89///
90/// alternatively you can use your own type limited to the fields you need
91#[derive(Debug, Clone, PartialEq, Eq, Serialize, serde::Deserialize)]
92pub struct WikiPage {
93    /// title
94    pub title: String,
95    /// the parent of this page
96    #[serde(default, skip_serializing_if = "Option::is_none")]
97    pub parent: Option<WikiPageParent>,
98    /// author
99    #[serde(default, skip_serializing_if = "Option::is_none")]
100    pub author: Option<UserEssentials>,
101    /// the text body of the wiki page
102    pub text: String,
103    /// the version number of the wiki page
104    pub version: u64,
105    /// the comments supplied when saving this version of the page
106    pub comments: String,
107    /// the project this wiki page belongs to (Redmine 7.0 and later)
108    #[serde(default, skip_serializing_if = "Option::is_none")]
109    pub project: Option<ProjectEssentials>,
110    /// The time when this wiki page was created
111    #[serde(
112        serialize_with = "crate::api::serialize_rfc3339",
113        deserialize_with = "crate::api::deserialize_rfc3339"
114    )]
115    pub created_on: time::OffsetDateTime,
116    /// The time when this wiki page was last updated
117    #[serde(
118        serialize_with = "crate::api::serialize_rfc3339",
119        deserialize_with = "crate::api::deserialize_rfc3339"
120    )]
121    pub updated_on: time::OffsetDateTime,
122    /// wiki page attachments (only when include parameter is used)
123    #[serde(default, skip_serializing_if = "Option::is_none")]
124    pub attachments: Option<Vec<Attachment>>,
125    /// is the wiki page protected
126    #[serde(default, skip_serializing_if = "Option::is_none")]
127    pub protected: Option<bool>,
128}
129
130/// The endpoint for all wiki pages in a project
131#[derive(Debug, Clone, Builder)]
132#[builder(setter(strip_option))]
133pub struct ListProjectWikiPages<'a> {
134    /// project id or name as it appears in the URL
135    #[builder(setter(into))]
136    project_id_or_name: Cow<'a, str>,
137    /// Include associated data
138    #[builder(default)]
139    include: Option<Vec<WikiPageInclude>>,
140}
141
142impl ReturnsJsonResponse for ListProjectWikiPages<'_> {}
143impl NoPagination for ListProjectWikiPages<'_> {}
144
145impl<'a> ListProjectWikiPages<'a> {
146    /// Create a builder for the endpoint.
147    #[must_use]
148    pub fn builder() -> ListProjectWikiPagesBuilder<'a> {
149        ListProjectWikiPagesBuilder::default()
150    }
151}
152
153impl Endpoint for ListProjectWikiPages<'_> {
154    fn method(&self) -> Method {
155        Method::GET
156    }
157
158    fn endpoint(&self) -> Cow<'static, str> {
159        format!("projects/{}/wiki/index.json", self.project_id_or_name).into()
160    }
161
162    fn parameters(&self) -> QueryParams<'_> {
163        let mut params = QueryParams::default();
164        params.push_opt("include", self.include.as_ref());
165        params
166    }
167}
168
169/// The endpoint for a specific Redmine project wiki page
170#[derive(Debug, Clone, Builder)]
171#[builder(setter(strip_option))]
172pub struct GetProjectWikiPage<'a> {
173    /// the project id or name as it appears in the URL
174    #[builder(setter(into))]
175    project_id_or_name: Cow<'a, str>,
176    /// the title as it appears in the URL
177    #[builder(setter(into))]
178    title: Cow<'a, str>,
179    /// the types of associate data to include
180    #[builder(default)]
181    include: Option<Vec<WikiPageInclude>>,
182}
183
184impl ReturnsJsonResponse for GetProjectWikiPage<'_> {}
185impl NoPagination for GetProjectWikiPage<'_> {}
186
187impl<'a> GetProjectWikiPage<'a> {
188    /// Create a builder for the endpoint.
189    #[must_use]
190    pub fn builder() -> GetProjectWikiPageBuilder<'a> {
191        GetProjectWikiPageBuilder::default()
192    }
193}
194
195impl Endpoint for GetProjectWikiPage<'_> {
196    fn method(&self) -> Method {
197        Method::GET
198    }
199
200    fn endpoint(&self) -> Cow<'static, str> {
201        format!(
202            "projects/{}/wiki/{}.json",
203            self.project_id_or_name, self.title
204        )
205        .into()
206    }
207
208    fn parameters(&self) -> QueryParams<'_> {
209        let mut params = QueryParams::default();
210        params.push_opt("include", self.include.as_ref());
211        params
212    }
213}
214
215/// The endpoint for a specific Redmine project wiki page version
216#[derive(Debug, Clone, Builder)]
217#[builder(setter(strip_option))]
218pub struct GetProjectWikiPageVersion<'a> {
219    /// the project id or name as it appears in the URL
220    #[builder(setter(into))]
221    project_id_or_name: Cow<'a, str>,
222    /// the title as it appears in the URL
223    #[builder(setter(into))]
224    title: Cow<'a, str>,
225    /// the version
226    version: u64,
227    /// the types of associate data to include
228    #[builder(default)]
229    include: Option<Vec<WikiPageInclude>>,
230}
231
232impl ReturnsJsonResponse for GetProjectWikiPageVersion<'_> {}
233impl NoPagination for GetProjectWikiPageVersion<'_> {}
234
235impl<'a> GetProjectWikiPageVersion<'a> {
236    /// Create a builder for the endpoint.
237    #[must_use]
238    pub fn builder() -> GetProjectWikiPageVersionBuilder<'a> {
239        GetProjectWikiPageVersionBuilder::default()
240    }
241}
242
243impl Endpoint for GetProjectWikiPageVersion<'_> {
244    fn method(&self) -> Method {
245        Method::GET
246    }
247
248    fn endpoint(&self) -> Cow<'static, str> {
249        format!(
250            "projects/{}/wiki/{}/{}.json",
251            self.project_id_or_name, self.title, self.version,
252        )
253        .into()
254    }
255
256    fn parameters(&self) -> QueryParams<'_> {
257        let mut params = QueryParams::default();
258        params.push_opt("include", self.include.as_ref());
259        params
260    }
261}
262
263/// The endpoint to create or update a Redmine project wiki page
264#[derive(Debug, Clone, Builder, serde::Serialize, serde::Deserialize)]
265#[builder(setter(strip_option))]
266pub struct CreateOrUpdateProjectWikiPage<'a> {
267    /// the project id or name as it appears in the URL
268    #[serde(skip_serializing)]
269    #[builder(setter(into))]
270    project_id_or_name: Cow<'a, str>,
271    /// the title as it appears in the URL
272    #[serde(skip_serializing)]
273    #[builder(setter(into))]
274    title: Cow<'a, str>,
275    /// the version to update, if the version is not this a 409 Conflict is returned
276    #[serde(skip_serializing_if = "Option::is_none")]
277    #[builder(default)]
278    version: Option<u64>,
279    /// the body text of the page
280    #[builder(setter(into))]
281    text: Cow<'a, str>,
282    /// the comment for the update history
283    #[builder(setter(into))]
284    comments: Cow<'a, str>,
285    /// used when renaming or moving a page
286    #[serde(default, skip_serializing_if = "Option::is_none")]
287    #[builder(default)]
288    redirect_existing_links: Option<bool>,
289    /// is the wiki page the start page for the project
290    #[serde(default, skip_serializing_if = "Option::is_none")]
291    #[builder(default)]
292    is_start_page: Option<bool>,
293}
294
295impl<'a> CreateOrUpdateProjectWikiPage<'a> {
296    /// Create a builder for the endpoint.
297    #[must_use]
298    pub fn builder() -> CreateOrUpdateProjectWikiPageBuilder<'a> {
299        CreateOrUpdateProjectWikiPageBuilder::default()
300    }
301}
302
303impl Endpoint for CreateOrUpdateProjectWikiPage<'_> {
304    fn method(&self) -> Method {
305        Method::PUT
306    }
307
308    fn endpoint(&self) -> Cow<'static, str> {
309        format!(
310            "projects/{}/wiki/{}.json",
311            self.project_id_or_name, self.title
312        )
313        .into()
314    }
315
316    fn body(&self) -> Result<Option<(&'static str, Vec<u8>)>, crate::Error> {
317        Ok(Some((
318            "application/json",
319            serde_json::to_vec(&WikiPageWrapper::<CreateOrUpdateProjectWikiPage> {
320                wiki_page: (*self).to_owned(),
321            })?,
322        )))
323    }
324}
325
326/// The endpoint to delete a Redmine project wiki page
327#[derive(Debug, Clone, Builder)]
328#[builder(setter(strip_option))]
329pub struct DeleteProjectWikiPage<'a> {
330    /// the project id or name as it appears in the URL
331    #[builder(setter(into))]
332    project_id_or_name: Cow<'a, str>,
333    /// the title as it appears in the URL
334    #[builder(setter(into))]
335    title: Cow<'a, str>,
336    /// what to do with descendant pages: `null` (default) or `destroy`
337    #[builder(default)]
338    todo: Option<Cow<'a, str>>,
339    /// the id of the wiki page to reassign descendant pages to
340    #[builder(default)]
341    reassign_to_id: Option<u64>,
342}
343
344impl<'a> DeleteProjectWikiPage<'a> {
345    /// Create a builder for the endpoint.
346    #[must_use]
347    pub fn builder() -> DeleteProjectWikiPageBuilder<'a> {
348        DeleteProjectWikiPageBuilder::default()
349    }
350}
351
352impl Endpoint for DeleteProjectWikiPage<'_> {
353    fn method(&self) -> Method {
354        Method::DELETE
355    }
356
357    fn endpoint(&self) -> Cow<'static, str> {
358        format!(
359            "projects/{}/wiki/{}.json",
360            self.project_id_or_name, self.title
361        )
362        .into()
363    }
364
365    fn parameters(&self) -> QueryParams<'_> {
366        let mut params = QueryParams::default();
367        params.push_opt("todo", self.todo.as_ref());
368        params.push_opt("reassign_to_id", self.reassign_to_id);
369        params
370    }
371}
372
373/// The endpoint to delete a specific version of a Redmine project wiki page
374#[derive(Debug, Clone, Builder)]
375#[builder(setter(strip_option))]
376pub struct DeleteProjectWikiPageVersion<'a> {
377    /// the project id or name as it appears in the URL
378    #[builder(setter(into))]
379    project_id_or_name: Cow<'a, str>,
380    /// the title as it appears in the URL
381    #[builder(setter(into))]
382    title: Cow<'a, str>,
383    /// the version to delete
384    version: u64,
385}
386
387impl<'a> DeleteProjectWikiPageVersion<'a> {
388    /// Create a builder for the endpoint.
389    #[must_use]
390    pub fn builder() -> DeleteProjectWikiPageVersionBuilder<'a> {
391        DeleteProjectWikiPageVersionBuilder::default()
392    }
393}
394
395impl Endpoint for DeleteProjectWikiPageVersion<'_> {
396    fn method(&self) -> Method {
397        Method::DELETE
398    }
399
400    fn endpoint(&self) -> Cow<'static, str> {
401        format!(
402            "projects/{}/wiki/{}/{}/destroy_version.json",
403            self.project_id_or_name, self.title, self.version
404        )
405        .into()
406    }
407}
408
409/// The endpoint to get the annotated view of a Redmine project wiki page
410#[derive(Debug, Clone, Builder)]
411#[builder(setter(strip_option))]
412pub struct GetProjectWikiPageAnnotate<'a> {
413    /// the project id or name as it appears in the URL
414    #[builder(setter(into))]
415    project_id_or_name: Cow<'a, str>,
416    /// the title as it appears in the URL
417    #[builder(setter(into))]
418    title: Cow<'a, str>,
419    /// the version to annotate
420    version: u64,
421}
422
423impl<'a> GetProjectWikiPageAnnotate<'a> {
424    /// Create a builder for the endpoint.
425    #[must_use]
426    pub fn builder() -> GetProjectWikiPageAnnotateBuilder<'a> {
427        GetProjectWikiPageAnnotateBuilder::default()
428    }
429}
430
431impl NoPagination for GetProjectWikiPageAnnotate<'_> {}
432
433impl Endpoint for GetProjectWikiPageAnnotate<'_> {
434    fn method(&self) -> Method {
435        Method::GET
436    }
437
438    fn endpoint(&self) -> Cow<'static, str> {
439        format!(
440            "projects/{}/wiki/{}/annotate.json",
441            self.project_id_or_name, self.title
442        )
443        .into()
444    }
445
446    fn parameters(&self) -> QueryParams<'_> {
447        let mut params = QueryParams::default();
448        params.push("v", self.version);
449        params
450    }
451}
452
453/// The endpoint to export a Redmine project wiki page
454#[derive(Debug, Clone, Builder)]
455#[builder(setter(strip_option))]
456pub struct ExportProjectWikiPage<'a> {
457    /// the project id or name as it appears in the URL
458    #[builder(setter(into))]
459    project_id_or_name: Cow<'a, str>,
460    /// the title as it appears in the URL
461    #[builder(setter(into))]
462    title: Cow<'a, str>,
463    /// the version to export
464    #[builder(default)]
465    version: Option<u64>,
466}
467
468impl<'a> ExportProjectWikiPage<'a> {
469    /// Create a builder for the endpoint.
470    #[must_use]
471    pub fn builder() -> ExportProjectWikiPageBuilder<'a> {
472        ExportProjectWikiPageBuilder::default()
473    }
474}
475
476impl NoPagination for ExportProjectWikiPage<'_> {}
477
478impl Endpoint for ExportProjectWikiPage<'_> {
479    fn method(&self) -> Method {
480        Method::GET
481    }
482
483    fn endpoint(&self) -> Cow<'static, str> {
484        format!(
485            "projects/{}/wiki/{}/export.json",
486            self.project_id_or_name, self.title
487        )
488        .into()
489    }
490
491    fn parameters(&self) -> QueryParams<'_> {
492        let mut params = QueryParams::default();
493        params.push_opt("v", self.version);
494        params
495    }
496}
497
498/// helper struct for outer layers with a wiki_pages field holding the inner data
499#[derive(Debug, Clone, PartialEq, Eq, Serialize, serde::Deserialize)]
500pub struct WikiPagesWrapper<T> {
501    /// to parse JSON with wiki_pages key
502    pub wiki_pages: Vec<T>,
503}
504
505/// A lot of APIs in Redmine wrap their data in an extra layer, this is a
506/// helper struct for outer layers with a wiki_page field holding the inner data
507#[derive(Debug, Clone, PartialEq, Eq, Serialize, serde::Deserialize)]
508pub struct WikiPageWrapper<T> {
509    /// to parse JSON with an wiki_page key
510    pub wiki_page: T,
511}
512
513#[cfg(test)]
514pub(crate) mod test {
515    use crate::api::projects::{ListProjects, Project, ProjectsInclude};
516    use crate::api::test_helpers::with_project;
517
518    use super::*;
519    use pretty_assertions::assert_eq;
520    use std::error::Error;
521    use tokio::sync::RwLock;
522    use tracing_test::traced_test;
523
524    /// needed so we do not get 404s when listing while
525    /// creating/deleting or creating/updating/deleting
526    pub static PROJECT_WIKI_PAGE_LOCK: RwLock<()> = RwLock::const_new(());
527
528    /// title of the wiki page created by [`with_wiki_page`]
529    const TEST_WIKI_PAGE_TITLE: &str = "TestWikiPage";
530
531    /// creates a project with a wiki page with two versions and calls the
532    /// function with the project id
533    fn with_wiki_page<F>(name: &str, f: F) -> Result<(), Box<dyn Error>>
534    where
535        F: FnOnce(&crate::api::Redmine, u64) -> Result<(), Box<dyn Error>>,
536    {
537        with_project(name, |redmine, project_id, _name| {
538            let _w_project_wiki_pages = PROJECT_WIKI_PAGE_LOCK.blocking_write();
539            for (version, text) in [(None, "Test Content"), (Some(1), "Test Content Updates")] {
540                let mut builder = CreateOrUpdateProjectWikiPage::builder();
541                builder
542                    .project_id_or_name(project_id.to_string())
543                    .title(TEST_WIKI_PAGE_TITLE)
544                    .text(text)
545                    .comments("Unit test");
546                if let Some(version) = version {
547                    builder.version(version);
548                }
549                redmine.ignore_response_body(&builder.build()?)?;
550            }
551            f(redmine, project_id)
552        })
553    }
554
555    #[function_name::named]
556    #[traced_test]
557    #[test]
558    fn test_list_project_wiki_pages() -> Result<(), Box<dyn Error>> {
559        let name = format!("unittest_{}", function_name!());
560        with_wiki_page(&name, |redmine, project_id| {
561            let endpoint = ListProjectWikiPages::builder()
562                .project_id_or_name(project_id.to_string())
563                .build()?;
564            let WikiPagesWrapper { wiki_pages } =
565                redmine.json_response_body::<_, WikiPagesWrapper<WikiPageEssentials>>(&endpoint)?;
566            assert!(wiki_pages.iter().any(|p| p.title == TEST_WIKI_PAGE_TITLE));
567            Ok(())
568        })
569    }
570
571    /// this tests if any of the results contain a field we are not deserializing
572    ///
573    /// this will only catch fields we missed if they are part of the response but
574    /// it is better than nothing
575    #[function_name::named]
576    #[traced_test]
577    #[test]
578    fn test_completeness_wiki_page_essentials() -> Result<(), Box<dyn Error>> {
579        let name = format!("unittest_{}", function_name!());
580        with_wiki_page(&name, |redmine, _project_id| {
581            let endpoint = ListProjects::builder()
582                .include(vec![ProjectsInclude::EnabledModules])
583                .build()?;
584            let projects = redmine.json_response_body_all_pages_iter::<_, Project>(&endpoint);
585            let mut checked_projects = 0;
586            for project in projects {
587                let project = project?;
588                if !project
589                    .enabled_modules
590                    .is_some_and(|em| em.iter().any(|m| m.name == "wiki"))
591                {
592                    // skip projects where wiki is disabled
593                    continue;
594                }
595                let endpoint = ListProjectWikiPages::builder()
596                    .project_id_or_name(project.id.to_string())
597                    .include(vec![WikiPageInclude::Attachments])
598                    .build()?;
599                let Ok(WikiPagesWrapper { wiki_pages: values }) =
600                    redmine.json_response_body::<_, WikiPagesWrapper<serde_json::Value>>(&endpoint)
601                else {
602                    // TODO: some projects return a 404 for their wiki for unknown reasons even with an
603                    //       enabled wiki module. They also do not have a wiki tab so I assume
604                    //       it is intentional, they are not closed or archived either
605                    //
606                    //       Further analysis seems to indicate that this should not happen and is most
607                    //       likely an issue resulting from a database state from a buggy old version of
608                    //       Redmine
609                    continue;
610                };
611                checked_projects += 1;
612                for value in values {
613                    let o: WikiPageEssentials = serde_json::from_value(value.clone())?;
614                    let reserialized = serde_json::to_value(o)?;
615                    assert_eq!(value, reserialized);
616                }
617            }
618            assert!(checked_projects > 0);
619            Ok(())
620        })
621    }
622
623    #[function_name::named]
624    #[traced_test]
625    #[test]
626    fn test_get_project_wiki_page() -> Result<(), Box<dyn Error>> {
627        let name = format!("unittest_{}", function_name!());
628        with_wiki_page(&name, |redmine, project_id| {
629            let endpoint = GetProjectWikiPage::builder()
630                .project_id_or_name(project_id.to_string())
631                .title(TEST_WIKI_PAGE_TITLE)
632                .build()?;
633            let WikiPageWrapper { wiki_page } =
634                redmine.json_response_body::<_, WikiPageWrapper<WikiPage>>(&endpoint)?;
635            assert_eq!(wiki_page.version, 2);
636            Ok(())
637        })
638    }
639
640    /// this tests if any of the results contain a field we are not deserializing
641    ///
642    /// this will only catch fields we missed if they are part of the response but
643    /// it is better than nothing
644    #[function_name::named]
645    #[traced_test]
646    #[test]
647    fn test_completeness_wiki_page() -> Result<(), Box<dyn Error>> {
648        let name = format!("unittest_{}", function_name!());
649        with_wiki_page(&name, |redmine, _project_id| {
650            let endpoint = ListProjects::builder()
651                .include(vec![ProjectsInclude::EnabledModules])
652                .build()?;
653            let projects = redmine.json_response_body_all_pages_iter::<_, Project>(&endpoint);
654            let mut checked_pages = 0;
655            for project in projects {
656                let project = project?;
657                if !project
658                    .enabled_modules
659                    .is_some_and(|em| em.iter().any(|m| m.name == "wiki"))
660                {
661                    // skip projects where wiki is disabled
662                    continue;
663                }
664                let endpoint = ListProjectWikiPages::builder()
665                    .project_id_or_name(project.id.to_string())
666                    .include(vec![WikiPageInclude::Attachments])
667                    .build()?;
668                let Ok(WikiPagesWrapper { wiki_pages }) = redmine
669                    .json_response_body::<_, WikiPagesWrapper<WikiPageEssentials>>(&endpoint)
670                else {
671                    // TODO: some projects return a 404 for their wiki for unknown reasons even with an
672                    //       enabled wiki module. They also do not have a wiki tab so I assume
673                    //       it is intentional, they are not closed or archived either
674                    //
675                    //       Further analysis seems to indicate that this should not happen and is most
676                    //       likely an issue resulting from a database state from a buggy old version of
677                    //       Redmine
678                    continue;
679                };
680                checked_pages += 1;
681                for wiki_page in wiki_pages {
682                    let endpoint = GetProjectWikiPage::builder()
683                        .project_id_or_name(project.id.to_string())
684                        .title(wiki_page.title)
685                        .include(vec![WikiPageInclude::Attachments])
686                        .build()?;
687                    let WikiPageWrapper { wiki_page: value } = redmine
688                        .json_response_body::<_, WikiPageWrapper<serde_json::Value>>(&endpoint)?;
689                    let o: WikiPage = serde_json::from_value(value.clone())?;
690                    let reserialized = serde_json::to_value(o)?;
691                    assert_eq!(value, reserialized);
692                }
693            }
694            assert!(checked_pages > 0);
695            Ok(())
696        })
697    }
698
699    #[function_name::named]
700    #[traced_test]
701    #[test]
702    fn test_get_project_wiki_page_version() -> Result<(), Box<dyn Error>> {
703        let name = format!("unittest_{}", function_name!());
704        with_wiki_page(&name, |redmine, project_id| {
705            let endpoint = GetProjectWikiPageVersion::builder()
706                .project_id_or_name(project_id.to_string())
707                .title(TEST_WIKI_PAGE_TITLE)
708                .version(1)
709                .build()?;
710            let WikiPageWrapper { wiki_page } =
711                redmine.json_response_body::<_, WikiPageWrapper<WikiPage>>(&endpoint)?;
712            assert_eq!(wiki_page.version, 1);
713            assert_eq!(wiki_page.text, "Test Content");
714            Ok(())
715        })
716    }
717
718    #[function_name::named]
719    #[traced_test]
720    #[test]
721    fn test_create_update_and_delete_project_wiki_page() -> Result<(), Box<dyn Error>> {
722        let name = format!("unittest_{}", function_name!());
723        with_project(&name, |redmine, project_id, _name| {
724            let _w_project_wiki_pages = PROJECT_WIKI_PAGE_LOCK.blocking_write();
725            let project_id = project_id.to_string();
726            let endpoint = CreateOrUpdateProjectWikiPage::builder()
727                .project_id_or_name(project_id.as_str())
728                .title("CreateWikiPageTest")
729                .text("Test Content")
730                .comments("Create Page Test")
731                .build()?;
732            redmine.ignore_response_body(&endpoint)?;
733            let endpoint = CreateOrUpdateProjectWikiPage::builder()
734                .project_id_or_name(project_id.as_str())
735                .title("CreateWikiPageTest")
736                .text("Test Content Updates")
737                .version(1)
738                .comments("Update Page Test")
739                .build()?;
740            redmine.ignore_response_body(&endpoint)?;
741            let endpoint = DeleteProjectWikiPage::builder()
742                .project_id_or_name(project_id.as_str())
743                .title("CreateWikiPageTest")
744                .build()?;
745            redmine.ignore_response_body(&endpoint)?;
746            Ok(())
747        })
748    }
749
750    #[traced_test]
751    #[test]
752    fn test_wiki_page_lifecycle() -> Result<(), Box<dyn Error>> {
753        with_project("test_wiki_page_lifecycle", |redmine, project_id, _| {
754            tracing::debug!("Creating wiki page TestWikiPage");
755            let endpoint = CreateOrUpdateProjectWikiPage::builder()
756                .project_id_or_name(project_id.to_string())
757                .title("TestWikiPage")
758                .text("Test Content")
759                .comments("Create Page Test")
760                .build()?;
761            redmine.ignore_response_body(&endpoint)?;
762
763            tracing::debug!("Verifying existence, content and version of wiki page TestWikiPage");
764            let get_endpoint = GetProjectWikiPage::builder()
765                .project_id_or_name(project_id.to_string())
766                .title("TestWikiPage")
767                .build()?;
768            let WikiPageWrapper { wiki_page } =
769                redmine.json_response_body::<_, WikiPageWrapper<WikiPage>>(&get_endpoint)?;
770            assert_eq!(wiki_page.text, "Test Content");
771            assert_eq!(wiki_page.version, 1);
772
773            tracing::debug!("Updating wiki page TestWikiPage");
774            let update_endpoint = CreateOrUpdateProjectWikiPage::builder()
775                .project_id_or_name(project_id.to_string())
776                .title("TestWikiPage")
777                .text("Test Content Updates")
778                .version(1)
779                .comments("Update Page Test")
780                .build()?;
781            redmine.ignore_response_body(&update_endpoint)?;
782
783            tracing::debug!(
784                "Verifying existence, content and version of updated wiki page TestWikiPage"
785            );
786            let get_endpoint = GetProjectWikiPage::builder()
787                .project_id_or_name(project_id.to_string())
788                .title("TestWikiPage")
789                .build()?;
790            let WikiPageWrapper { wiki_page } =
791                redmine.json_response_body::<_, WikiPageWrapper<WikiPage>>(&get_endpoint)?;
792            assert_eq!(wiki_page.text, "Test Content Updates");
793            assert_eq!(wiki_page.version, 2);
794
795            tracing::debug!("Verifying existence and content of wiki page TestWikiPage version 1");
796            let version_endpoint = GetProjectWikiPageVersion::builder()
797                .project_id_or_name(project_id.to_string())
798                .title("TestWikiPage")
799                .version(1)
800                .build()?;
801            let WikiPageWrapper { wiki_page } =
802                redmine.json_response_body::<_, WikiPageWrapper<WikiPage>>(&version_endpoint)?;
803            assert_eq!(wiki_page.text, "Test Content");
804
805            tracing::debug!("Deleting wiki page TestWikiPage");
806            let delete_endpoint = DeleteProjectWikiPage::builder()
807                .project_id_or_name(project_id.to_string())
808                .title("TestWikiPage")
809                .build()?;
810            redmine.ignore_response_body(&delete_endpoint)?;
811
812            Ok(())
813        })
814    }
815}