Last active
July 2, 2023 18:40
-
-
Save aarkerio/21837272b3eff1f37170d1eb09270032 to your computer and use it in GitHub Desktop.
Rails 6 Rspec: Validates json web token API request with signed cookie
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
RSpec.describe Api::V2::DonationsController, type: :request do | |
let(:donor) { Fabricate(:donor) } | |
before do | |
cookies = ActionDispatch::Request.new(Rails.application.env_config.deep_dup).cookie_jar | |
@tmp = cookies.signed[:donor_jwtapi] = { value: { token: donor.token} , httponly: true } | |
end | |
describe 'POST#create' do | |
it 'create a bank account donation' do | |
post api_v2_donations_path, params: {donor_id: donor.id}, headers: { Cookie: "donor_jwtapi=#{@tmp[:value]};" }, as: :json | |
json_response = JSON.parse response.body | |
expect(response).to have_http_status :ok | |
expect(json_response['error']).to be false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment