lundi 29 juin 2020

How to change stub for RSpec

I have a stub that returns a 422 for this test. This is in order to generate a modal that asks the user if they are sure they want to continue. When they click "yes, continue" I'd like the stub to return 200 and for the test to take the user back to the main page. How could I do that? When I try putting in the stub I want, it seems the stub that was written last is the one that gets used. Seems like I cannot do both. It seems that when the save-refund-confirmation-button gets clicked, the 422 stub is called a second time. I want the 200 stub to be used.

scenario 'successfully saves refund when user clicks yes continue on similar refund', js: true do
      save_payer_refund_success_request = stub_request(:post, /remittances/).to_return(status: 200)
      save_payer_refund_fail_request = stub_request(:post, /remittances/).to_return(status:422, body: {error: "SIMILAR_REMITTANCE"}.to_json)
      visit record_refund_check_by_payer_remittances_path

      #Test fils out the form here

      page.find_by_id('refund_record').click
      wait_for_ajax
      expect(save_payer_refund_fail_request).to have_been_made # <--- This works
      expect(page).to have_content 'A refund from this payer with this number with the amount of $' + @refundTotalAmount + ' and date of ' + @EFTCheckDate + ' already exists in Value-Based Reimbursement. Are you sure you want to record this refund?'
      page.find_by_id('save-refund-confirmation-button').click
      wait_for_ajax
      expect(save_payer_refund_success_request).to have_been_made # <--- Fails here
      expect(page).to have_content 'Refund check ' + @checkNumber + ' to payer has been saved.'

Aucun commentaire:

Enregistrer un commentaire