@@ -59,6 +59,11 @@ $integration->mock( api_call => sub {
59
59
ServiceContractReference => ' GW-SERV-001' ,
60
60
};
61
61
}
62
+ } elsif ( $action eq ' cancel' ) {
63
+ return {
64
+ Reference => ' GWIT2025-001-001' ,
65
+ Status => ' Hold' ,
66
+ };
62
67
}
63
68
} );
64
69
@@ -69,7 +74,10 @@ subtest 'GET services' => sub {
69
74
ok $res -> is_success, ' valid request'
70
75
or diag $res -> content;
71
76
72
- is_deeply decode_json($res -> content), [
77
+ my @got = sort { $a -> {service_code } cmp $b -> {service_code } }
78
+ @{ decode_json( $res -> content ) };
79
+
80
+ is_deeply \@got , [
73
81
{
74
82
group => " Waste" ,
75
83
service_code => " garden_subscription" ,
@@ -78,7 +86,16 @@ subtest 'GET services' => sub {
78
86
type => " realtime" ,
79
87
service_name => " Garden Subscription" ,
80
88
metadata => " true"
81
- }
89
+ },
90
+ {
91
+ group => " Waste" ,
92
+ service_code => " garden_subscription_cancel" ,
93
+ description => " Cancel Garden Subscription" ,
94
+ keywords => " waste_only" ,
95
+ type => " realtime" ,
96
+ service_name => " Cancel Garden Subscription" ,
97
+ metadata => " true"
98
+ },
82
99
], ' correct json returned' ;
83
100
};
84
101
@@ -113,21 +130,42 @@ subtest 'GET service' => sub {
113
130
description => ' UPRN reference' ,
114
131
order => 2,
115
132
},
133
+ { %defaults ,
134
+ code => ' property_id' ,
135
+ description => ' Property ID' ,
136
+ order => 3,
137
+ },
116
138
{ %defaults ,
117
139
code => ' current_containers' ,
118
140
description => ' Number of current containers' ,
119
- order => 3 ,
141
+ order => 4 ,
120
142
},
121
143
{ %defaults ,
122
144
code => ' new_containers' ,
123
145
description => ' Number of new containers' ,
124
- order => 4 ,
146
+ order => 5 ,
125
147
},
126
148
{ %defaults ,
127
149
code => ' payment_method' ,
128
150
description => ' Payment method: credit card or direct debit' ,
129
- order => 5,
130
- }
151
+ order => 6,
152
+ },
153
+ { %defaults ,
154
+ code => ' reason' ,
155
+ description => ' Cancellation reason' ,
156
+ order => 7,
157
+ },
158
+ { %defaults ,
159
+ code => ' due_date' ,
160
+ description => ' Cancellation date' ,
161
+ order => 8,
162
+ },
163
+ { %defaults ,
164
+ code => ' customer_external_ref' ,
165
+ description => ' Customer external ref' ,
166
+ order => 9,
167
+ },
168
+
131
169
],
132
170
}, ' correct json returned' ;
133
171
};
@@ -206,4 +244,47 @@ subtest 'handle unknown error' => sub {
206
244
' Dies with error msg' ;
207
245
};
208
246
247
+ subtest ' successfully cancel a garden subscription' => sub {
248
+ my $res = $endpoint -> run_test_request(
249
+ POST => ' /requests.json' ,
250
+ api_key => ' test' ,
251
+ service_code => ' garden_subscription_cancel' ,
252
+ lat => 51,
253
+ long => -1,
254
+ ' attribute[fixmystreet_id]' => 2000002,
255
+ ' attribute[customer_external_ref]' => ' customer_ABC' ,
256
+ ' attribute[uprn]' => ' 234_has_sub' ,
257
+ ' attribute[reason]' => ' I used all my garden waste for a bonfire' ,
258
+ ' attribute[due_date]' => ' 01/01/2025' ,
259
+ );
260
+
261
+ ok $res -> is_success, ' valid request'
262
+ or diag $res -> content;
263
+
264
+ is_deeply decode_json($res -> content), [ {
265
+ service_request_id => ' GWIT2025-001-001' ,
266
+ } ], ' correct json returned' ;
267
+ };
268
+
269
+ subtest ' try to cancel when no subscription' => sub {
270
+ my $res = $endpoint -> run_test_request(
271
+ POST => ' /requests.json' ,
272
+ api_key => ' test' ,
273
+ service_code => ' garden_subscription_cancel' ,
274
+ lat => 51,
275
+ long => -1,
276
+ ' attribute[fixmystreet_id]' => 2000002,
277
+ ' attribute[customer_external_ref]' => ' customer_ABC' ,
278
+ ' attribute[uprn]' => ' 123_no_sub' ,
279
+ ' attribute[reason]' => ' I used all my garden waste for a bonfire' ,
280
+ ' attribute[due_date]' => ' 01/01/2025' ,
281
+ );
282
+
283
+ my $content = decode_json($res -> content);
284
+ is $content -> [0]{code }, 500;
285
+ like $content -> [0]{description },
286
+ qr / UPRN 123_no_sub does not have a subscription to be cancelled/ ,
287
+ ' Dies with error msg' ;
288
+ };
289
+
209
290
done_testing;
0 commit comments