From e3341ba2f81a6f25c521161a42c29597749678c1 Mon Sep 17 00:00:00 2001 From: David Stone Date: Tue, 20 Feb 2024 11:30:33 -0800 Subject: [PATCH] Allow .ics files --- lambda/src/trashcal.rs | 5 ++- .../tests/data/path_based_with_extension.json | 34 +++++++++++++++++++ lambda/tests/integration_tests.rs | 13 +++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 lambda/tests/data/path_based_with_extension.json diff --git a/lambda/src/trashcal.rs b/lambda/src/trashcal.rs index 0dd49cc..e9cbfcb 100644 --- a/lambda/src/trashcal.rs +++ b/lambda/src/trashcal.rs @@ -9,6 +9,9 @@ pub async fn trashcal(id: &str) -> Result { // as far as I can tell, all IDs start with a4Ot ensure!(id.starts_with("a4Ot"), Error::IdError(id.to_string())); + // rip out .ics for Paul + let id = id.replace(".ics", ""); + info!("Getting trashcal"); let url = format!("https://getitdone.force.com/CollectionDetail?id={id}"); let html = reqwest::get(url).await?.text().await?; @@ -21,7 +24,7 @@ pub async fn trashcal(id: &str) -> Result { info!("Parsing calendar"); let document = Html::parse_document(&html); - let calendar = PickupCalendar::try_from((id, &document))?; + let calendar = PickupCalendar::try_from((id.as_str(), &document))?; Ok(calendar) } diff --git a/lambda/tests/data/path_based_with_extension.json b/lambda/tests/data/path_based_with_extension.json new file mode 100644 index 0000000..356432b --- /dev/null +++ b/lambda/tests/data/path_based_with_extension.json @@ -0,0 +1,34 @@ +{ + "version": "2.0", + "routeKey": "$default", + "rawPath": "/a4Ot0000001E8i4EAC.ics", + "rawQueryString": "", + "cookies": [], + "headers": {}, + "queryStringParameters": {}, + "requestContext": { + "accountId": "123456789012", + "apiId": "api-id", + "authorizer": {}, + "domainName": "trashcal.test.com", + "domainPrefix": "id", + "http": { + "method": "POST", + "path": "/", + "protocol": "HTTP/1.1", + "sourceIp": "IP", + "userAgent": "agent" + }, + "requestId": "id", + "routeKey": "$default", + "stage": "$default", + "time": "12/Mar/2020:19:03:58 +0000", + "timeEpoch": 1583348638390 + }, + "body": "", + "pathParameters": { + "id": "a4Ot0000001E8i4EAC.ics" + }, + "isBase64Encoded": false, + "stageVariables": {} +} \ No newline at end of file diff --git a/lambda/tests/integration_tests.rs b/lambda/tests/integration_tests.rs index e7b2b02..284fdd4 100644 --- a/lambda/tests/integration_tests.rs +++ b/lambda/tests/integration_tests.rs @@ -14,6 +14,19 @@ async fn path_based() { assert!(body.contains("X-WR-CALNAME:Trashcal")); } +#[tokio::test] +async fn path_based_with_extension() { + let input = include_str!("./data/path_based_with_extension.json"); + let request = lambda_http::request::from_str(input).expect("failed to create request"); + let response = trashcal_handler(request).await.expect("Failed to execute"); + let body = std::str::from_utf8(response.body()).expect("Should have a body"); + assert_eq!( + response.headers()[CONTENT_TYPE], + "text/calendar;charset=UTF-8" + ); + assert!(body.contains("X-WR-CALNAME:Trashcal")); +} + #[tokio::test] async fn query_based() { let input = include_str!("./data/query_based.json");