Skip to content

Instantly share code, notes, and snippets.

@aarkerio
Last active July 2, 2023 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarkerio/21837272b3eff1f37170d1eb09270032 to your computer and use it in GitHub Desktop.
Save aarkerio/21837272b3eff1f37170d1eb09270032 to your computer and use it in GitHub Desktop.
Rails 6 Rspec: Validates json web token API request with signed cookie
# 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