2021-01-29 00:20:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe 'Project noteable notes', feature_category: :team_planning do
|
2021-01-29 00:20:46 +05:30
|
|
|
describe '#index' do
|
|
|
|
let_it_be(:merge_request) { create(:merge_request) }
|
|
|
|
|
|
|
|
let(:etag_store) { Gitlab::EtagCaching::Store.new }
|
|
|
|
let(:notes_path) { project_noteable_notes_path(project, target_type: merge_request.class.name.underscore, target_id: merge_request.id) }
|
|
|
|
let(:project) { merge_request.project }
|
2022-04-04 11:22:00 +05:30
|
|
|
let(:user) { project.first_owner }
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
let(:response_etag) { response.headers['ETag'] }
|
|
|
|
let(:stored_etag) { "W/\"#{etag_store.get(notes_path)}\"" }
|
|
|
|
|
|
|
|
before do
|
|
|
|
login_as(user)
|
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'does not set a Gitlab::EtagCaching ETag if there is a note' do
|
|
|
|
create(:note_on_merge_request, noteable: merge_request, project: merge_request.project)
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
get notes_path
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
|
|
|
|
# Rack::ETag will set an etag based on the body digest, but that doesn't
|
|
|
|
# interfere with notes pagination
|
|
|
|
expect(response_etag).not_to eq(stored_etag)
|
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
it 'sets a Gitlab::EtagCaching ETag if there is no note' do
|
|
|
|
get notes_path
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response_etag).to eq(stored_etag)
|
|
|
|
end
|
2023-04-23 21:23:45 +05:30
|
|
|
|
|
|
|
it "instruments cache hits correctly" do
|
|
|
|
etag_store.touch(notes_path)
|
|
|
|
|
|
|
|
expect(Gitlab::Metrics::RailsSlis.request_apdex).to(
|
|
|
|
receive(:increment).with(
|
|
|
|
labels: {
|
|
|
|
request_urgency: :medium,
|
|
|
|
feature_category: "team_planning",
|
|
|
|
endpoint_id: "Projects::NotesController#index"
|
|
|
|
},
|
|
|
|
success: be_in([true, false])
|
|
|
|
)
|
|
|
|
)
|
|
|
|
allow(ActiveSupport::Notifications).to receive(:instrument).and_call_original
|
|
|
|
|
|
|
|
expect(ActiveSupport::Notifications).to(
|
|
|
|
receive(:instrument).with(
|
|
|
|
'process_action.action_controller',
|
|
|
|
a_hash_including(
|
|
|
|
{
|
|
|
|
request_urgency: :medium,
|
|
|
|
target_duration_s: 0.5,
|
|
|
|
metadata: a_hash_including({
|
|
|
|
'meta.feature_category' => 'team_planning',
|
|
|
|
'meta.caller_id' => "Projects::NotesController#index"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
get notes_path, headers: { "if-none-match": stored_etag }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_modified)
|
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
end
|