mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-29 08:19:06 +00:00
improve caldav integration test
This commit is contained in:
@@ -1,13 +1,23 @@
|
||||
use crate::integration_tests::{ResponseExtractString, get_app};
|
||||
use axum::body::{Body, Bytes};
|
||||
use axum::body::Body;
|
||||
use axum::extract::Request;
|
||||
use headers::{Authorization, HeaderMapExt};
|
||||
use http::{HeaderValue, StatusCode};
|
||||
use rstest::rstest;
|
||||
use rustical_store::{Calendar, CalendarMetadata};
|
||||
use rustical_store::{CalendarMetadata, CalendarStore};
|
||||
use rustical_store_sqlite::{calendar_store::SqliteCalendarStore, tests::get_test_calendar_store};
|
||||
use tower::ServiceExt;
|
||||
|
||||
const MKCOL_REQUEST: &str = r#"
|
||||
fn mkcalendar_template(
|
||||
CalendarMetadata {
|
||||
displayname,
|
||||
order: _order,
|
||||
description,
|
||||
color,
|
||||
}: &CalendarMetadata,
|
||||
) -> String {
|
||||
format!(
|
||||
r#"
|
||||
<?xml version='1.0' encoding='UTF-8' ?>
|
||||
<CAL:mkcalendar xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav">
|
||||
<set>
|
||||
@@ -16,9 +26,9 @@ const MKCOL_REQUEST: &str = r#"
|
||||
<collection />
|
||||
<CAL:calendar />
|
||||
</resourcetype>
|
||||
<displayname>Amazing Calendar</displayname>
|
||||
<CAL:calendar-description>Description</CAL:calendar-description>
|
||||
<n0:calendar-color xmlns:n0="http://apple.com/ns/ical/">#FFF8DCFF</n0:calendar-color>
|
||||
<displayname>{displayname}</displayname>
|
||||
<CAL:calendar-description>{description}</CAL:calendar-description>
|
||||
<n0:calendar-color xmlns:n0="http://apple.com/ns/ical/">{color}</n0:calendar-color>
|
||||
<CAL:calendar-timezone-id>Europe/Berlin</CAL:calendar-timezone-id>
|
||||
<CAL:supported-calendar-component-set>
|
||||
<CAL:comp name="VEVENT"/>
|
||||
@@ -28,7 +38,12 @@ const MKCOL_REQUEST: &str = r#"
|
||||
</prop>
|
||||
</set>
|
||||
</CAL:mkcalendar>
|
||||
"#;
|
||||
"#,
|
||||
displayname = displayname.as_deref().unwrap_or_default(),
|
||||
description = description.as_deref().unwrap_or_default(),
|
||||
color = color.as_deref().unwrap_or_default(),
|
||||
)
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[tokio::test]
|
||||
@@ -36,14 +51,27 @@ async fn test_caldav_calendar(
|
||||
#[from(get_app)]
|
||||
#[future]
|
||||
app: axum::Router,
|
||||
#[from(get_test_calendar_store)]
|
||||
#[future]
|
||||
cal_store: SqliteCalendarStore,
|
||||
) {
|
||||
let app = app.await;
|
||||
let cal_store = cal_store.await;
|
||||
|
||||
let calendar_meta = CalendarMetadata {
|
||||
displayname: Some("Calendar".to_string()),
|
||||
description: Some("Description".to_string()),
|
||||
color: Some("#00FF00".to_string()),
|
||||
order: 0,
|
||||
};
|
||||
let (principal, cal_id) = ("user", "calendar");
|
||||
let url = format!("/caldav/principal/{principal}/{cal_id}");
|
||||
|
||||
let request_template = || {
|
||||
Request::builder()
|
||||
.method("MKCALENDAR")
|
||||
.uri("/caldav/principal/user/calendar")
|
||||
.body(Body::from(MKCOL_REQUEST))
|
||||
.uri(&url)
|
||||
.body(Body::from(mkcalendar_template(&calendar_meta)))
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
@@ -66,7 +94,7 @@ async fn test_caldav_calendar(
|
||||
|
||||
let mut request = Request::builder()
|
||||
.method("GET")
|
||||
.uri("/caldav/principal/user/calendar")
|
||||
.uri(&url)
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
request
|
||||
@@ -77,9 +105,18 @@ async fn test_caldav_calendar(
|
||||
let body = response.extract_string().await;
|
||||
insta::assert_snapshot!(body);
|
||||
|
||||
assert_eq!(
|
||||
cal_store
|
||||
.get_calendar(principal, cal_id, false)
|
||||
.await
|
||||
.unwrap()
|
||||
.meta,
|
||||
calendar_meta
|
||||
);
|
||||
|
||||
let mut request = Request::builder()
|
||||
.method("PROPFIND")
|
||||
.uri("/caldav/principal/user/calendar")
|
||||
.uri(&url)
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
request
|
||||
@@ -90,7 +127,7 @@ async fn test_caldav_calendar(
|
||||
let body = response.extract_string().await;
|
||||
insta::with_settings!({
|
||||
filters => vec![
|
||||
(r"<PUSH:topic>[0-9a-f-]+</PUSH:topic>", "[PUSH_TOPIC]")
|
||||
(r"<PUSH:topic>[0-9a-f-]+</PUSH:topic>", "<PUSH:topic>[PUSH_TOPIC]</PUSH:topic>")
|
||||
]
|
||||
}, {
|
||||
insta::assert_snapshot!(body);
|
||||
@@ -98,7 +135,8 @@ async fn test_caldav_calendar(
|
||||
|
||||
let mut request = Request::builder()
|
||||
.method("DELETE")
|
||||
.uri("/caldav/principal/user/calendar")
|
||||
.uri(&url)
|
||||
.header("X-No-Trashbin", HeaderValue::from_static("1"))
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
request
|
||||
@@ -108,4 +146,10 @@ async fn test_caldav_calendar(
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
let body = response.extract_string().await;
|
||||
insta::assert_snapshot!(body);
|
||||
|
||||
assert!(matches!(
|
||||
cal_store.get_calendar(principal, cal_id, false).await,
|
||||
Err(rustical_store::Error::NotFound)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user