diff options
Diffstat (limited to 'spec/requests/api')
-rw-r--r-- | spec/requests/api/events_spec.rb | 20 | ||||
-rw-r--r-- | spec/requests/api/graphql/group_query_spec.rb | 3 | ||||
-rw-r--r-- | spec/requests/api/groups_spec.rb | 22 | ||||
-rw-r--r-- | spec/requests/api/releases_spec.rb | 21 |
4 files changed, 63 insertions, 3 deletions
diff --git a/spec/requests/api/events_spec.rb b/spec/requests/api/events_spec.rb index acf3bb3482a..decdcc66327 100644 --- a/spec/requests/api/events_spec.rb +++ b/spec/requests/api/events_spec.rb @@ -114,6 +114,26 @@ describe API::Events do expect(json_response.size).to eq(1) end + context 'when the list of events includes wiki page events' do + it 'returns information about the wiki event', :aggregate_failures do + page = create(:wiki_page, project: private_project) + [Event::CREATED, Event::UPDATED, Event::DESTROYED].each do |action| + create(:wiki_page_event, wiki_page: page, action: action, author: user) + end + + get api("/users/#{user.id}/events", user) + + wiki_events = json_response.select { |e| e['target_type'] == 'WikiPage::Meta' } + action_names = wiki_events.map { |e| e['action_name'] } + titles = wiki_events.map { |e| e['target_title'] } + slugs = wiki_events.map { |e| e.dig('wiki_page', 'slug') } + + expect(action_names).to contain_exactly('created', 'updated', 'destroyed') + expect(titles).to all(eq(page.title)) + expect(slugs).to all(eq(page.slug)) + end + end + context 'when the list of events includes push events' do let(:event) do create(:push_event, author: user, project: private_project) diff --git a/spec/requests/api/graphql/group_query_spec.rb b/spec/requests/api/graphql/group_query_spec.rb index a38d1857076..c7b537a9923 100644 --- a/spec/requests/api/graphql/group_query_spec.rb +++ b/spec/requests/api/graphql/group_query_spec.rb @@ -51,6 +51,7 @@ describe 'getting group information', :do_not_mock_admin_mode do it "returns one of user1's groups" do project = create(:project, namespace: group2, path: 'Foo') + issue = create(:issue, project: create(:project, group: group1)) create(:project_group_link, project: project, group: group1) post_graphql(group_query(group1), current_user: user1) @@ -67,6 +68,8 @@ describe 'getting group information', :do_not_mock_admin_mode do expect(graphql_data['group']['fullName']).to eq(group1.full_name) expect(graphql_data['group']['fullPath']).to eq(group1.full_path) expect(graphql_data['group']['parentId']).to eq(group1.parent_id) + expect(graphql_data['group']['issues']['nodes'].count).to eq(1) + expect(graphql_data['group']['issues']['nodes'][0]['iid']).to eq(issue.iid.to_s) end it "does not return a non existing group" do diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb index cec4995c620..ea60f783b48 100644 --- a/spec/requests/api/groups_spec.rb +++ b/spec/requests/api/groups_spec.rb @@ -71,6 +71,7 @@ describe API::Groups do expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.length).to eq(1) + expect(json_response.first['created_at']).to be_present expect(json_response) .to satisfy_one { |group| group['name'] == group1.name } end @@ -121,6 +122,15 @@ describe API::Groups do expect(json_response).to be_an Array expect(json_response.first).not_to include 'statistics' end + + it "includes a created_at timestamp" do + get api("/groups", user1) + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.first['created_at']).to be_present + end end context "when authenticated as admin" do @@ -152,6 +162,15 @@ describe API::Groups do expect(json_response.first).not_to include('statistics') end + it "includes a created_at timestamp" do + get api("/groups", admin) + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.first['created_at']).to be_present + end + it "includes statistics if requested" do attributes = { storage_size: 1158, @@ -357,6 +376,7 @@ describe API::Groups do expect(response).to have_gitlab_http_status(:ok) expect(json_response).not_to include('runners_token') + expect(json_response).to include('created_at') end it 'returns only public projects in the group' do @@ -407,6 +427,7 @@ describe API::Groups do expect(json_response['full_name']).to eq(group1.full_name) expect(json_response['full_path']).to eq(group1.full_path) expect(json_response['parent_id']).to eq(group1.parent_id) + expect(json_response['created_at']).to be_present expect(json_response['projects']).to be_an Array expect(json_response['projects'].length).to eq(2) expect(json_response['shared_projects']).to be_an Array @@ -613,6 +634,7 @@ describe API::Groups do expect(json_response['subgroup_creation_level']).to eq("maintainer") expect(json_response['request_access_enabled']).to eq(true) expect(json_response['parent_id']).to eq(nil) + expect(json_response['created_at']).to be_present expect(json_response['projects']).to be_an Array expect(json_response['projects'].length).to eq(2) expect(json_response['shared_projects']).to be_an Array diff --git a/spec/requests/api/releases_spec.rb b/spec/requests/api/releases_spec.rb index 41999ca6e60..e66e999dc27 100644 --- a/spec/requests/api/releases_spec.rb +++ b/spec/requests/api/releases_spec.rb @@ -104,6 +104,21 @@ describe API::Releases do expect(json_response.first['upcoming_release']).to eq(false) end + it 'avoids N+1 queries' do + create(:release, :with_evidence, project: project, tag: 'v0.1', author: maintainer) + + control_count = ActiveRecord::QueryRecorder.new do + get api("/projects/#{project.id}/releases", maintainer) + end.count + + create(:release, :with_evidence, project: project, tag: 'v0.1', author: maintainer) + create(:release, :with_evidence, project: project, tag: 'v0.1', author: maintainer) + + expect do + get api("/projects/#{project.id}/releases", maintainer) + end.not_to exceed_query_limit(control_count) + end + context 'when tag does not exist in git repository' do let!(:release) { create(:release, project: project, tag: 'v1.1.5') } @@ -725,7 +740,7 @@ describe API::Releases do end it 'does not create an Evidence object', :sidekiq_inline do - expect { subject }.not_to change(Evidence, :count) + expect { subject }.not_to change(Releases::Evidence, :count) end it 'is a historical release' do @@ -755,7 +770,7 @@ describe API::Releases do end it 'creates Evidence', :sidekiq_inline do - expect { subject }.to change(Evidence, :count).by(1) + expect { subject }.to change(Releases::Evidence, :count).by(1) end it 'is not a historical release' do @@ -785,7 +800,7 @@ describe API::Releases do end it 'creates Evidence', :sidekiq_inline do - expect { subject }.to change(Evidence, :count).by(1) + expect { subject }.to change(Releases::Evidence, :count).by(1) end it 'is not a historical release' do |