@@ -2,11 +2,22 @@ use super::*;
2
2
use shopify_function:: { run_function_with_input, Result } ;
3
3
4
4
#[ test]
5
- fn test_result_contains_no_discounts ( ) -> Result < ( ) > {
5
+ fn test_no_metafield_result_contains_no_discounts ( ) -> Result < ( ) > {
6
6
let result = run_function_with_input (
7
7
function,
8
8
r#"
9
9
{
10
+ "cart": {
11
+ "lines": [
12
+ {
13
+ "quantity": 10,
14
+ "merchandise": {
15
+ "__typename": "ProductVariant",
16
+ "id": "gid://shopify/ProductVariant/123456789"
17
+ }
18
+ }
19
+ ]
20
+ },
10
21
"discountNode": {
11
22
"metafield": null
12
23
}
@@ -18,3 +29,99 @@ fn test_result_contains_no_discounts() -> Result<()> {
18
29
assert_eq ! ( result. discounts. len( ) , expected) ;
19
30
Ok ( ( ) )
20
31
}
32
+
33
+ #[ test]
34
+ fn test_quantity_unmet_result_contains_no_discounts ( ) -> Result < ( ) > {
35
+ let result = run_function_with_input (
36
+ function,
37
+ r#"
38
+ {
39
+ "cart": {
40
+ "lines": [
41
+ {
42
+ "quantity": 1,
43
+ "merchandise": {
44
+ "__typename": "ProductVariant",
45
+ "id": "gid://shopify/ProductVariant/123456789"
46
+ }
47
+ }
48
+ ]
49
+ },
50
+ "discountNode": {
51
+ "metafield": {
52
+ "value": "{\"quantity\":2,\"percentage\":5}"
53
+ }
54
+ }
55
+ }
56
+ "# ,
57
+ ) ?;
58
+ let expected = 0 ;
59
+
60
+ assert_eq ! ( result. discounts. len( ) , expected) ;
61
+ Ok ( ( ) )
62
+ }
63
+
64
+ #[ test]
65
+ fn test_quantity_met_discounts_variants ( ) -> Result < ( ) > {
66
+ let result = run_function_with_input (
67
+ function,
68
+ r#"
69
+ {
70
+ "cart": {
71
+ "lines": [
72
+ {
73
+ "quantity": 2,
74
+ "merchandise": {
75
+ "__typename": "ProductVariant",
76
+ "id": "gid://shopify/ProductVariant/123456789"
77
+ }
78
+ },
79
+ {
80
+ "quantity": 3,
81
+ "merchandise": {
82
+ "__typename": "ProductVariant",
83
+ "id": "gid://shopify/ProductVariant/987654321"
84
+ }
85
+ }
86
+ ]
87
+ },
88
+ "discountNode": {
89
+ "metafield": {
90
+ "value": "{\"quantity\":2,\"percentage\":5}"
91
+ }
92
+ }
93
+ }
94
+ "# ,
95
+ ) ?;
96
+ let expected = output:: FunctionResult {
97
+ discount_application_strategy : output:: DiscountApplicationStrategy :: FIRST ,
98
+ discounts : vec ! [
99
+ output:: Discount {
100
+ message: None ,
101
+ targets: vec![
102
+ output:: Target {
103
+ product_variant: Some ( output:: ProductVariantTarget {
104
+ id: "gid://shopify/ProductVariant/123456789" . to_string( ) ,
105
+ quantity: None
106
+ } )
107
+ } ,
108
+ output:: Target {
109
+ product_variant: Some ( output:: ProductVariantTarget {
110
+ id: "gid://shopify/ProductVariant/987654321" . to_string( ) ,
111
+ quantity: None
112
+ } )
113
+ } ,
114
+ ] ,
115
+ value: output:: Value {
116
+ fixed_amount: None ,
117
+ percentage: Some ( output:: Percentage {
118
+ value: "5" . to_string( )
119
+ } )
120
+ }
121
+ }
122
+ ]
123
+ } ;
124
+
125
+ assert_eq ! ( result, expected) ;
126
+ Ok ( ( ) )
127
+ }
0 commit comments