diff --git a/app/controllers/api/v0/chat_channels_controller.rb b/app/controllers/api/v0/chat_channels_controller.rb index a34254b5b..7278e1a55 100644 --- a/app/controllers/api/v0/chat_channels_controller.rb +++ b/app/controllers/api/v0/chat_channels_controller.rb @@ -1,9 +1,9 @@ module Api module V0 - class ChatChannelsController < ApplicationController + class ChatChannelsController < ApiController def show @chat_channel = ChatChannel.find(params[:id]) - raise unless @chat_channel.has_member?(current_user) + error_not_found unless @chat_channel.has_member?(current_user) end end end diff --git a/spec/requests/api/v0/chat_channels_spec.rb b/spec/requests/api/v0/chat_channels_spec.rb new file mode 100644 index 000000000..286f41688 --- /dev/null +++ b/spec/requests/api/v0/chat_channels_spec.rb @@ -0,0 +1,27 @@ +require "rails_helper" + +RSpec.describe "Api::V0::ChatChannels", type: :request do + let(:user) { create(:user) } + let(:chat_channel) { create(:chat_channel) } + let(:invite_channel) { create(:chat_channel, channel_type: "invite_only") } + + before { sign_in user } + + describe "GET /api/chat_channels/:id" do + it "returns 200 if user is a member of the channel" do + chat_channel.add_users([user]) + get "/api/chat_channels/#{chat_channel.id}" + expect(response).to have_http_status(:ok) + end + + it "returns a 404 if user is not a memeber of the channel" do + get "/api/chat_channels/#{invite_channel.id}" + expect(response.status).to eq(404) + end + + it "returns a 404 if channel is not found" do + get "/api/chat_channels/#{invite_channel.id + 100}" + expect(response.status).to eq(404) + end + end +end