Skip to content

Commit

Permalink
#32 Add get circle statuses test
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Sep 26, 2023
1 parent af62d7f commit 60241d9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
1 change: 0 additions & 1 deletion app/controllers/api/v1/circles/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class Api::V1::Circles::StatusesController < Api::BaseController
before_action -> { doorkeeper_authorize! :read, :'read:lists' }, only: [:show]
before_action -> { doorkeeper_authorize! :write, :'write:lists' }, except: [:show]

before_action :require_user!
before_action :set_circle
Expand Down
43 changes: 43 additions & 0 deletions spec/controllers/api/v1/circles/statuses_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

require 'rails_helper'

describe Api::V1::Circles::StatusesController do
render_views

let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:lists') }
let(:circle) { Fabricate(:circle, account: user.account) }
let(:status) { Fabricate(:status, account: user.account, visibility: 'limited', limited_scope: 'circle') }

before do
allow(controller).to receive(:doorkeeper_token) { token }
Fabricate(:circle_status, status: status, circle: circle)
other_circle = Fabricate(:circle)
Fabricate(:circle_status, status: Fabricate(:status, visibility: 'limited', limited_scope: 'circle', account: other_circle.account), circle: other_circle)
end

describe 'GET #index' do
it 'returns http success' do
get :show, params: { circle_id: circle.id, limit: 1 }

expect(response).to have_http_status(200)
json = body_as_json
expect(json.map { |item| item[:id].to_i }).to eq [status.id]
end

context "with someone else's statuses" do
let(:other_account) { Fabricate(:account) }
let(:other_circle) { Fabricate(:circle, account: other_account) }

before do
Fabricate(:circle_status, circle: other_circle, status: Fabricate(:status, account: other_account, visibility: 'limited', limited_scope: 'circle'))
end

it 'returns http failed' do
get :show, params: { circle_id: other_circle.id }
expect(response).to have_http_status(404)
end
end
end
end
6 changes: 6 additions & 0 deletions spec/fabricators/circle_status_fabricator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

Fabricator(:circle_status) do
circle { Fabricate.build(:circle) }
status { Fabricate.build(:status) }
end

0 comments on commit 60241d9

Please sign in to comment.