Skip to content

Commit bae0cff

Browse files
committed
test: added more test data
1 parent 663b91d commit bae0cff

File tree

5 files changed

+66
-15
lines changed

5 files changed

+66
-15
lines changed

src/main.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ async fn filter_actions(event: Value, _: Context) -> Result<Value, Error> {
2525

2626
let input: Vec<Action> = serde_json::from_value(event)?;
2727

28-
let mut selected: HashMap<&str, Action> = HashMap::new();
28+
let mut selected: HashMap<String, Action> = HashMap::new();
2929

3030
for action in input {
31-
let days_since_last = (now - action.last_action_time).num_days();
31+
let days_since_last = (now - action.last_action_time).to_std().unwrap().as_secs() / 86400;
3232
if days_since_last < 7 {
3333
continue;
3434
}
@@ -37,9 +37,7 @@ async fn filter_actions(event: Value, _: Context) -> Result<Value, Error> {
3737
continue;
3838
}
3939

40-
selected
41-
.entry(&action.entity_id)
42-
.or_insert(action);
40+
selected.entry(action.entity_id.clone()).or_insert(action);
4341
}
4442

4543
let mut actions: Vec<Action> = selected.into_iter().map(|(_, v)| v).collect();

testdata/sample-input.json renamed to testdata/01_sample-input.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
"entity_id": "entity_1",
44
"last_action_time": "2025-06-20T00:00:00Z",
55
"next_action_time": "2025-07-10T00:00:00Z",
6-
"priority": "high"
6+
"priority": "urgent"
77
},
88
{
99
"entity_id": "entity_1",
1010
"last_action_time": "2025-06-01T00:00:00Z",
1111
"next_action_time": "2025-07-01T00:00:00Z",
12-
"priority": "low"
12+
"priority": "normal"
1313
},
1414
{
1515
"entity_id": "entity_2",
1616
"last_action_time": "2025-03-01T00:00:00Z",
1717
"next_action_time": "2026-01-01T00:00:00Z",
18-
"priority": "high"
18+
"priority": "urgent"
1919
},
2020
{
2121
"entity_id": "entity_3",
2222
"last_action_time": "2025-05-01T00:00:00Z",
2323
"next_action_time": "2025-07-10T00:00:00Z",
24-
"priority": "low"
24+
"priority": "normal"
2525
}
2626
]

testdata/02_priority-input.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{
3+
"entity_id": "entity_1",
4+
"last_action_time": "2025-06-20T00:00:00Z",
5+
"next_action_time": "2025-07-10T00:00:00Z",
6+
"priority": "urgent"
7+
},
8+
{
9+
"entity_id": "entity_2",
10+
"last_action_time": "2025-06-01T00:00:00Z",
11+
"next_action_time": "2025-07-01T00:00:00Z",
12+
"priority": "normal"
13+
},
14+
{
15+
"entity_id": "entity_3",
16+
"last_action_time": "2025-03-01T00:00:00Z",
17+
"next_action_time": "2026-01-01T00:00:00Z",
18+
"priority": "urgent"
19+
},
20+
{
21+
"entity_id": "entity_4",
22+
"last_action_time": "2025-05-01T00:00:00Z",
23+
"next_action_time": "2025-07-10T00:00:00Z",
24+
"priority": "normal"
25+
},
26+
{
27+
"entity_id": "entity_5",
28+
"last_action_time": "2025-05-01T00:00:00Z",
29+
"next_action_time": "2025-07-10T00:00:00Z",
30+
"priority": "urgent"
31+
}
32+
]

testdata/03_bad-input.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[
2+
{
3+
"entity_id": "entity_1",
4+
"last_action_time": "2025-08-20T00:00:00Z",
5+
"next_action_time": "2025-07-10T00:00:00Z",
6+
"priority": "urgent"
7+
},
8+
{
9+
"entity_id": "entity_2",
10+
"last_action_time": "2025-03-01T00:00:00Z",
11+
"next_action_time": "2026-01-01T00:00:00Z",
12+
"priority": "urgent"
13+
},
14+
{
15+
"entity_id": "entity_3",
16+
"last_action_time": "2025-05-01T00:00:00Z",
17+
"next_action_time": "2025-07-10T00:00:00Z",
18+
"priority": "normal"
19+
},
20+
{
21+
"entity_id": "entity_3",
22+
"last_action_time": "2025-05-01T00:00:00Z",
23+
"next_action_time": "2025-07-10T00:00:00Z",
24+
"priority": "unknown"
25+
}
26+
]

tests/filter_tests.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
use lambda_action_filter::main as lambda_main; // Adjust if crate name changes
2-
// Placeholder for integration tests; candidates can extend
3-
#[test]
4-
fn dummy() {
5-
assert_eq!(2 + 2, 4);
6-
}
1+

0 commit comments

Comments
 (0)