|
1 |
| -use super::*; |
2 |
| -use shopify_function::{run_function_with_input, Result}; |
3 |
| - |
4 |
| -#[test] |
5 |
| -fn test_result_contains_no_operations() -> Result<()> { |
6 |
| - let result = run_function_with_input( |
7 |
| - function, |
8 |
| - r#" |
| 1 | +use shopify_function::prelude::*; |
| 2 | +use shopify_function::Result; |
| 3 | + |
| 4 | +use serde::{Deserialize, Serialize}; |
| 5 | + |
| 6 | +#[derive(Serialize, Deserialize, Default, PartialEq)] |
| 7 | +struct Config {} |
| 8 | + |
| 9 | +#[shopify_function_target(query_path = "src/run.graphql", schema_path = "schema.graphql")] |
| 10 | +fn run(_input: input::ResponseData) -> Result<output::FunctionRunResult> { |
| 11 | + let operations = vec![output::Operation { |
| 12 | + add: output::LocalPickupDeliveryOption { |
| 13 | + title: Some("Main St.".to_string()), |
| 14 | + cost: Some(Decimal(1.99)), |
| 15 | + pickup_location: output::PickupLocation { |
| 16 | + location_handle: "2578303".to_string(), |
| 17 | + pickup_instruction: Some("Usually ready in 24 hours.".to_string()), |
| 18 | + }, |
| 19 | + }, |
| 20 | + }]; |
| 21 | + |
| 22 | + // Build operations based on the input query response here. |
| 23 | + |
| 24 | + Ok(output::FunctionRunResult { operations }) |
| 25 | +} |
| 26 | + |
| 27 | +#[cfg(test)] |
| 28 | +mod tests { |
| 29 | + use super::run::*; |
| 30 | + use super::*; |
| 31 | + use shopify_function::{run_function_with_input, Result}; |
| 32 | + |
| 33 | + #[test] |
| 34 | + fn test_result_contains_no_operations() -> Result<()> { |
| 35 | + let result = run_function_with_input( |
| 36 | + run, |
| 37 | + r#" |
9 | 38 | {
|
10 | 39 | "cart": {
|
11 | 40 | "lines": [
|
@@ -42,21 +71,22 @@ fn test_result_contains_no_operations() -> Result<()> {
|
42 | 71 | }
|
43 | 72 | }
|
44 | 73 | "#,
|
45 |
| - )?; |
| 74 | + )?; |
46 | 75 |
|
47 |
| - let operations = vec![output::Operation { |
48 |
| - add: output::LocalPickupDeliveryOption { |
49 |
| - title: Some("Main St.".to_string()), |
50 |
| - cost: Some(Decimal(1.99)), |
51 |
| - pickup_location: output::PickupLocation { |
52 |
| - location_handle: "2578303".to_string(), |
53 |
| - pickup_instruction: Some("Usually ready in 24 hours.".to_string()), |
| 76 | + let operations = vec![output::Operation { |
| 77 | + add: output::LocalPickupDeliveryOption { |
| 78 | + title: Some("Main St.".to_string()), |
| 79 | + cost: Some(Decimal(1.99)), |
| 80 | + pickup_location: output::PickupLocation { |
| 81 | + location_handle: "2578303".to_string(), |
| 82 | + pickup_instruction: Some("Usually ready in 24 hours.".to_string()), |
| 83 | + }, |
54 | 84 | },
|
55 |
| - }, |
56 |
| - }]; |
| 85 | + }]; |
57 | 86 |
|
58 |
| - let expected = crate::output::FunctionResult { operations }; |
| 87 | + let expected = output::FunctionRunResult { operations }; |
59 | 88 |
|
60 |
| - assert_eq!(result, expected); |
61 |
| - Ok(()) |
| 89 | + assert_eq!(result, expected); |
| 90 | + Ok(()) |
| 91 | + } |
62 | 92 | }
|
0 commit comments