@@ -2,11 +2,14 @@ use super::*;
2
2
use shopify_function:: { run_function_with_input, Result } ;
3
3
4
4
#[ test]
5
- fn test_result_contains_no_operations ( ) -> Result < ( ) > {
5
+ fn test_returns_no_operations_without_configuration ( ) -> Result < ( ) > {
6
6
let result = run_function_with_input (
7
7
function,
8
8
r#"
9
9
{
10
+ "cart": {
11
+ "deliveryGroups": []
12
+ },
10
13
"deliveryCustomization": {
11
14
"metafield": null
12
15
}
@@ -18,3 +21,87 @@ fn test_result_contains_no_operations() -> Result<()> {
18
21
assert_eq ! ( result, expected) ;
19
22
Ok ( ( ) )
20
23
}
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