Sha256: e028779d919fbbf5fbc99957e715608ca0aac99615e292390db38c17aec83515

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

RSpec.shared_examples :user_authentication do |_action|
  context "when the token is invalid" do
    let(:headers) {{Authorization: "invalid_token"}}

    it "returns a 401 status" do
      expect(response.status).to eq 401
      expect(json_response["success"]).to eq false
      expect(json_response["errors"][0]["code"]).to eq 1204
      expect(json_response["errors"][0]["message"]).to eq "Invalid Token"
    end
  end

  context "when the token is invalid type" do
    let(:headers) {{Authorization: JsonWebToken.encode({id: user.id, resource_type: "invalid_type"})}}

    it "returns a 401 status" do
      expect(response.status).to eq 401
      expect(json_response["success"]).to eq false
      expect(json_response["errors"][0]["code"]).to eq 1204
      expect(json_response["errors"][0]["message"]).to eq "Invalid Token"
    end
  end

  context "when the token is invalid author resource" do
    let(:headers) {{Authorization: JsonWebToken.encode({id: 0, resource_type: "User"})}}

    it "returns a 401 status" do
      expect(response.status).to eq 401
      expect(json_response["success"]).to eq false
      expect(json_response["errors"][0]["code"]).to eq 1204
      expect(json_response["errors"][0]["message"]).to eq "Invalid Token"
    end
  end

  context "when the token is invalid device" do
    let(:headers) {{Authorization: JsonWebToken.encode({id: user.id, resource_type: "User", device_id: 0})}}

    it "returns a 401 status" do
      expect(response.status).to eq 401
      expect(json_response["success"]).to eq false
      expect(json_response["errors"][0]["code"]).to eq 1204
      expect(json_response["errors"][0]["message"]).to eq "Invalid Token"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
n_base_rails-0.1.2 lib/spec/supports/shared_example/user_authentication.rb
n_base_rails-0.1.1 lib/spec/supports/shared_example/user_authentication.rb