-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathrun.rs
More file actions
72 lines (63 loc) · 2.05 KB
/
run.rs
File metadata and controls
72 lines (63 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use shopify_function::prelude::*;
use shopify_function::Result;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Default, PartialEq)]
#[allow(dead_code)]
struct Config {}
#[shopify_function_target(query_path = "src/run.graphql", schema_path = "schema.graphql")]
fn run(input: input::ResponseData) -> Result<output::FunctionRunResult> {
let operations = input
.fulfillment_groups
.iter()
.map(|group| {
let rankings = group
.inventory_location_handles
.iter()
.map(|location_handle| output::RankedLocation {
location_handle: location_handle.clone(),
rank: 0,
})
.collect::<Vec<output::RankedLocation>>();
output::Operation {
rank: output::FulfillmentGroupRankedLocations {
fulfillment_group_handle: group.handle.clone(),
rankings,
},
}
})
.collect();
Ok(output::FunctionRunResult { operations })
}
#[cfg(test)]
mod tests {
use super::*;
use shopify_function::{run_function_with_input, Result};
#[test]
fn test_result_ranks_all_locations_zero() -> Result<()> {
use run::output::*;
let result = run_function_with_input(
run,
r#"
{
"fulfillmentGroups": [{
"handle": "123",
"inventoryLocationHandles": ["456"]
}]
}
"#,
)?;
let expected = FunctionRunResult {
operations: vec![Operation {
rank: FulfillmentGroupRankedLocations {
fulfillment_group_handle: "123".to_string(),
rankings: vec![RankedLocation {
location_handle: "456".to_string(),
rank: 0,
}],
},
}],
};
assert_eq!(result, expected);
Ok(())
}
}