Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
Cypress: ¿cómo almacenar un valor de una solicitud que cambia cada vez que se afirma en él?

Nuestra empresa se está cambiando a Cybersource y tarjetas de crédito tokenizadas. El token es nuevo cada vez.

Estoy tratando de encontrar una manera de almacenar el token de la solicitud y hacer referencia a él para afirmar que es correcto.

Ejemplo de la solicitud:

 request: body: accountRegistrationPreferences: {email: ''} paymentDetails: Array(1) 0: billingAddress: {address: {…}, contactInfo: {…}, personalInfo: {…}} cardId: "eusercc42210010" tokenDetails: referenceId: "bcc8c381-79d6-4a83-a10a-d67e2d585268" token:

"eyJraWQiOiIwOFJORkptMWFIVlhhZUhRaUJrNHZNRFF1MGt3WW9kNCIsImFsZyI6IlJTMjU2In0.eyJkYXRhIjp7ImV4cGlyYXRpb25ZZWFyIjoiMjAzMCIsImV4cGlyYXRpb25Nb250aCI6IjAzIn0sImlzcyI6IkZsZXgvMDgiLCJleHAiOjE2NDQ0MzE2ODQsInR5cGUiOiJtZi0wLjExLjAiLCJpYXQiOjE2NDQ0MzA3ODQsImp0aSI6IjFFNVpSSEQzTFBaUzM0NUdIVVVUUjJQRjdFNzBZSDlKN1dTQjRTWEhTVEJEN08xTFRFUzg2MjA0MDk0NEFBNjIiLCJjb250ZW50Ijp7InBheW1lbnRJbmZvcm1hdGlvbiI6eyJjYXJkIjp7ImV4cGlyYXRpb25ZZWFyIjp7InZhbHVlIjoiMjAzMCJ9LCJzZWN1cml0eUNvZGUiOnt9LCJleHBpcmF0aW9uTW9udGgiOnsidmFsdWUiOiIwMyJ9fX19fQ.bCR73pMD9eXILtZHQRrmqgzcLqI_QCTEVtnQXNPJLOk-RxMUar8LbC1BS59G6FpynCI2rvJVMPixjtes2WRcnM77cjOlTarNM4-VnAJnqKluXy2jx5Hgtn_OrT7aSaS8NOoSyYzwPFlbkqsBMV5oT5kmiHZ8Qn4qBnga8sEYmPFgzoAUUnQ6uWLN1ZkZnKCO8uizZ_HaKUjdUQCyRzgWbtKfTctD9aAi5AcSNgAVbWTV_gt155jFa11v8mLF4iaqA3bLdJfEh4lu9HxB17sOShZBoZvxEQ3fN8gDkk4f56VlswB-aN3J5QFI7me36pgwY5khAhYrFma1o79V-b2KYw"

 type: "tokenizedCreditCard"

Aquí está la prueba de Cypress

 it("User clicks confirm & pay button to complete order", () => { cy.intercept("/api/checkout/payandcommit?*").as("placeOrder"); cy.placeOrderAndPay(); cy.wait("@placeOrder").then((interception) => { console.log(interception); // Order status should equal 200 cy.wrap(interception.response.statusCode).should("eq", 200); // Check payment details card type cy.wrap(interception.request.body.paymentDetails[0].type).should( "include", "tokenizedCreditCard" ); cy.wrap( interception.request.body.paymentDetails[0].tokenDetails.token ).should("include", token); // Check request to ensure delivery charge is passed at £0 due to Unlimited membership. cy.wrap( interception.response.body.response.order.orderPriceInfo.shipping ).should("eq", 0); // Ensure standard delivery is returned in the order response. cy.wrap( interception.response.body.response.order.shippingDetails[0] .shippingMethod.type ).should("include", "standard"); });

});

Esta es la parte con la que estoy luchando:

 cy.wrap( interception.request.body.paymentDetails[0].tokenDetails.token).should("include", token);

¿Cómo puedo almacenar el valor del token que cambia cada vez para poder afirmarlo?

es posible? Cualquier ayuda sería increíble, soy un poco tonto y estoy aprendiendo.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Para probar que la respuesta tiene una propiedad de token,

 cy.wrap(interception.request.body.paymentDetails[0].tokenDetails) .should('have.property', 'token') //or cy.wrap(interception.request.body.paymentDetails[0]) .should('have.deep.property', 'token') // this assertion searches the object

Para almacenar el token, se puede usar un alias.

 cy.wrap(interception.request.body.paymentDetails[0].tokenDetails.token) .as('token') // Later in test cy.get('@token').then(token => { expect(token).to.eq(expectedToken) })

El alias del token obtiene un nuevo valor cada vez que usa .as('token') , por lo que no hay problema con el cambio del valor del token.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!