Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

215- add shared context for when user is not authenticated #216

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions backend/spec/requests/api/v1/hello_word_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,7 @@
describe "GET /api/v1/private_method" do
let(:user) { create(:user) }

context "when user is not authenticated" do
before do
get "/api/v1/private_method"
end

it "renders json with message" do
expect(response.body).to include("error", "Invalid token")
end

it "receives http status unauthorized" do
expect(response).to have_http_status(:unauthorized)
end
end
include_context "when user is not authenticated"

context "when user is authenticated" do
let(:instance_token) { Devise::Api::TokensService::Create.new(resource_owner: user, previous_refresh_token: nil) }
Expand Down
13 changes: 13 additions & 0 deletions backend/spec/support/shared_examples/requests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
RSpec.shared_context "when user is not authenticated" do
before do
get "/api/v1/private_method"
end

it "renders json with message" do
expect(response.body).to include("error", "Invalid token")
end

it "receives http status unauthorized" do
expect(response).to have_http_status(:unauthorized)
end
end
Loading