RahulOnRails
RahulOnRails

Reputation: 6542

Rails 5 + Rspec + API Testcase inside MODEL or Request

Rails 5 + Rspec + API Testcase inside MODEL or Request

Code:

require "rails_helper"
RSpec.describe "req", :type => :request do
  it "creates a api request page" do
    headers = {
      'Content-Type' => 'application/json',
      'Authorization' => 'Basic bW9oZC5hbmFzQG6bW9oZGFuYXNAMTIz',
      'Token' => "222222222222222222"
    }
    get "/api/product/list", {}, headers
    expect(response.status).to eq(200)
  end
end

I am getting Unauthorised error message and token I passed is correct. AuthorisedCode is passed through token.

Please suggest something

Upvotes: 0

Views: 146

Answers (1)

CaDs
CaDs

Reputation: 106

Your headers looks right, maybe the Unauthorized errors comes from somewhere else. Are you sure the token that you are sending to the back end exists?

Upvotes: 1

Related Questions