Skip to content

Commit b19c1df

Browse files
committed
Add tests for delivery customization function
1 parent 3ef94a6 commit b19c1df

File tree

1 file changed

+88
-1
lines changed
  • sample-apps/delivery-customizations/extensions/delivery-customization/src

1 file changed

+88
-1
lines changed

sample-apps/delivery-customizations/extensions/delivery-customization/src/tests.rs

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ use super::*;
22
use shopify_function::{run_function_with_input, Result};
33

44
#[test]
5-
fn test_result_contains_no_operations() -> Result<()> {
5+
fn test_returns_no_operations_without_configuration() -> Result<()> {
66
let result = run_function_with_input(
77
function,
88
r#"
99
{
10+
"cart": {
11+
"deliveryGroups": []
12+
},
1013
"deliveryCustomization": {
1114
"metafield": null
1215
}
@@ -18,3 +21,87 @@ fn test_result_contains_no_operations() -> Result<()> {
1821
assert_eq!(result, expected);
1922
Ok(())
2023
}
24+
25+
#[test]
26+
fn test_renames_delivery_options_if_province_matches() -> Result<()> {
27+
let result = run_function_with_input(
28+
function,
29+
r#"
30+
{
31+
"cart": {
32+
"deliveryGroups": [{
33+
"deliveryAddress": {
34+
"provinceCode": "ON"
35+
},
36+
"deliveryOptions": [{
37+
"handle": "test_delivery_option",
38+
"title": "Test Delivery Option"
39+
}, {
40+
"handle": "test_delivery_option_2",
41+
"title": "Test Delivery Option 2"
42+
}]
43+
}]
44+
},
45+
"deliveryCustomization": {
46+
"metafield": {
47+
"value": "{\"stateProvinceCode\": \"ON\", \"message\": \"Test Message\"}"
48+
}
49+
}
50+
}
51+
"#,
52+
)?;
53+
let expected = crate::output::FunctionResult {
54+
operations: vec![
55+
output::Operation {
56+
rename: Some(output::RenameOperation {
57+
delivery_option_handle: "test_delivery_option".to_string(),
58+
title: "Test Delivery Option - Test Message".to_string(),
59+
}),
60+
hide: None,
61+
move_: None,
62+
},
63+
output::Operation {
64+
rename: Some(output::RenameOperation {
65+
delivery_option_handle: "test_delivery_option_2".to_string(),
66+
title: "Test Delivery Option 2 - Test Message".to_string(),
67+
}),
68+
hide: None,
69+
move_: None,
70+
},
71+
],
72+
};
73+
74+
assert_eq!(result, expected);
75+
Ok(())
76+
}
77+
78+
#[test]
79+
fn test_returns_no_operations_if_province_code_does_not_match() -> Result<()> {
80+
let result = run_function_with_input(
81+
function,
82+
r#"
83+
{
84+
"cart": {
85+
"deliveryGroups": [{
86+
"deliveryAddress": {
87+
"provinceCode": "NC"
88+
},
89+
"deliveryOptions": [{
90+
"handle": "test_delivery_option",
91+
"title": "Test Delivery Option"
92+
}]
93+
}]
94+
},
95+
"deliveryCustomization": {
96+
"metafield": {
97+
"value": "{\"stateProvinceCode\": \"ON\", \"message\": \"Test Message\"}"
98+
}
99+
}
100+
}
101+
"#,
102+
)?;
103+
let expected = crate::output::FunctionResult { operations: vec![] };
104+
105+
assert_eq!(result, expected);
106+
Ok(())
107+
}

0 commit comments

Comments
 (0)