AgileTesters / forum

Fórum de Discussão do Agile Testers
https://agiletesters.com.br
MIT License
80 stars 2 forks source link

Testar tag do Json no postman #186

Closed allanocosta closed 3 years ago

allanocosta commented 3 years ago

Olá pessoal! Estou aprendendo a trabalhar com API's e encontrei um problema no test que estou fazendo. Preciso ver se a tag "CustomerId" está recebendo o valor que estou passando no body, mas no test que criei está retornando o seguinte erro: AssertionError: expected undefined to equal '13cd9318-7e1c-11e8-8208-8e29971bc2ab'

Test: pm.test("CustomerId is equal to the body", () => { const body = pm.response.json(); pm.expect(body.CustomerId).is.to.equal("13cd9318-7e1c-11e8-8208-8e29971bc2ab"); });

JSON { "data": { "orderFormId": "a36963a8632e4748bd97fc85a0635706", "salesChannel": "2", "loggedIn": false, "isCheckedIn": false, "storeId": null, "checkedInPickupPointId": null, "allowManualPrice": false, "canEditData": false, "userProfileId": "913c67d3-9064-4f4d-9e37-6ee237071d5c", "userType": null, "ignoreProfileData": false, "value": 29999700, "messages": [ { "code": null, "text": "O valor dos itens foi alterado", "status": "warning", "fields": {} } ], "items": [ { "uniqueId": "335F8D6DB1924240AAAFDF4CABD3FF4F", "id": "37", "productId": "38", "productRefId": "14-558", "refId": "14-558", "ean": "076174145588", "name": "14-558 - Tesoura de Aviação - 12\" 14-558", "skuName": "14-558", "modalType": null, "parentItemIndex": null, "parentAssemblyBinding": null, "assemblies": [], "priceValidUntil": "2022-03-04T15:15:42Z", "tax": 0, "price": 9999900, "listPrice": 9999900, "manualPrice": null, "manualPriceAppliedBy": null, "sellingPrice": 9999900, "rewardValue": 0, "isGift": false, "additionalInfo": { "dimension": null, "brandName": "STANLEY", "brandId": "2000005", "offeringInfo": null, "offeringType": null, "offeringTypeId": null }, "preSaleDate": null, "productCategoryIds": "/12/83/132/", "productCategories": { "12": "Ferram. Manuais e Armazenagem", "83": "Corte e Acabamento", "132": "Tesouras" }, "quantity": 1, "seller": "1", "sellerChain": [ "1" ], "imageUrl": "http://sbdbrqa.vteximg.com.br/arquivos/ids/157172-55-55/14-558.jpg?v=636652763122500000", "detailUrl": "/14-558tesouradeaviacao-12/p", "components": [], "bundleItems": [], "attachments": [], "attachmentOfferings": [], "offerings": [], "priceTags": [], "availability": "available", "measurementUnit": "un", "unitMultiplier": 1, "manufacturerCode": null }, { "uniqueId": "F41F9D7209B4495687A2EE5986A9DD1E", "id": "2678", "productId": "2724", "productRefId": "STDH8013-BR", "refId": "STDH8013-BR", "ean": "885911389648", "name": "STDH8013-BR - Furadeira De 13mm 800W STDH8013-BR", "skuName": "STDH8013-BR", "modalType": null, "parentItemIndex": null, "parentAssemblyBinding": null, "assemblies": [], "priceValidUntil": "2022-03-04T15:15:42Z", "tax": 0, "price": 9999900, "listPrice": 9999900, "manualPrice": null, "manualPriceAppliedBy": null, "sellingPrice": 9999900, "rewardValue": 0, "isGift": false, "additionalInfo": { "dimension": null, "brandName": "STANLEY", "brandId": "2000005", "offeringInfo": null, "offeringType": null, "offeringTypeId": null }, "preSaleDate": null, "productCategoryIds": "/10/35/62/", "productCategories": { "10": "Ferramentas Elétricas", "35": "Martelos e Marteletes", "62": "Martelos" }, "quantity": 2, "seller": "1", "sellerChain": [ "1" ], "imageUrl": "http://sbdbrqa.vteximg.com.br/arquivos/ids/157571-55-55/STDR5510_2.jpg?v=636652776783430000", "detailUrl": "/stdh8013-brfuradeirade13mm800w/p", "components": [], "bundleItems": [], "attachments": [], "attachmentOfferings": [], "offerings": [], "priceTags": [], "availability": "available", "measurementUnit": "un", "unitMultiplier": 1, "manufacturerCode": null } ], "selectableGifts": [], "totalizers": [ { "id": "Items", "name": "Total dos Itens", "value": 29999700 }, { "id": "Shipping", "name": "Total do Frete", "value": 0 } ], "shippingData": { "address": { "addressType": "Comercial", "receiverName": "GUR****** ******** * *********** * *", "addressId": "219095", "isDisposable": false, "postalCode": "*****100", "city": "CAJ****", "state": "SP", "country": "BRA", "street": "V A* ***** ** ** *** *******ERA", "number": "*", "neighborhood": "EMP** **** ***** **********", "complement": null, "reference": null, "geoCoordinates": [] }, "logisticsInfo": [ { "itemIndex": 0, "selectedSla": "Normal", "selectedDeliveryChannel": "delivery", "addressId": "219095", "slas": [ { "id": "Normal", "deliveryChannel": "delivery", "name": "Normal", "deliveryIds": [ { "courierId": "150876e", "warehouseId": "CDLO2CML_IPA", "dockId": "CDLO2CML", "courierName": "Transportadora SP", "quantity": 1, "kitItemDetails": [] } ], "shippingEstimate": "3bd", "shippingEstimateDate": null, "lockTTL": null, "availableDeliveryWindows": [], "deliveryWindow": null, "price": 0, "listPrice": 0, "tax": 0, "pickupStoreInfo": { "isPickupStore": false, "friendlyName": null, "address": null, "additionalInfo": null, "dockId": null }, "pickupPointId": null, "pickupDistance": 0, "polygonName": null, "transitTime": "3bd" } ], "shipsTo": [ "BRA" ], "itemId": "37", "deliveryChannels": [ { "id": "delivery" } ] }, { "itemIndex": 1, "selectedSla": "Normal", "selectedDeliveryChannel": "delivery", "addressId": "219095", "slas": [ { "id": "Normal", "deliveryChannel": "delivery", "name": "Normal", "deliveryIds": [ { "courierId": "150876e", "warehouseId": "CDLO2CML_IPA", "dockId": "CDLO2CML", "courierName": "Transportadora SP", "quantity": 2, "kitItemDetails": [] } ], "shippingEstimate": "3bd", "shippingEstimateDate": null, "lockTTL": null, "availableDeliveryWindows": [], "deliveryWindow": null, "price": 0, "listPrice": 0, "tax": 0, "pickupStoreInfo": { "isPickupStore": false, "friendlyName": null, "address": null, "additionalInfo": null, "dockId": null }, "pickupPointId": null, "pickupDistance": 0, "polygonName": null, "transitTime": "3bd" } ], "shipsTo": [ "BRA" ], "itemId": "2678", "deliveryChannels": [ { "id": "delivery" } ] } ], "selectedAddresses": [ { "addressType": "Comercial", "receiverName": "GUR****** ******** * *********** * *", "addressId": "219095", "isDisposable": false, "postalCode": "*****100", "city": "CAJ****", "state": "SP", "country": "BRA", "street": "V A* ***** ** ** *** *******ERA", "number": "*", "neighborhood": "EMP** **** ***** **********", "complement": null, "reference": null, "geoCoordinates": [] } ], "availableAddresses": [ { "addressType": "Comercial", "receiverName": "GUR****** ******** * *********** * *", "addressId": "219095", "isDisposable": false, "postalCode": "*****100", "city": "CAJ****", "state": "SP", "country": "BRA", "street": "V A* ***** ** ** *** *******ERA", "number": "*", "neighborhood": "EMP** **** ***** **********", "complement": null, "reference": null, "geoCoordinates": [] } ], "pickupPoints": [] }, "clientProfileData": { "email": "josielfermino+219095@gurgelmix.com.br", "firstName": "GUR****** ******** * *********** * *", "lastName": "219***", "document": "*1*1*5*2*8*", "documentType": "cpf", "phone": "******0832", "corporateName": "GURGE**** ******** * *********** * *", "tradeName": "GU******* ******** * *********** * *", "corporateDocument": "*9*0*3*8*0*3*7", "stateInscription": "ISENTO", "corporatePhone": "** **** 1111", "isCorporate": true, "profileCompleteOnLoading": true, "profileErrorOnLoading": false, "customerClass": null }, "paymentData": { "installmentOptions": [ { "paymentSystem": "64", "bin": null, "paymentName": null, "paymentGroupName": null, "value": 29999700, "installments": [ { "count": 1, "hasInterestRate": false, "interestRate": 0, "value": 29999700, "total": 29999700, "sellerMerchantInstallments": [ { "id": "SBDBRQA", "count": 1, "hasInterestRate": false, "interestRate": 0, "value": 29999700, "total": 29999700 } ] }, { "count": 2, "hasInterestRate": false, "interestRate": 0, "value": 14999850, "total": 29999700, "sellerMerchantInstallments": [ { "id": "SBDBRQA", "count": 2, "hasInterestRate": false, "interestRate": 0, "value": 14999850, "total": 29999700 } ] }, { "count": 3, "hasInterestRate": false, "interestRate": 0, "value": 9999900, "total": 29999700, "sellerMerchantInstallments": [ { "id": "SBDBRQA", "count": 3, "hasInterestRate": false, "interestRate": 0, "value": 9999900, "total": 29999700 } ] }, { "count": 4, "hasInterestRate": false, "interestRate": 0, "value": 7499925, "total": 29999700, "sellerMerchantInstallments": [ { "id": "SBDBRQA", "count": 4, "hasInterestRate": false, "interestRate": 0, "value": 7499925, "total": 29999700 } ] }, { "count": 5, "hasInterestRate": false, "interestRate": 0, "value": 5999940, "total": 29999700, "sellerMerchantInstallments": [ { "id": "SBDBRQA", "count": 5, "hasInterestRate": false, "interestRate": 0, "value": 5999940, "total": 29999700 } ] } ] }, { "paymentSystem": "201", "bin": null, "paymentName": null, "paymentGroupName": null, "value": 29999700, "installments": [ { "count": 1, "hasInterestRate": false, "interestRate": 0, "value": 29999700, "total": 29999700, "sellerMerchantInstallments": [ { "id": "SBDBRQA", "count": 1, "hasInterestRate": false, "interestRate": 0, "value": 29999700, "total": 29999700 } ] } ] }, { "paymentSystem": "601", "bin": null, "paymentName": null, "paymentGroupName": null, "value": 29999700, "installments": [ { "count": 1, "hasInterestRate": false, "interestRate": 0, "value": 29999700, "total": 29999700, "sellerMerchantInstallments": [ { "id": "SBDBRQA", "count": 1, "hasInterestRate": false, "interestRate": 0, "value": 29999700, "total": 29999700 } ] } ] } ], "paymentSystems": [ { "id": 201, "name": "Pedido Bonificação", "groupName": "custom201PaymentGroupPaymentGroup", "validator": { "regex": null, "mask": null, "cardCodeRegex": null, "cardCodeMask": null, "weights": null, "useCvv": false, "useExpirationDate": false, "useCardHolderName": false, "useBillingAddress": false }, "stringId": "201", "template": "custom201PaymentGroupPaymentGroup-template", "requiresDocument": false, "isCustom": true, "description": "Pedido Bonificação", "requiresAuthentication": false, "dueDate": "2021-03-11T15:15:44.1157132Z", "availablePayments": null }, { "id": 601, "name": "CardPromissory", "groupName": "cardPromissoryPaymentGroup", "validator": { "regex": null, "mask": null, "cardCodeRegex": null, "cardCodeMask": null, "weights": null, "useCvv": false, "useExpirationDate": false, "useCardHolderName": false, "useBillingAddress": false }, "stringId": "601", "template": "cardPromissoryPaymentGroup-template", "requiresDocument": false, "isCustom": false, "description": null, "requiresAuthentication": false, "dueDate": "2021-03-11T15:15:44.1157132Z", "availablePayments": [ { "Id": 1, "Name": "American Express" }, { "Id": 2, "Name": "Visa" }, { "Id": 3, "Name": "Diners" }, { "Id": 4, "Name": "Mastercard" } ] }, { "id": 64, "name": "Customer Credit", "groupName": "creditControlPaymentGroup", "validator": { "regex": null, "mask": null, "cardCodeRegex": null, "cardCodeMask": null, "weights": null, "useCvv": false, "useExpirationDate": false, "useCardHolderName": false, "useBillingAddress": false }, "stringId": "64", "template": "creditControlPaymentGroup-template", "requiresDocument": false, "isCustom": false, "description": null, "requiresAuthentication": false, "dueDate": "2021-03-11T15:15:44.1157132Z", "availablePayments": null } ], "payments": [], "giftCards": [], "giftCardMessages": [], "availableAccounts": [], "availableTokens": [] }, "marketingData": null, "sellers": [ { "id": "1", "name": "Stanley Black & Decker, Inc.", "logo": "" } ], "clientPreferencesData": { "locale": "pt-BR", "optinNewsLetter": false }, "commercialConditionData": null, "storePreferencesData": { "countryCode": "BRA", "saveUserData": true, "timeZone": "E. South America Standard Time", "currencyCode": "BRL", "currencyLocale": 1046, "currencySymbol": "R$", "currencyFormatInfo": { "currencyDecimalDigits": 2, "currencyDecimalSeparator": ",", "currencyGroupSeparator": ".", "currencyGroupSize": 3, "startsWithCurrencySymbol": true } }, "giftRegistryData": null, "openTextField": null, "invoiceData": null, "customData": { "customApps": [ { "fields": { "CustomerId": "13cd9318-7e1c-11e8-8208-8e29971bc2ab", "PaymentTerm": "x", "PaymentTermDescription": "x", "NatureOperation": "x", "OrderType": "x", "PoNumber": "x", "DeliveryDateBegin": "08/02/2021", "DeliveryDateEnd": "08/03/2021", "CorporateEmail": "agarotinhaita@hotmail.com", "RepresentativeId": "gxm0901a" }, "id": "order-details", "major": 1 } ] }, "itemMetadata": { "items": [ { "id": "37", "seller": "1", "name": "14-558 - Tesoura de Aviação - 12\" 14-558", "skuName": "14-558", "productId": "38", "refId": "14-558", "ean": "076174145588", "imageUrl": "http://sbdbrqa.vteximg.com.br/arquivos/ids/157172-55-55/14-558.jpg?v=636652763122500000", "detailUrl": "/14-558tesouradeaviacao-12/p", "assemblyOptions": [] }, { "id": "2678", "seller": "1", "name": "STDH8013-BR - Furadeira De 13mm 800W STDH8013-BR", "skuName": "STDH8013-BR", "productId": "2724", "refId": "STDH8013-BR", "ean": "885911389648", "imageUrl": "http://sbdbrqa.vteximg.com.br/arquivos/ids/157571-55-55/STDR5510_2.jpg?v=636652776783430000", "detailUrl": "/stdh8013-brfuradeirade13mm800w/p", "assemblyOptions": [] } ] }, "hooksData": null, "ratesAndBenefitsData": { "rateAndBenefitsIdentifiers": [], "teaser": [] }, "subscriptionData": null, "itemsOrdination": null } }

leoGalani commented 3 years ago

parece que vc está usando node-fetch....

O método .json() é um método async, sendo assim, vc precisa esperar pelo retorno

const body = await pm.response.json();

E também vc precisa tornar o it de teste async para funcionar direito.