Skip to content

Commit c9cf12d

Browse files
authored
APPT-1671: remove if statement for cancel booking parse (#1180)
# Description Resolving error in the cancel booking parsing - `{"Level":"Error","MessageTemplate":"Specified method is not supported.","RenderedMessage":"Specified method is not supported.","Exception":"System.NotSupportedException: Specified method is not supported.\r\n at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.get_Length()\r\n at Nhs.Appointments.Api.Functions.CancelBookingFunction.ReadRequestAsync(HttpRequest req) in /home/vsts/work/1/s/src/api/Nhs.Appointments.Api/Functions/CancelBookingFunction.cs:line 109\r\n at Nhs.Appointments.Api.Functions.BaseApiFunction`2.RunAsync(HttpRequest req)","TraceId":"288a641dfb98b44e7d25fdc931a440de","SpanId":"4ffc4d12300d0c4f","Properties":{"SourceContext":"Nhs.Appointments.Api.Functions.CancelBookingFunction","AzureFunctions_InvocationId":"391bae1f-c9ab-4a7c-a067-9c7077b58400","AzureFunctions_FunctionName":"CancelBookingFunction"}}` Example error is in 2.8 - will need cherry-picking index="mya_nhsuk_int"| spath TraceId | search TraceId=288a641dfb98b44e7d25fdc931a440de Fixes # (issue) # Checklist: - [x] My work is behind a feature toggle (if appropriate) - [x] If my work is behind a feature toggle, I've added a full suite of tests for both the ON and OFF state - [x] The ticket number is in the Pull Request title, with format "APPT-XXX: My Title Here" - [x] I have ran npm tsc / lint (in the future these will be ran automatically) - [x] My code generates no new .NET warnings (in the future these will be treated as errors) - [x] If I've added a new Function, it is disabled in all but one of the terraform groups (e.g. http_functions) - [x] If I've added a new Function, it has both unit and integration tests. Any request body validators have unit tests also - [x] If I've made UI changes, I've added appropriate Playwright and Jest tests - [x] If I've added/updated an end-point, I've added the appropriate annotations and tested the Swagger documentation reflects the change
1 parent fcc6b2b commit c9cf12d

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

src/api/Nhs.Appointments.Api/Functions/HttpFunctions/CancelBookingFunction.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,20 @@ protected override async Task<ApiResult<CancelBookingResponse>> HandleRequest(Ca
107107
}
108108

109109
var cancellationReason = CancellationReason.CancelledByCitizen;
110-
object additionalData = null;
111-
if (req.Body.Length > 0)
112-
{
113-
var (errorsFromBody, payload) = await JsonRequestReader.ReadRequestAsync<CancelBookingRequest>(req.Body, true);
114-
errors.AddRange(errorsFromBody);
115-
116-
if (errors.Any(x => x.Property == "cancellationReason"))
117-
{
118-
return (errors, null);
119-
}
110+
var (errorsFromBody, payload) = await JsonRequestReader.ReadRequestAsync<CancelBookingRequest>(req.Body);
120111

121-
if (payload?.cancellationReason != null)
122-
{
123-
cancellationReason = (CancellationReason)payload.cancellationReason;
124-
}
125-
126-
additionalData = payload?.additionalData;
112+
errors.AddRange(errorsFromBody);
113+
114+
if (errors.Count != 0)
115+
{
116+
return (errors, new CancelBookingRequest(bookingReference, site, cancellationReason, null));
127117
}
118+
if (payload?.cancellationReason != null)
119+
{
120+
cancellationReason = (CancellationReason)payload.cancellationReason;
121+
}
122+
123+
var additionalData = payload?.additionalData;
128124

129125
var requestModel = new CancelBookingRequest(bookingReference, site, cancellationReason, additionalData);
130126

tests/Nhs.Appointments.Api.Integration/Scenarios/Booking/Cancel/Autocancellation.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
Feature: Appointment cancellation
22

3+
Scenario: Can cancel a booking when I provide no details for cancellation reason or additional data
4+
Given the following sessions
5+
| Date | From | Until | Services | Slot Length | Capacity |
6+
| Tomorrow | 09:00 | 12:00 | RSV:Adult | 10 | 1 |
7+
And the following bookings exist
8+
| Reference | Booking Type |
9+
| 1 | Confirmed |
10+
When I cancel the following bookings
11+
| Reference |
12+
| 1 |
13+
Then the following bookings are now in the following state
14+
| Reference | Status | Cancellation reason |
15+
| 1 | Cancelled | CancelledByCitizen |
16+
317
Scenario: Can set additional data when cancelling a booking and providing no site parameter
418
Given the following sessions
519
| Date | From | Until | Services | Slot Length | Capacity |

0 commit comments

Comments
 (0)