above solution is not working for the below API endpoint.
getSectionsCategoriesItemsByGuest
Response of this get API endpoint is:
{
"sessionToken": "kDCp36W91ogKAAAABwAAAAAAAAAkYmEwNTRhNzctYWIyZC00ZTZkLWJmZTctMzQ0ZjYyMWQyZjFmAQAAAANBQ0cCAAAAA0FDUAYAAAACMTkFAAAAA2VuZwMAAAAHMTI5ODc3OAQAAAADMTAyAQAAAAAAAAA.-aCxKVIYYrd2t5euF6ZPPVlmPCOxkK97du9soX1e_KI",
"responsesIncluded": "getSectionsCategoriesItemsByGuest",
"responses": [
{
"getSectionsCategoriesItemsByGuest": {
"content": {
"sections": [
{
"id": 733977,
"code": "51f0c8cb-93c7-4230-8291-4761a91fd374",
"referenceCode": null,
"name": "Dynamic Widget Section Visible to specific room",
"internalName": "Dynamic Widget Section Visible to specific room",
"gridFormat": "",
"headerTitle": "<p>Dynamic Widget Section Visible to specific room</p>\n",
"headerBody": "<p>Dynamic Widget Section Visible to specific room</p>\n",
"relatedItemsTitle": null,
"iconCode": "i-f-cart-1",
"type": "StandardContent",
"customAction": "",
"url": null,
"displayOrder": 10,
"infoModules": [],
"categories": [
{
"subCategories": [],
"imageUrl": null,
"headerTitle": "<p>Lunch Category</p>\r\n",
"headerBody": "<p>Lunch Category</p>\r\n",
"type": "StandardContent",
"displayOrder": 0,
"externalUrl": null,
"gridFormat": null,
"fbDisplayType": null,
"name": "Lunch Category",
"relatedItemsTitle": null,
"updateDate": "2019-04-04T10:04:51.39",
"sectionCode": "51f0c8cb-93c7-4230-8291-4761a91fd374",
"code": "230725f9-9b5c-45fd-937b-a5b08c2d1674",
"useGallery": false,
"categoryExtraCharges": [],
"teasers": [],
"analyticsTag": null
}
],
"imageUrl": "https://irisv4neuqaasstore.blob.core.windows.net/fileresources/public/iris/ACG/maini-s-green-leaf8e97ca65a1b44e798b893da8fd19aa84.jpg",
"teasers": [],
"analyticsTag": null,
"hideFromWebValet": false,
"hideFromNativeApps": false,
"visibleToRooms": "102",
"isEncryptedUrl": false,
"isVisibleToAllRooms": false,
"availabilityPeriods": [],
"availabilitySummary": {},
"sectionOutlets": [],
"widgetReferenceCode": null
},
{
"id": 733985,
"code": "f03947c2-e47c-4da2-93d5-cb275214edb1",
"referenceCode": null,
"name": "Room Specific - Standard Section - Product Items with Modifiers",
"internalName": "Room Specific - Standard Section - Product Items with Modifiers",
"gridFormat": "",
"headerTitle": "<p>Room Specific - Standard Section - Product Items with Modifiers</p>\n",
"headerBody": "<p>Room Specific - Standard Section - Product Items with Modifiers</p>\n",
"relatedItemsTitle": null,
"iconCode": "i-f-pause-1",
"type": "StandardContent",
"customAction": "",
"url": null,
"displayOrder": 18,
"infoModules": [],
"categories": [
{
"subCategories": [],
"imageUrl": null,
"headerTitle": "<p>Category - Product Items with Modifiers</p>\r\n",
"headerBody": "<p>Category - Product Items with Modifiers</p>\r\n",
"type": "StandardContent",
"displayOrder": 0,
"externalUrl": null,
"gridFormat": null,
"fbDisplayType": null,
"name": "Category - Product Items with Modifiers",
"relatedItemsTitle": null,
"updateDate": "2019-04-04T10:04:51.44",
"sectionCode": "f03947c2-e47c-4da2-93d5-cb275214edb1",
"code": "58104a1b-d19c-41a2-a77d-6f2688bfd709",
"useGallery": false,
"categoryExtraCharges": [],
"teasers": [],
"analyticsTag": null
}
],
"imageUrl": null,
"teasers": [],
"analyticsTag": null,
"hideFromWebValet": false,
"hideFromNativeApps": false,
"visibleToRooms": "102",
"isEncryptedUrl": false,
"isVisibleToAllRooms": false,
"availabilityPeriods": [],
"availabilitySummary": {},
"sectionOutlets": [],
"widgetReferenceCode": null
}
],
"categoryItems": [
{
"code": "12fa0b39-6e65-496c-bba8-b96b93697dec",
"price": 10,
"imageUrl": null,
"directContentParameter": null,
"type": "Product",
"name": "Lunch Item",
"shortDescription": "<p>Lunch Item</p>\r\n",
"longDescription": "<p>Lunch Item</p>\r\n",
"categoryCode": "230725f9-9b5c-45fd-937b-a5b08c2d1674",
"itemCode": "007e69fc-9f60-405f-9740-deb8e60eee84",
"printEnabled": false,
"emailSharingEnable": false,
"qrCodeEnabled": false,
"promo": false,
"directContentType": null,
"availabilityPeriod": null,
"attributes": [],
"availabilityPeriods": [
{
"name": "Lunch",
"description": "Lunch",
"code": "a80f4518-9c00-45bf-9335-bf8bdc0a7feb",
"startTime": "12:00:00",
"endTime": "15:00:00",
"isMonday": true,
"isTuesday": true,
"isWednesday": true,
"isThursday": true,
"isFriday": false,
"isSaturday": false,
"isSunday": true
}
],
"availabilitySummary": {
"monday": {
"periods": [
{
"start": 720,
"end": 900
}
]
},
"tuesday": {
"periods": [
{
"start": 720,
"end": 900
}
]
},
"wednesday": {
"periods": [
{
"start": 720,
"end": 900
}
]
},
"thursday": {
"periods": [
{
"start": 720,
"end": 900
}
]
},
"sunday": {
"periods": [
{
"start": 720,
"end": 900
}
]
}
},
"relatedCategoryItemCodes": [],
"modifiers": [],
"analyticsTag": null,
"templateTag": null,
"buttons": [],
"itemImages": [],
"posItemCode": null,
"isInStock": true,
"spaItemCode": null,
"sosItemCode": null,
"sortOrder": 1
},
{
"code": "b9310f4c-5e33-4460-8d82-0acce29fac2a",
"price": 20,
"imageUrl": null,
"directContentParameter": null,
"type": "Product",
"name": "Product Item with Item Modifiers",
"shortDescription": null,
"longDescription": null,
"categoryCode": "58104a1b-d19c-41a2-a77d-6f2688bfd709",
"itemCode": "2e2da95e-ecb3-4b2e-b659-6c4ed9209c20",
"printEnabled": false,
"emailSharingEnable": false,
"qrCodeEnabled": false,
"promo": false,
"directContentType": null,
"availabilityPeriod": null,
"attributes": [],
"availabilityPeriods": [],
"availabilitySummary": {},
"relatedCategoryItemCodes": [],
"modifiers": [
{
"name": "Visible Multi Select Item Modifier with Invisible Options",
"code": "1b1211ab-d6b1-489f-a3ff-5cf417f82d52",
"posItemCode": null,
"parentModifierOptionCode": null,
"type": "multiselect",
"isRequired": false,
"sortOrder": 2,
"maximumQuantity": null,
"modifierOptions": []
},
{
"name": "Multi Select Item Modifier",
"code": "753dc005-13ac-4831-a228-7c4b542eab84",
"posItemCode": null,
"parentModifierOptionCode": null,
"type": "multiselect",
"isRequired": false,
"sortOrder": 3,
"maximumQuantity": null,
"modifierOptions": [
{
"value": "Option 1",
"code": "dd4bb4e8-ecd4-4504-85a7-bef127d91369",
"price": 0,
"modifierOptionCode": "753dc005-13ac-4831-a228-7c4b542eab84",
"subModifiers": [],
"timeValue": 0,
"name": "Option 1",
"posItemCode": null,
"optionType": "Text"
},
{
"value": "Option 2",
"code": "b821b52d-e453-464b-bfc2-5146ff092321",
"price": 0,
"modifierOptionCode": "753dc005-13ac-4831-a228-7c4b542eab84",
"subModifiers": [],
"timeValue": 0,
"name": "Option 2",
"posItemCode": null,
"optionType": "Text"
}
]
}
],
"analyticsTag": null,
"templateTag": null,
"buttons": [],
"itemImages": [],
"posItemCode": null,
"isInStock": true,
"spaItemCode": null,
"sosItemCode": null,
"sortOrder": 1
}
]
},
"succeeded": true
}
}
],
"status": "Success"
}
I have written below script in Tests
var jsonData = JSON.parse(responseBody);
var i;
categoryItems = _.get(jsonData, 'responses[0].getSectionsCategoriesItemsByGuest.content.categoryItems');
//console.log(categoryItems.length);
modifiers = _.get(jsonData, 'responses[0].getSectionsCategoriesItemsByGuest.content.categoryItems[1].modifiers');
modifierOptions = _.get(jsonData, 'responses[0].getSectionsCategoriesItemsByGuest.content.categoryItems[1].modifiers[0].modifierOptions');
var result;
for (i=0; i<categoryItems.length; i++)
{
for (j=0; j<modifiers.length; j++)
{
if (modifiers[j] !== 0)
{
var size = modifiers[j].modifierOptions.length;
if(size === 0)
{
var categoryItemName = _.get(categoryItems, `${i}.name`);
var modifierName = _.get(modifiers, `${j}.name`);
console.log(categoryItemName +" which has " +modifierName);
result = true;
}
}
else
result = false;
}
}
if (result === true)
console.log("Test case Passed");
else
console.log("Test case Failed");
Output in console is:
Lunch Item which has Visible Multi Select Item Modifier with Invisible Options
Product Item with Item Modifiers which has Visible Multi Select Item Modifier with Invisible Options
Test case Passed
I just want the below result in console:
Product Item with Item Modifiers which has Visible Multi Select Item Modifier with Invisible Options
Test case Passed
Also I want to extract the arrays in for loop instead of writing it as hard coded like below:
categoryItems = _.get(jsonData, 'responses[0].getSectionsCategoriesItemsByGuest.content.categoryItems');
modifiers = _.get(jsonData, 'responses[0].getSectionsCategoriesItemsByGuest.content.categoryItems[1].modifiers');
modifierOptions = _.get(jsonData, 'responses[0].getSectionsCategoriesItemsByGuest.content.categoryItems[1].modifiers[0].modifierOptions');
Could you please help me out on this?