improve caldav integration test

This commit is contained in:
Lennart
2025-12-12 23:43:14 +01:00
parent 50a74e3a25
commit d9cca5a298
5 changed files with 65 additions and 21 deletions

View File

@@ -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)
));
}

View File

@@ -111,7 +111,7 @@ async fn test_caldav_principal(
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);

View File

@@ -54,7 +54,7 @@ expression: body
<href>/caldav/principal/user/calendar/</href>
<propstat>
<prop>
<calendar-color xmlns="http://apple.com/ns/ical/">#FFF8DCFF</calendar-color>
<calendar-color xmlns="http://apple.com/ns/ical/">#00FF00</calendar-color>
<CAL:calendar-description>Description</CAL:calendar-description>
<CAL:calendar-timezone>BEGIN:VCALENDAR
PRODID:-//github.com/lennart-k/vzic-rs//RustiCal Calendar server//EN
@@ -209,7 +209,7 @@ END:VCALENDAR
<PUSH:transports>
<PUSH:web-push/>
</PUSH:transports>
[PUSH_TOPIC]
<PUSH:topic>[PUSH_TOPIC]</PUSH:topic>
<PUSH:supported-triggers>
<PUSH:content-update>
<depth>1</depth>
@@ -222,7 +222,7 @@ END:VCALENDAR
<collection/>
<CAL:calendar/>
</resourcetype>
<displayname>Amazing Calendar</displayname>
<displayname>Calendar</displayname>
<current-user-principal>
<href>/caldav/principal/user/</href>
</current-user-principal>

View File

@@ -6,7 +6,7 @@ BEGIN:VCALENDAR
VERSION:4.0
CALSCALE:GREGORIAN
PRODID:RustiCal
X-WR-CALNAME:Amazing Calendar
X-WR-CALNAME:Calendar
X-WR-CALDESC:Description
X-WR-TIMEZONE:Europe/Berlin
END:VCALENDAR

View File

@@ -8,7 +8,7 @@ expression: body
<href>/caldav/principal/user/calendar/</href>
<propstat>
<prop>
<calendar-color xmlns="http://apple.com/ns/ical/">#FFF8DCFF</calendar-color>
<calendar-color xmlns="http://apple.com/ns/ical/">#00FF00</calendar-color>
<CAL:calendar-description>Description</CAL:calendar-description>
<CAL:calendar-timezone>BEGIN:VCALENDAR
PRODID:-//github.com/lennart-k/vzic-rs//RustiCal Calendar server//EN
@@ -163,7 +163,7 @@ END:VCALENDAR
<PUSH:transports>
<PUSH:web-push/>
</PUSH:transports>
[PUSH_TOPIC]
<PUSH:topic>[PUSH_TOPIC]</PUSH:topic>
<PUSH:supported-triggers>
<PUSH:content-update>
<depth>1</depth>
@@ -176,7 +176,7 @@ END:VCALENDAR
<collection/>
<CAL:calendar/>
</resourcetype>
<displayname>Amazing Calendar</displayname>
<displayname>Calendar</displayname>
<current-user-principal>
<href>/caldav/principal/user/</href>
</current-user-principal>