I am trying to create some random test data for my project, and I am trying to this with Postman pre-request script. My problem is that I have some values in array, and I am trying to get values from them. This is my Postmans pre-request script:
var images = [
"\\advertisement\\86b37148-70b6qKhw-4ce7MZbh-a287osa0-b8fadf350955.jpg",
"\\advertisement\\c54acd53-6caaYlaU-4e5963l2-955b0XNs-63e9376787ca.jpg",
"\\advertisement\\86deb41e-55d82qT0-4919xLYP-9562yjcg-82b1e565c45e.jpg"
];
var objectHeating = [
"NotSet",
"CentralHeating",
"ElectricHeating",
"TtermoaccumulationStove",
"Gas",
"AtTheFoot",
"TileStove",
"MarbleRadiators",
"NorwegianRadiators"
];
var objectDescription = [
"NotSet",
"NewConstruction",
"OldConstruction",
"UnderConstruction",
"Upgrade",
"ApartmentInTheHouse"
];
var objectPropertyCondition = [
"NotSet",
"OriginalState",
"Renovated",
"Luxury",
"ForRenovation"
];
var objectOrientation = [
"NotSet",
'East',
"West",
"North",
"South",
"Northwest",
"Northeast",
"Southwest",
"Southeast"
];
var objectStructure = [
"NotSet",
"Studio",
"Workshop",
"OneBedroom",
"OneAndHalfBedrooms",
"TwoBedrooms",
"TwoAndHalfBedrooms",
"ThreeBedrooms",
"ThreeAndHalfBedrooms",
"FourBedrooms",
"FourAndHalfBedrooms",
"FiveBedrooms",
"FiveAndHalfBedrooms"
];
var objectBelongingSurfaces = [
"NotSet",
"GroundFloor",
"Attic"
];
var _mainCategories = [
"GARAZA",
"POSLOVNI_PROSTOR",
"STAMBENI_PPROSTOR",
"UGOSTITELJSKI_OBJEKAT",
"VIKENDICA",
"ZEMLJISTE"
];
var _subCategories = [
"PODZEMNA",
"NADZEMNA",
"LOKAL",
"KANCELARIJSKI_POSLOVNI_PROSTOR",
"POSLOVNA_ZGRADA",
"HALA",
"MAGACIN",
"KIOSK",
"STOVARISTE",
"STAN",
"KUCA",
"SOBA",
"ATELJE",
"STAN_NA_DAN",
"KAFIC",
"KAFANA",
"SMESTAJ",
"APARTMAN",
"BUNGALOV",
"SPLAV",
"KLUB",
"RESTORAN",
"KOLIBA",
"HOTEL",
"MOTEL",
"SALAS",
"ETNO_SELO",
"SPA",
"DISKOTEKA",
"PEKARA",
"IGRAONICA",
"BROD_RESTORAN",
"VILA",
"VINARIJA",
"KUHINJA",
"HOSTEL",
"PLANINSKA",
"JEZERSKA",
"MORSKA",
"RECNA",
"GRADJEVINSKO",
"INDUSTRIJSKO",
"POLJOPRIVREDNO"
];
pm.environment.set("subCategoryKey", _.shuffle(this._subCategories)[0]);
pm.environment.set("isRentable", _.$randomBoolean);
pm.environment.set("title", _.$randomLoremSentence);
pm.environment.set("price", _.random(0, 100000001));
pm.environment.set("latitude", _.$randomLatitude);
pm.environment.set("longitude", _.$randomLongitude);
pm.environment.set("address", _.$randomStreetAddress);
pm.environment.set("location", _.$randomCountry);
pm.environment.set("cityLocationID", _.random(0, 495));
pm.environment.set("quadrature", _.random(0, 100000000));
pm.environment.set("apartmentLevel", _.random(0, 101));
pm.environment.set("floorsOfTheBuilding", _.random(0, 101));
pm.environment.set("heatingType", _.shuffle(this.objectHeating)[0]);
pm.environment.set("objectDescription", _.shuffle(this.objectDescription)[0]);
pm.environment.set("constructionYear", _.random(0, 2020));
pm.environment.set("propertyCondition", _.shuffle(this.objectPropertyCondition)[0]);
pm.environment.set("badrooms", _.random(0, 11));
pm.environment.set("bathrooms", _.random(0, 11));
pm.environment.set("toilets", _.random(0, 11));
pm.environment.set("pantries", _.random(0, 11));
pm.environment.set("commonAreas", _.random(0, 11));
pm.environment.set("orientation", _.shuffle(this.objectOrientation)[0]);
pm.environment.set("structure", _.shuffle(this.objectStructure)[0]);
pm.environment.set("belongingSurfaces", _.shuffle(this.objectBelongingSurfaces)[0]);
pm.environment.set("additionalDescription", _.$randomLoremParagraphs);
pm.environment.set("showcase3D", _.$randomCityImage);
pm.environment.set("videoURL", _.$randomImageUrl);
pm.environment.set("duplex", _.$randomBoolean);
pm.environment.set("laundryAndDryingRoom", _.$randomBoolean);
pm.environment.set("balcony", _.$randomBoolean);
pm.environment.set("filed", _.$randomBoolean);
pm.environment.set("wardrobe", _.$randomBoolean);
pm.environment.set("active", _.$randomBoolean);
pm.environment.set("images", this.images);
My request looks like this:
{
"Images": {{images}},
"subCategoryKey" : "{{subCategoryKey}}",
"isRentable": "{{isRentable}}",
"title": "{{title}}",
"price": "{{price}}",
"latitude": "{{latitude}}",
"longitude": "{{longitude}}",
"address": "{{address}}",
"location" : "{{location}}",
"cityLocationID" : "{{cityLocationID}}",
"quadrature": "{{quadrature}}",
"apartmentLevel": "{{apartmentLevel}}",
"floorsOfTheBuilding": "{{floorsOfTheBuilding}}",
"constructionYear": "{{constructionYear}}",
"badrooms": "{{badrooms}}",
"bathrooms": "{{bathrooms}}",
"toilets": "{{toilets}}",
"pantries": "{{pantries}}",
"commonAreas": "{{commonAreas}}",
"additionalDescription": "{{additionalDescription}}",
"showcase3D": "{{showcase3D}}",
"videoURL": "{{videoURL}}",
"duplex": "{{duplex}}",
"laundryAndDryingRoom": "{{laundryAndDryingRoom}}",
"balcony": "{{balcony}}",
"filed": "{{filed}}",
"wardrobe": "{{wardrobe}}",
"active" : "{{active}}",
"structure": "{{structure}}",
"heatingType": "{{heatingType}}",
"orientation": "{{orientation}}",
"belongingSurfaces": "{{belongingSurfaces}}",
"objectDescription": "{{objectDescription}}",
"propertyCondition": "{{propertyCondition}}"
}
And I got the following error:
{
"structure": [
"Error converting value \"\" to type 'portalnekretnine.models.enums.AdvertisementObjectStructure'. Path 'structure', line 30, position 19."
],
"heatingType": [
"Error converting value \"\" to type 'portalnekretnine.models.enums.AdvertisementObjectHeating'. Path 'heatingType', line 31, position 21."
],
"orientation": [
"Error converting value \"\" to type 'portalnekretnine.models.enums.AdvertisementObjectOrientation'. Path 'orientation', line 32, position 21."
],
"belongingSurfaces": [
"Error converting value \"\" to type 'portalnekretnine.models.enums.AdvertisementObjectBelongingSurfaces'. Path 'belongingSurfaces', line 33, position 27."
],
"objectDescription": [
"Error converting value \"\" to type 'portalnekretnine.models.enums.AdvertisementObjectDescription'. Path 'objectDescription', line 34, position 27."
],
"propertyCondition": [
"Error converting value \"\" to type 'portalnekretnine.models.enums.AdvertisementObjectPropertyCondition'. Path 'propertyCondition', line 35, position 27."
]
}