Skip to content

Commit

Permalink
Add specs for new api endpoints for watchlist and to support the old api
Browse files Browse the repository at this point in the history
Signed-off-by: Rubhan Azeem <rubhanazeem@gmail.com>
  • Loading branch information
rubhanazeem committed Apr 28, 2022
1 parent ebcd12f commit 1df6fa3
Showing 1 changed file with 78 additions and 2 deletions.
80 changes: 78 additions & 2 deletions src/api/spec/controllers/person_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,33 @@
let(:xml) do
<<-XML_DATA
<userinfo>
<realname>test name</realname>
<email>test@test.de</email>
<realname>test-user</realname>
<email>test-user@email.com</email>
<watchlist>
<project name="test-proj"/>
<package name="test-pkg" project="test-proj"/>
</watchlist>
</userinfo>
XML_DATA
end

context 'when watchlist is available in xml' do
let(:test_user) { create(:confirmed_user, login: 'test-user', email: 'test-user@email.com') }
let(:project) { create(:project, name: 'test-proj') }

before do
create(:package, project: project, name: 'test-pkg')
Flipper.enable_actor(:new_watchlist, admin_user)
login admin_user
put :put_userinfo, params: { login: test_user.login, format: :xml }, body: xml
end

it "adds projects and packages to user's watchlist" do
expect(test_user.watched_items.count).to eq(2)
expect(test_user.watched_items.collect(&:watchable)).to include(project)
end
end

context 'when in LDAP mode' do
before do
stub_const('CONFIG', CONFIG.merge('ldap_mode' => :on))
Expand Down Expand Up @@ -174,4 +195,59 @@
end
end
end

describe 'GET #get_watchlist' do
context 'user logged-in' do
let(:xml) do
<<-XML_DATA
<watchlist>
<project name="test-proj"/>
<package name="test-pkg" project="test-proj"/>
</watchlist>
XML_DATA
end

before do
project = create(:project, name: 'test-proj')
package = create(:package, project: project, name: 'test-pkg')
Flipper.enable_actor(:new_watchlist, user)
user.watched_items.create(watchable: project)
user.watched_items.create(watchable: package)
login user
end

subject! { get :get_watchlist, params: { login: user.login } }

it 'returns watchlist' do
expect(Xmlhash.parse(response.body)).to eq(Xmlhash.parse(xml))
end
end
end

describe 'PUT #put_watchlist' do
context 'creates watchlist' do
let(:xml) do
<<-XML_DATA
<watchlist>
<project name="test-proj"/>
<package name="test-pkg" project="test-proj"/>
</watchlist>
XML_DATA
end

let!(:project) { create(:project, name: 'test-proj') }
let!(:package) { create(:package, project: project, name: 'test-pkg') }

before do
Flipper.enable_actor(:new_watchlist, user)
login user
put :put_watchlist, params: { login: user.login, format: :xml }, body: xml
end

it "adds projects and packages to user's watchlist" do
expect(user.watched_items.count).to eq(2)
expect(user.watched_items.collect(&:watchable)).to include(project, package)
end
end
end
end

0 comments on commit 1df6fa3

Please sign in to comment.