Skip to content

Commit 0b589a3

Browse files
committed
Ignore empty phone numbers in POST /api/deliveries.
1 parent ce72cc6 commit 0b589a3

2 files changed

Lines changed: 161 additions & 0 deletions

File tree

features/deliveries.feature

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,162 @@ Feature: Deliveries
11471147
}
11481148
"""
11491149

1150+
Scenario: Create delivery with empty phone number
1151+
Given the fixtures files are loaded:
1152+
| sylius_products.yml |
1153+
| sylius_taxation.yml |
1154+
| payment_methods.yml |
1155+
| stores.yml |
1156+
And the store with name "Acme" has an OAuth client named "Acme"
1157+
And the OAuth client with name "Acme" has an access token
1158+
When I add "Content-Type" header equal to "application/ld+json"
1159+
And I add "Accept" header equal to "application/ld+json"
1160+
And the OAuth client "Acme" sends a "POST" request to "/api/deliveries" with body:
1161+
"""
1162+
{
1163+
"pickup": {
1164+
"address": "24, Rue de la Paix",
1165+
"doneBefore": "tomorrow 13:00"
1166+
},
1167+
"dropoff": {
1168+
"address": {
1169+
"streetAddress": "48, Rue de Rivoli",
1170+
"telephone": ""
1171+
},
1172+
"doneBefore": "tomorrow 13:30"
1173+
}
1174+
}
1175+
"""
1176+
Then the response status code should be 201
1177+
And the response should be in JSON
1178+
And the JSON should match:
1179+
"""
1180+
{
1181+
"@context":"/api/contexts/Delivery",
1182+
"@id":"@string@.startsWith('/api/deliveries')",
1183+
"@type":"http://schema.org/ParcelDelivery",
1184+
"id":@integer@,
1185+
"distance":@integer@,
1186+
"duration":@integer@,
1187+
"polyline":@string@,
1188+
"tasks":@array@,
1189+
"pickup":{
1190+
"@id":"@string@.startsWith('/api/tasks')",
1191+
"@type":"Task",
1192+
"id":@integer@,
1193+
"status":"TODO",
1194+
"type":"PICKUP",
1195+
"address":{
1196+
"@id":"@string@.startsWith('/api/addresses')",
1197+
"@type":"http://schema.org/Place",
1198+
"geo":{
1199+
"@type":"GeoCoordinates",
1200+
"latitude":@double@,
1201+
"longitude":@double@
1202+
},
1203+
"provider": null,
1204+
"streetAddress":@string@,
1205+
"telephone":null,
1206+
"name":null,
1207+
"contactName": null,
1208+
"description": null
1209+
},
1210+
"doneAfter":"@string@.isDateTime()",
1211+
"after":"@string@.isDateTime()",
1212+
"before":"@string@.isDateTime()",
1213+
"doneBefore":"@string@.isDateTime()",
1214+
"comments": "",
1215+
"weight": null,
1216+
"packages": [],
1217+
"barcode": {"@*@":"@*@"},
1218+
"createdAt":"@string@.isDateTime()",
1219+
"tags": [],
1220+
"metadata": {"@*@": "@*@"}
1221+
},
1222+
"dropoff":{
1223+
"@id":"@string@.startsWith('/api/tasks')",
1224+
"@type":"Task",
1225+
"id":@integer@,
1226+
"status":"TODO",
1227+
"type":"DROPOFF",
1228+
"address":{
1229+
"@id":"@string@.startsWith('/api/addresses')",
1230+
"@type":"http://schema.org/Place",
1231+
"geo":{
1232+
"@type":"GeoCoordinates",
1233+
"latitude":@double@,
1234+
"longitude":@double@
1235+
},
1236+
"provider": null,
1237+
"streetAddress":@string@,
1238+
"telephone":null,
1239+
"name":null,
1240+
"contactName": null,
1241+
"description": null
1242+
},
1243+
"doneAfter":"@string@.isDateTime()",
1244+
"after":"@string@.isDateTime()",
1245+
"before":"@string@.isDateTime()",
1246+
"doneBefore":"@string@.isDateTime()",
1247+
"comments": "",
1248+
"weight":null,
1249+
"packages": [],
1250+
"barcode": {"@*@":"@*@"},
1251+
"createdAt":"@string@.isDateTime()",
1252+
"tags": [],
1253+
"metadata": {"@*@": "@*@"}
1254+
},
1255+
"trackingUrl": @string@,
1256+
"order": {
1257+
"@id":"@string@.startsWith('/api/orders')",
1258+
"@type":"http://schema.org/Order",
1259+
"number": @string@,
1260+
"total": @integer@,
1261+
"taxTotal": @integer@,
1262+
"paymentGateway": @string@
1263+
}
1264+
}
1265+
"""
1266+
1267+
Scenario: Create delivery with invalid phone number
1268+
Given the fixtures files are loaded:
1269+
| sylius_products.yml |
1270+
| sylius_taxation.yml |
1271+
| payment_methods.yml |
1272+
| stores.yml |
1273+
And the store with name "Acme" has an OAuth client named "Acme"
1274+
And the OAuth client with name "Acme" has an access token
1275+
When I add "Content-Type" header equal to "application/ld+json"
1276+
And I add "Accept" header equal to "application/ld+json"
1277+
And the OAuth client "Acme" sends a "POST" request to "/api/deliveries" with body:
1278+
"""
1279+
{
1280+
"pickup": {
1281+
"address": "24, Rue de la Paix",
1282+
"doneBefore": "tomorrow 13:00"
1283+
},
1284+
"dropoff": {
1285+
"address": {
1286+
"streetAddress": "48, Rue de Rivoli",
1287+
"telephone": "not a phone number"
1288+
},
1289+
"doneBefore": "tomorrow 13:30"
1290+
}
1291+
}
1292+
"""
1293+
Then the response status code should be 400
1294+
And the response should be in JSON
1295+
And the JSON should match:
1296+
"""
1297+
{
1298+
"@context":"/api/contexts/Error",
1299+
"@type":"hydra:Error",
1300+
"hydra:title":"An error occurred",
1301+
"hydra:description":"The string supplied did not seem to be a phone number.",
1302+
"@*@": "@*@"
1303+
}
1304+
"""
1305+
11501306
Scenario: Create delivery with pickup & dropoff as an admin
11511307
Given the fixtures files are loaded:
11521308
| sylius_products.yml |

src/Serializer/PhoneNumberNormalizer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public function denormalize($data, $class, $format = null, array $context = []):
2222
return null;
2323
}
2424

25+
// Ignore empty phone numbers instead of throwing a parsing error
26+
if (\is_string($data) && '' === trim($data)) {
27+
return null;
28+
}
29+
2530
return parent::denormalize($data, $class, $format, $context);
2631
}
2732

0 commit comments

Comments
 (0)