Skip to content

Commit

Permalink
Allow .ics files
Browse files Browse the repository at this point in the history
  • Loading branch information
stabbylambda committed Feb 20, 2024
1 parent 5f92418 commit e3341ba
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lambda/src/trashcal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ pub async fn trashcal(id: &str) -> Result<PickupCalendar> {
// 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?;
Expand All @@ -21,7 +24,7 @@ pub async fn trashcal(id: &str) -> Result<PickupCalendar> {

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)
}
34 changes: 34 additions & 0 deletions lambda/tests/data/path_based_with_extension.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
13 changes: 13 additions & 0 deletions lambda/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit e3341ba

Please sign in to comment.