Instruction:
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true

module Jira
  module Requests
    module Projects
      class ListService < Base
        extend ::Gitlab::Utils::Override

        def initialize(jira_integration, params = {})
          super(jira_integration, params)

          @query = params[:query]
        end

        private

        attr_reader :query

        override :url
        def url
          "#{base_api_url}/project"
        end

        override :build_service_response
        def build_service_response(response)
          return ServiceResponse.success(payload: empty_payload) unless response.present?

          ServiceResponse.success(payload: { projects: map_projects(response), is_last: true })
        end

        def map_projects(response)
          response
            .map { |v| JIRA::Resource::Project.build(client, v) }
            .select { |jira_project| match_query?(jira_project) }
        end

        def match_query?(jira_project)
          downcase_query = query.to_s.downcase

          jira_project&.key&.downcase&.include?(downcase_query) || jira_project&.name&.downcase&.include?(downcase_query)
        end

        def empty_payload
          { projects: [], is_last: true }
        end
      end
    end
  end
end

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Jira::Requests::Projects::ListService, feature_category: :groups_and_projects do
  include AfterNextHelpers

  let(:jira_integration) { create(:jira_integration) }
  let(:params) { {} }

  describe '#execute' do
    let(:service) { described_class.new(jira_integration, params) }

    subject { service.execute }

    context 'without jira_integration' do
      before do
        jira_integration.update!(active: false)
      end

      it 'returns an error response' do
        expect(subject.error?).to be_truthy
        expect(subject.message).to eq('Jira service not configured.')
      end
    end

    context 'when jira_integration is nil' do
      let(:jira_integration) { nil }

      it 'returns an error response' do
        expect(subject.error?).to be_truthy
        expect(subject.message).to eq('Jira service not configured.')
      end
    end

    context 'with jira_integration' do
      context 'when validations and params are ok' do
        let(:response_headers) { { 'content-type' => 'application/json' } }
        let(:response_body) { [].to_json }
        let(:expected_url_pattern) { %r{.*jira.example.com/rest/api/2/project} }

        before do
          stub_request(:get, expected_url_pattern).to_return(status: 200, body: response_body, headers: response_headers)
        end

        it_behaves_like 'a service that handles Jira API errors'

        context 'when jira runs on a subpath' do
          let(:jira_integration) { create(:jira_integration, url: 'http://jira.example.com/jira') }
          let(:expected_url_pattern) { %r{.*jira.example.com/jira/rest/api/2/project} }

          it 'takes the subpath into account' do
            expect(subject.success?).to be_truthy
          end
        end

        context 'when the request does not return any values' do
          let(:response_body) { [].to_json }

          it 'returns a paylod with no projects returned' do
            payload = subject.payload

            expect(subject.success?).to be_truthy
            expect(payload[:projects]).to be_empty
            expect(payload[:is_last]).to be_truthy
          end
        end

        context 'when the request returns values' do
          let(:response_body) { [{ 'key' => 'pr1', 'name' => 'First Project' }, { 'key' => 'pr2', 'name' => 'Second Project' }].to_json }

          it 'returns a paylod with Jira projects' do
            payload = subject.payload

            expect(subject.success?).to be_truthy
            expect(payload[:projects].map(&:key)).to eq(%w[pr1 pr2])
            expect(payload[:is_last]).to be_truthy
          end

          context 'when filtering projects by name' do
            let(:params) { { query: 'first' } }

            it 'returns a paylod with Jira procjets' do
              payload = subject.payload

              expect(subject.success?).to be_truthy
              expect(payload[:projects].map(&:key)).to eq(%w[pr1])
              expect(payload[:is_last]).to be_truthy
            end
          end
        end
      end
    end
  end
end


Instruction:
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true

module ContainerExpirationPolicies
  class CleanupService
    attr_reader :repository

    SERVICE_RESULT_FIELDS = %i[original_size before_truncate_size after_truncate_size before_delete_size deleted_size cached_tags_count].freeze

    def initialize(repository)
      @repository = repository
    end

    def execute
      return ServiceResponse.error(message: 'no repository') unless repository

      unless policy.valid?
        disable_policy!

        return ServiceResponse.error(message: 'invalid policy')
      end

      schedule_next_run_if_needed

      begin
        service_result = Projects::ContainerRepository::CleanupTagsService
                           .new(container_repository: repository, params: policy_params.merge('container_expiration_policy' => true))
                           .execute
      rescue StandardError
        repository.cleanup_unfinished!

        raise
      end

      if service_result[:status] == :success
        repository.update!(
          expiration_policy_cleanup_status: :cleanup_unscheduled,
          expiration_policy_completed_at: Time.zone.now,
          last_cleanup_deleted_tags_count: service_result[:deleted_size]
        )

        success(:finished, service_result)
      else
        repository.cleanup_unfinished!

        success(:unfinished, service_result)
      end
    end

    private

    def schedule_next_run_if_needed
      return if policy.next_run_at.future?

      repos_before_next_run = ::ContainerRepository.for_project_id(policy.project_id)
                                                   .expiration_policy_started_at_nil_or_before(policy.next_run_at)
      return if repos_before_next_run.exists?

      policy.schedule_next_run!
    end

    def disable_policy!
      policy.disable!
      repository.cleanup_unscheduled!

      Gitlab::ErrorTracking.log_exception(
        ::ContainerExpirationPolicyWorker::InvalidPolicyError.new,
        container_expiration_policy_id: policy.id
      )
    end

    def success(cleanup_status, service_result)
      payload = {
        cleanup_status: cleanup_status,
        container_repository_id: repository.id
      }

      SERVICE_RESULT_FIELDS.each do |field|
        payload["cleanup_tags_service_#{field}".to_sym] = service_result[field]
      end

      ServiceResponse.success(message: "cleanup #{cleanup_status}", payload: payload)
    end

    def policy_params
      return {} unless policy

      policy.policy_params
    end

    def policy
      project.container_expiration_policy
    end

    def project
      repository&.project
    end
  end
end

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ContainerExpirationPolicies::CleanupService, feature_category: :container_registry do
  let_it_be(:repository, reload: true) { create(:container_repository, expiration_policy_started_at: 30.minutes.ago) }
  let_it_be(:project) { repository.project }

  let(:service) { described_class.new(repository) }

  describe '#execute' do
    let(:policy) { repository.project.container_expiration_policy }

    subject { service.execute }

    before do
      policy.update!(enabled: true)
      policy.update_column(:next_run_at, 5.minutes.ago)
    end

    context 'with a successful cleanup tags service execution' do
      let(:cleanup_tags_service_params) { project.container_expiration_policy.policy_params.merge('container_expiration_policy' => true) }
      let(:cleanup_tags_service) { instance_double(Projects::ContainerRepository::CleanupTagsService) }

      it 'completely clean up the repository' do
        expect(Projects::ContainerRepository::CleanupTagsService)
          .to receive(:new).with(container_repository: repository, params: cleanup_tags_service_params).and_return(cleanup_tags_service)
        expect(cleanup_tags_service).to receive(:execute).and_return(status: :success, deleted_size: 1)

        response = subject

        aggregate_failures "checking the response and container repositories" do
          expect(response.success?).to eq(true)
          expect(response.payload).to include(cleanup_status: :finished, container_repository_id: repository.id)
          expect(ContainerRepository.waiting_for_cleanup.count).to eq(0)
          expect(repository.reload.cleanup_unscheduled?).to be_truthy
          expect(repository.expiration_policy_completed_at).not_to eq(nil)
          expect(repository.expiration_policy_started_at).not_to eq(nil)
          expect(repository.last_cleanup_deleted_tags_count).to eq(1)
        end
      end
    end

    context 'without a successful cleanup tags service execution' do
      let(:cleanup_tags_service_response) { { status: :error, message: 'timeout' } }

      before do
        expect(Projects::ContainerRepository::CleanupTagsService)
          .to receive(:new).and_return(double(execute: cleanup_tags_service_response))
      end

      it 'partially clean up the repository' do
        response = subject

        aggregate_failures "checking the response and container repositories" do
          expect(response.success?).to eq(true)
          expect(response.payload).to include(cleanup_status: :unfinished, container_repository_id: repository.id)
          expect(ContainerRepository.waiting_for_cleanup.count).to eq(1)
          expect(repository.reload.cleanup_unfinished?).to be_truthy
          expect(repository.expiration_policy_started_at).not_to eq(nil)
          expect(repository.expiration_policy_completed_at).to eq(nil)
          expect(repository.last_cleanup_deleted_tags_count).to eq(nil)
        end
      end

      context 'with a truncated cleanup tags service response' do
        let(:cleanup_tags_service_response) do
          {
            status: :error,
            original_size: 1000,
            before_truncate_size: 800,
            after_truncate_size: 200,
            before_delete_size: 100,
            cached_tags_count: 0,
            deleted_size: 100
          }
        end

        it 'partially clean up the repository' do
          response = subject

          aggregate_failures "checking the response and container repositories" do
            expect(response.success?).to eq(true)
            expect(response.payload)
              .to include(
                cleanup_status: :unfinished,
                container_repository_id: repository.id,
                cleanup_tags_service_original_size: 1000,
                cleanup_tags_service_before_truncate_size: 800,
                cleanup_tags_service_after_truncate_size: 200,
                cleanup_tags_service_before_delete_size: 100,
                cleanup_tags_service_cached_tags_count: 0,
                cleanup_tags_service_deleted_size: 100
              )
            expect(ContainerRepository.waiting_for_cleanup.count).to eq(1)
            expect(repository.reload.cleanup_unfinished?).to be_truthy
            expect(repository.expiration_policy_started_at).not_to eq(nil)
            expect(repository.expiration_policy_completed_at).to eq(nil)
            expect(repository.last_cleanup_deleted_tags_count).to eq(nil)
          end
        end
      end
    end

    context 'with no repository' do
      let(:service) { described_class.new(nil) }

      it 'returns an error response' do
        expect(subject.success?).to eq(false)
        expect(subject.message).to eq('no repository')
      end
    end

    context 'with an invalid policy' do
      let(:policy) { repository.project.container_expiration_policy }

      before do
        policy.name_regex = nil
        policy.enabled = true
        repository.expiration_policy_cleanup_status = :cleanup_ongoing
      end

      it 'returns an error response' do
        expect { subject }.to change { repository.expiration_policy_cleanup_status }.from('cleanup_ongoing').to('cleanup_unscheduled')
        expect(subject.success?).to eq(false)
        expect(subject.message).to eq('invalid policy')
        expect(policy).not_to be_enabled
      end
    end

    context 'with a network error' do
      before do
        expect(Projects::ContainerRepository::CleanupTagsService)
          .to receive(:new).and_raise(Faraday::TimeoutError)
      end

      it 'raises an error' do
        expect { subject }.to raise_error(Faraday::TimeoutError)

        expect(ContainerRepository.waiting_for_cleanup.count).to eq(1)
        expect(repository.reload.cleanup_unfinished?).to be_truthy
        expect(repository.expiration_policy_started_at).not_to eq(nil)
        expect(repository.expiration_policy_completed_at).to eq(nil)
        expect(repository.last_cleanup_deleted_tags_count).to eq(nil)
      end
    end

    context 'next run scheduling' do
      let_it_be_with_reload(:repository2) { create(:container_repository, project: project) }
      let_it_be_with_reload(:repository3) { create(:container_repository, project: project) }

      before do
        cleanup_tags_service = instance_double(Projects::ContainerRepository::CleanupTagsService)
        allow(Projects::ContainerRepository::CleanupTagsService)
          .to receive(:new).and_return(cleanup_tags_service)
        allow(cleanup_tags_service).to receive(:execute).and_return(status: :success)
      end

      shared_examples 'not scheduling the next run' do
        it 'does not scheduled the next run' do
          expect(policy).not_to receive(:schedule_next_run!)

          expect { subject }.not_to change { policy.reload.next_run_at }
        end
      end

      shared_examples 'scheduling the next run' do
        it 'schedules the next run' do
          expect(policy).to receive(:schedule_next_run!).and_call_original

          expect { subject }.to change { policy.reload.next_run_at }
        end
      end

      context 'with cleanups started_at before policy next_run_at' do
        before do
          ContainerRepository.update_all(expiration_policy_started_at: 10.minutes.ago)
        end

        it_behaves_like 'not scheduling the next run'
      end

      context 'with cleanups started_at around policy next_run_at' do
        before do
          repository3.update!(expiration_policy_started_at: policy.next_run_at + 10.minutes.ago)
        end

        it_behaves_like 'not scheduling the next run'
      end

      context 'with only the current repository started_at before the policy next_run_at' do
        before do
          repository.update!(expiration_policy_started_at: policy.next_run_at + 9.minutes)
          repository2.update!(expiration_policy_started_at: policy.next_run_at + 10.minutes)
          repository3.update!(expiration_policy_started_at: policy.next_run_at + 12.minutes)
        end

        it_behaves_like 'scheduling the next run'
      end

      context 'with cleanups started_at after policy next_run_at' do
        before do
          ContainerRepository.update_all(expiration_policy_started_at: policy.next_run_at + 10.minutes)
        end

        it_behaves_like 'scheduling the next run'
      end

      context 'with a future policy next_run_at' do
        before do
          policy.update_column(:next_run_at, 5.minutes.from_now)
        end

        it_behaves_like 'not scheduling the next run'
      end
    end
  end
end


Instruction:
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true

module ContainerExpirationPolicies
  class UpdateService < BaseContainerService
    include Gitlab::Utils::StrongMemoize

    ALLOWED_ATTRIBUTES = %i[enabled cadence older_than keep_n name_regex name_regex_keep].freeze

    def execute
      return ServiceResponse.error(message: 'Access Denied', http_status: 403) unless allowed?

      if container_expiration_policy.update(container_expiration_policy_params)
        ServiceResponse.success(payload: { container_expiration_policy: container_expiration_policy })
      else
        ServiceResponse.error(
          message: container_expiration_policy.errors.full_messages.to_sentence || 'Bad request',
          http_status: 400
        )
      end
    end

    private

    def container_expiration_policy
      strong_memoize(:container_expiration_policy) do
        @container.container_expiration_policy || @container.build_container_expiration_policy
      end
    end

    def allowed?
      Ability.allowed?(current_user, :admin_container_image, @container)
    end

    def container_expiration_policy_params
      @params.slice(*ALLOWED_ATTRIBUTES)
    end
  end
end

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ContainerExpirationPolicies::UpdateService, feature_category: :container_registry do
  using RSpec::Parameterized::TableSyntax

  let_it_be(:project, reload: true) { create(:project) }
  let_it_be(:user) { create(:user) }
  let_it_be(:params) { { cadence: '3month', keep_n: 100, older_than: '14d', extra_key: 'will_not_be_processed' } }

  let(:container_expiration_policy) { project.container_expiration_policy }

  describe '#execute' do
    subject { described_class.new(container: project, current_user: user, params: params).execute }

    RSpec.shared_examples 'returning a success' do
      it 'returns a success' do
        result = subject

        expect(result.payload[:container_expiration_policy]).to be_present
        expect(result.success?).to be_truthy
      end
    end

    RSpec.shared_examples 'returning an error' do |message, http_status|
      it 'returns an error' do
        result = subject

        expect(result.message).to eq(message)
        expect(result.status).to eq(:error)
        expect(result.http_status).to eq(http_status)
      end
    end

    RSpec.shared_examples 'updating the container expiration policy' do
      it_behaves_like 'updating the container expiration policy attributes', mode: :update, from: { cadence: '1d', keep_n: 10, older_than: '90d' }, to: { cadence: '3month', keep_n: 100, older_than: '14d' }

      it_behaves_like 'returning a success'

      context 'with invalid params' do
        let_it_be(:params) { { cadence: '20d' } }

        it_behaves_like 'not creating the container expiration policy'

        it "doesn't update the cadence" do
          expect { subject }
            .not_to change { container_expiration_policy.reload.cadence }
        end

        it_behaves_like 'returning an error', 'Cadence is not included in the list', 400
      end
    end

    RSpec.shared_examples 'denying access to container expiration policy' do
      context 'with existing container expiration policy' do
        it_behaves_like 'not creating the container expiration policy'

        it_behaves_like 'returning an error', 'Access Denied', 403
      end
    end

    context 'with existing container expiration policy' do
      where(:user_role, :shared_examples_name) do
        :maintainer | 'updating the container expiration policy'
        :developer  | 'denying access to container expiration policy'
        :reporter   | 'denying access to container expiration policy'
        :guest      | 'denying access to container expiration policy'
        :anonymous  | 'denying access to container expiration policy'
      end

      with_them do
        before do
          project.send("add_#{user_role}", user) unless user_role == :anonymous
        end

        it_behaves_like params[:shared_examples_name]
      end
    end

    context 'without existing container expiration policy' do
      let_it_be(:project, reload: true) { create(:project, :without_container_expiration_policy) }

      where(:user_role, :shared_examples_name) do
        :maintainer | 'creating the container expiration policy'
        :developer  | 'denying access to container expiration policy'
        :reporter   | 'denying access to container expiration policy'
        :guest      | 'denying access to container expiration policy'
        :anonymous  | 'denying access to container expiration policy'
      end

      with_them do
        before do
          project.send("add_#{user_role}", user) unless user_role == :anonymous
        end

        it_behaves_like params[:shared_examples_name]
      end
    end
  end
end


Instruction:
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true

module Notes
  class ResolveService < ::BaseService
    def execute(note)
      note.resolve!(current_user)

      ::MergeRequests::ResolvedDiscussionNotificationService.new(project: project, current_user: current_user).execute(note.noteable)
    end
  end
end

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Notes::ResolveService, feature_category: :team_planning do
  let(:merge_request) { create(:merge_request) }
  let(:note) { create(:diff_note_on_merge_request, noteable: merge_request, project: merge_request.project) }
  let(:user) { merge_request.author }

  describe '#execute' do
    it "resolves the note" do
      described_class.new(merge_request.project, user).execute(note)
      note.reload

      expect(note.resolved?).to be true
      expect(note.resolved_by).to eq(user)
    end

    it "sends notifications if all discussions are resolved" do
      expect_next_instance_of(MergeRequests::ResolvedDiscussionNotificationService) do |instance|
        expect(instance).to receive(:execute).with(merge_request)
      end

      described_class.new(merge_request.project, user).execute(note)
    end
  end
end


Instruction:
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true

# This service copies Notes from one Noteable to another.
#
# It expects the calling code to have performed the necessary authorization
# checks in order to allow the copy to happen.
module Notes
  class CopyService
    def initialize(current_user, from_noteable, to_noteable)
      raise ArgumentError, 'Noteables must be different' if from_noteable == to_noteable

      @current_user = current_user
      @from_noteable = from_noteable
      @to_noteable = to_noteable
      @from_project = from_noteable.project
      @new_discussion_ids = {}
    end

    def execute
      from_noteable.notes_with_associations.find_each do |note|
        copy_note(note)
      end

      ServiceResponse.success
    end

    private

    attr_reader :from_noteable, :to_noteable, :from_project, :current_user, :new_discussion_ids

    def copy_note(note)
      new_note = note.dup
      new_params = params_from_note(note, new_note)
      new_note.update!(new_params)

      copy_award_emoji(note, new_note)
    end

    def params_from_note(note, new_note)
      new_discussion_ids[note.discussion_id] ||= Discussion.discussion_id(new_note)

      new_params = sanitized_note_params(note)

      new_params.merge!(
        project: to_noteable.project,
        noteable: to_noteable,
        discussion_id: new_discussion_ids[note.discussion_id],
        created_at: note.created_at,
        updated_at: note.updated_at
      )

      if note.system_note_metadata
        new_params[:system_note_metadata] = note.system_note_metadata.dup

        # TODO: Implement copying of description versions when an issue is moved
        # https://gitlab.com/gitlab-org/gitlab/issues/32300
        new_params[:system_note_metadata].description_version = nil
      end

      new_params
    end

    # Skip copying cached markdown HTML if text
    # does not contain references or uploads.
    def sanitized_note_params(note)
      MarkdownContentRewriterService
        .new(current_user, note, :note, from_project, to_noteable.resource_parent)
        .execute
    end

    def copy_award_emoji(from_note, to_note)
      AwardEmojis::CopyService.new(from_note, to_note).execute
    end
  end
end

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Notes::CopyService, feature_category: :team_planning do
  describe '#initialize' do
    let_it_be(:noteable) { create(:issue) }

    it 'validates that we cannot copy notes to the same Noteable' do
      expect { described_class.new(nil, noteable, noteable) }.to raise_error(ArgumentError)
    end
  end

  describe '#execute' do
    let_it_be(:user) { create(:user) }
    let_it_be(:group) { create(:group) }
    let_it_be(:from_project) { create(:project, :public, group: group) }
    let_it_be(:to_project) { create(:project, :public, group: group) }
    let_it_be(:from_noteable) { create(:issue, project: from_project) }
    let_it_be(:to_noteable) { create(:issue, project: to_project) }

    subject(:execute_service) { described_class.new(user, from_noteable, to_noteable).execute }

    context 'rewriting the note body' do
      context 'simple notes' do
        let!(:notes) do
          [
            create(
              :note, noteable: from_noteable, project: from_noteable.project,
              created_at: 2.weeks.ago, updated_at: 1.week.ago
            ),
            create(:note, noteable: from_noteable, project: from_noteable.project),
            create(:note, system: true, noteable: from_noteable, project: from_noteable.project)
          ]
        end

        it 'rewrites existing notes in valid order' do
          execute_service

          expect(to_noteable.notes.order('id ASC').pluck(:note).first(3)).to eq(notes.map(&:note))
        end

        it 'copies all the issue notes' do
          execute_service

          expect(to_noteable.notes.count).to eq(3)
        end

        it 'does not change the note attributes' do
          execute_service

          new_note = to_noteable.notes.first

          expect(new_note).to have_attributes(
            note: notes.first.note,
            author: notes.first.author
          )
        end

        it 'copies the award emojis' do
          create(:award_emoji, awardable: notes.first, name: 'thumbsup')

          execute_service

          new_award_emoji = to_noteable.notes.first.award_emoji.first

          expect(new_award_emoji.name).to eq('thumbsup')
        end

        it 'copies system_note_metadata for system note' do
          system_note_metadata = create(:system_note_metadata, note: notes.last)

          execute_service

          new_note = to_noteable.notes.last

          aggregate_failures do
            expect(new_note.system_note_metadata.action).to eq(system_note_metadata.action)
            expect(new_note.system_note_metadata.id).not_to eq(system_note_metadata.id)
          end
        end

        it 'returns success' do
          aggregate_failures do
            expect(execute_service).to be_kind_of(ServiceResponse)
            expect(execute_service).to be_success
          end
        end

        it 'copies rendered markdown from note_html' do
          expect(Banzai::Renderer).not_to receive(:cacheless_render_field)

          execute_service

          new_note = to_noteable.notes.first
          expect(new_note.note_html).to eq(notes.first.note_html)
        end
      end

      context 'notes with mentions' do
        let!(:note_with_mention) { create(:note, noteable: from_noteable, author: from_noteable.author, project: from_noteable.project, note: "note with mention #{user.to_reference}") }
        let!(:note_with_no_mention) { create(:note, noteable: from_noteable, author: from_noteable.author, project: from_noteable.project, note: "note without mention") }

        it 'saves user mentions with actual mentions for new issue' do
          execute_service

          aggregate_failures do
            expect(to_noteable.user_mentions.first.mentioned_users_ids).to match_array([user.id])
            expect(to_noteable.user_mentions.count).to eq(1)
          end
        end
      end

      context 'notes with reference' do
        let(:other_issue) { create(:issue, project: from_noteable.project) }
        let(:merge_request) { create(:merge_request) }
        let(:text) { "See ##{other_issue.iid} and #{merge_request.project.full_path}!#{merge_request.iid}" }
        let!(:note) { create(:note, noteable: from_noteable, note: text, project: from_noteable.project) }

        it 'rewrites the references correctly' do
          execute_service

          new_note = to_noteable.notes.first

          expected_text = "See #{other_issue.project.path}##{other_issue.iid} and #{merge_request.project.full_path}!#{merge_request.iid}"

          aggregate_failures do
            expect(new_note.note).to eq(expected_text)
            expect(new_note.author).to eq(note.author)
          end
        end

        it 'does not copy rendered markdown from note_html' do
          execute_service

          new_note = to_noteable.notes.first
          expect(new_note.note_html).not_to eq(note.note_html)
        end
      end

      context 'notes with upload' do
        let(:uploader) { build(:file_uploader, project: from_noteable.project) }
        let(:text) { "Simple text with image: #{uploader.markdown_link} " }
        let!(:note) { create(:note, noteable: from_noteable, note: text, project: from_noteable.project) }

        it 'rewrites note content correctly' do
          execute_service
          new_note = to_noteable.notes.first

          aggregate_failures do
            expect(note.note).to match(/Simple text with image:/o)
            expect(FileUploader::MARKDOWN_PATTERN.match(note.note)).not_to be_nil
            expect(new_note.note).to match(/Simple text with image:/o)
            expect(FileUploader::MARKDOWN_PATTERN.match(new_note.note)).not_to be_nil
            expect(note.note).not_to eq(new_note.note)
            expect(note.note_html).not_to eq(new_note.note_html)
          end
        end

        it 'does not copy rendered markdown from note_html' do
          execute_service

          new_note = to_noteable.notes.first
          expect(new_note.note_html).not_to eq(note.note_html)
        end
      end

      context 'discussion notes' do
        let(:note) { create(:note, noteable: from_noteable, note: 'sample note', project: from_noteable.project) }
        let!(:discussion) { create(:discussion_note_on_issue, in_reply_to: note, note: 'reply to sample note') }

        it 'rewrites discussion correctly' do
          execute_service

          aggregate_failures do
            expect(to_noteable.notes.count).to eq(from_noteable.notes.count)
            expect(to_noteable.notes.where(discussion_id: discussion.discussion_id).count).to eq(0)
            expect(from_noteable.notes.where(discussion_id: discussion.discussion_id).count).to eq(1)
          end
        end
      end
    end
  end
end


Instruction:
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true

module Notes
  class PostProcessService
    attr_accessor :note

    def initialize(note)
      @note = note
    end

    def execute
      # Skip system notes, like status changes and cross-references and awards
      unless note.system?
        EventCreateService.new.leave_note(note, note.author)

        return if note.for_personal_snippet?

        note.create_cross_references!
        ::SystemNoteService.design_discussion_added(note) if create_design_discussion_system_note?

        execute_note_hooks
      end
    end

    private

    def create_design_discussion_system_note?
      note && note.for_design? && note.start_of_discussion?
    end

    def hook_data
      Gitlab::DataBuilder::Note.build(note, note.author)
    end

    def execute_note_hooks
      return unless note.project

      note_data = hook_data
      is_confidential = note.confidential?(include_noteable: true)
      hooks_scope = is_confidential ? :confidential_note_hooks : :note_hooks

      note.project.execute_hooks(note_data, hooks_scope)
      note.project.execute_integrations(note_data, hooks_scope)

      execute_group_mention_hooks(note, note_data, is_confidential)
    end

    def execute_group_mention_hooks(note, note_data, is_confidential)
      Integrations::GroupMentionService.new(note, hook_data: note_data, is_confidential: is_confidential).execute
    end
  end
end

Notes::PostProcessService.prepend_mod_with('Notes::PostProcessService')

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Notes::PostProcessService, feature_category: :team_planning do
  let(:project) { create(:project) }
  let(:issue) { create(:issue, project: project) }
  let(:user) { create(:user) }

  describe '#execute' do
    before do
      project.add_maintainer(user)
      note_opts = {
        note: 'Awesome comment',
        noteable_type: 'Issue',
        noteable_id: issue.id
      }

      @note = Notes::CreateService.new(project, user, note_opts).execute
    end

    it do
      expect(project).to receive(:execute_hooks)
      expect(project).to receive(:execute_integrations)
      expect_next_instance_of(Integrations::GroupMentionService) do |group_mention_service|
        expect(group_mention_service).to receive(:execute)
      end

      described_class.new(@note).execute
    end

    context 'with a confidential issue' do
      let(:issue) { create(:issue, :confidential, project: project) }

      it "doesn't call note hooks/integrations" do
        expect(project).not_to receive(:execute_hooks).with(anything, :note_hooks)
        expect(project).not_to receive(:execute_integrations).with(anything, :note_hooks)

        described_class.new(@note).execute
      end

      it "calls confidential-note hooks/integrations" do
        expect(project).to receive(:execute_hooks).with(anything, :confidential_note_hooks)
        expect(project).to receive(:execute_integrations).with(anything, :confidential_note_hooks)

        described_class.new(@note).execute
      end
    end

    context 'when the noteable is a design' do
      let_it_be(:noteable) { create(:design, :with_file) }
      let_it_be(:discussion_note) { create_note }

      subject { described_class.new(note).execute }

      def create_note(in_reply_to: nil)
        create(:diff_note_on_design, noteable: noteable, in_reply_to: in_reply_to)
      end

      context 'when the note is the start of a new discussion' do
        let(:note) { discussion_note }

        it 'creates a new system note' do
          expect { subject }.to change { Note.system.count }.by(1)
        end
      end

      context 'when the note is a reply within a discussion' do
        let_it_be(:note) { create_note(in_reply_to: discussion_note) }

        it 'does not create a new system note' do
          expect { subject }.not_to change { Note.system.count }
        end
      end
    end
  end
end


Instruction:
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true

# QuickActionsService class
#
# Executes quick actions commands extracted from note text
#
# Most commands returns parameters to be applied later
# using QuickActionService#apply_updates
#
module Notes
  class QuickActionsService < BaseService
    attr_reader :interpret_service

    delegate :commands_executed_count, to: :interpret_service, allow_nil: true

    SUPPORTED_NOTEABLES = %w[WorkItem Issue MergeRequest Commit].freeze

    private_constant :SUPPORTED_NOTEABLES

    def self.supported_noteables
      SUPPORTED_NOTEABLES
    end

    def self.supported?(note)
      return true if note.for_work_item?

      supported_noteables.include? note.noteable_type
    end

    def supported?(note)
      self.class.supported?(note)
    end

    def execute(note, options = {})
      return [note.note, {}] unless supported?(note)

      @interpret_service = QuickActions::InterpretService.new(project, current_user, options)

      interpret_service.execute(note.note, note.noteable)
    end

    # Applies updates extracted to note#noteable
    # The update parameters are extracted on self#execute
    def apply_updates(update_params, note)
      return if update_params.empty?
      return unless supported?(note)

      # We need the `id` after the note is persisted
      if update_params[:spend_time]
        update_params[:spend_time][:note_id] = note.id
      end

      execute_update_service(note, update_params)
    end

    private

    def execute_update_service(note, params)
      service_response = noteable_update_service(note, params).execute(note.noteable)

      service_errors = if service_response.respond_to?(:errors)
                         service_response.errors.full_messages
                       elsif service_response.respond_to?(:[]) && service_response[:status] == :error
                         Array.wrap(service_response[:message])
                       end

      service_errors.blank? ? ServiceResponse.success : ServiceResponse.error(message: service_errors)
    end

    def noteable_update_service(note, update_params)
      if note.for_work_item?
        parsed_params = note.noteable.transform_quick_action_params(update_params)

        WorkItems::UpdateService.new(
          container: note.resource_parent,
          current_user: current_user,
          params: parsed_params[:common],
          widget_params: parsed_params[:widgets]
        )
      elsif note.for_issue?
        Issues::UpdateService.new(container: note.resource_parent, current_user: current_user, params: update_params)
      elsif note.for_merge_request?
        MergeRequests::UpdateService.new(
          project: note.resource_parent, current_user: current_user, params: update_params
        )
      elsif note.for_commit?
        Commits::TagService.new(note.resource_parent, current_user, update_params)
      end
    end
  end
end

Notes::QuickActionsService.prepend_mod_with('Notes::QuickActionsService')

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Notes::QuickActionsService, feature_category: :team_planning do
  shared_context 'note on noteable' do
    let_it_be(:project) { create(:project, :repository) }
    let_it_be(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } }
    let_it_be(:assignee) { create(:user) }

    before do
      project.add_maintainer(assignee)
    end
  end

  shared_examples 'note on noteable that supports quick actions' do
    include_context 'note on noteable'

    before do
      note.note = note_text
    end

    let!(:milestone) { create(:milestone, project: project) }
    let!(:labels) { create_pair(:label, project: project) }

    describe 'note with only command' do
      describe '/close, /label, /assign & /milestone' do
        let(:note_text) do
          %(/close\n/label ~#{labels.first.name} ~#{labels.last.name}\n/assign @#{assignee.username}\n/milestone %"#{milestone.name}")
        end

        it 'closes noteable, sets labels, assigns, and sets milestone to noteable, and leave no note' do
          content = execute(note)

          expect(content).to be_empty
          expect(note.noteable).to be_closed
          expect(note.noteable.labels).to match_array(labels)
          expect(note.noteable.assignees).to eq([assignee])
          expect(note.noteable.milestone).to eq(milestone)
        end
      end

      context '/relate' do
        let_it_be(:issue) { create(:issue, project: project) }
        let_it_be(:other_issue) { create(:issue, project: project) }

        let(:note_text) { "/relate #{other_issue.to_reference}" }
        let(:note) { create(:note_on_issue, noteable: issue, project: project, note: note_text) }

        context 'user cannot relate issues', :sidekiq_inline do
          before do
            project.team.find_member(maintainer.id).destroy!
            project.update!(visibility: Gitlab::VisibilityLevel::PUBLIC)
          end

          it 'does not create issue relation' do
            expect { execute(note) }.not_to change { IssueLink.count }
          end
        end

        context 'user is allowed to relate issues' do
          it 'creates issue relation' do
            expect { execute(note) }.to change { IssueLink.count }.by(1)
          end
        end
      end

      describe '/reopen' do
        before do
          note.noteable.close!
          expect(note.noteable).to be_closed
        end
        let(:note_text) { '/reopen' }

        it 'opens the noteable, and leave no note' do
          content = execute(note)

          expect(content).to be_empty
          expect(note.noteable).to be_open
        end
      end

      describe '/spend' do
        context 'when note is not persisted' do
          let(:note_text) { '/spend 1h' }

          it 'adds time to noteable, adds timelog with nil note_id and has no content' do
            content = execute(note)

            expect(content).to be_empty
            expect(note.noteable.time_spent).to eq(3600)
            expect(Timelog.last.note_id).to be_nil
          end
        end

        context 'when note is persisted' do
          let(:note_text) { "a note \n/spend 1h" }

          it 'updates the spent time and populates timelog with note_id' do
            new_content, update_params = service.execute(note)
            note.update!(note: new_content)
            service.apply_updates(update_params, note)

            expect(Timelog.last.note_id).to eq(note.id)
          end
        end

        context 'adds a system note' do
          context 'when not specifying a date' do
            let(:note_text) { "/spend 1h" }

            it 'does not include the date' do
              _, update_params = service.execute(note)
              service.apply_updates(update_params, note)

              expect(Note.last.note).to eq('added 1h of time spent')
            end
          end

          context 'when specifying a date' do
            let(:note_text) { "/spend 1h 2020-01-01" }

            it 'does include the date' do
              _, update_params = service.execute(note)
              service.apply_updates(update_params, note)

              expect(Note.last.note).to eq('added 1h of time spent at 2020-01-01')
            end
          end
        end
      end
    end

    describe '/estimate' do
      before do
        # reset to 10 minutes before each test
        note.noteable.update!(time_estimate: 600)
      end

      shared_examples 'does not update time_estimate and displays the correct error message' do
        it 'shows validation error message' do
          content = execute(note)

          expect(content).to be_empty
          expect(note.noteable.errors[:time_estimate]).to include('must have a valid format and be greater than or equal to zero.')
          expect(note.noteable.reload.time_estimate).to eq(600)
        end
      end

      context 'when the time estimate is valid' do
        let(:note_text) { '/estimate 1h' }

        it 'adds time estimate to noteable' do
          content = execute(note)

          expect(content).to be_empty
          expect(note.noteable.reload.time_estimate).to eq(3600)
        end
      end

      context 'when the time estimate is 0' do
        let(:note_text) { '/estimate 0' }

        it 'adds time estimate to noteable' do
          content = execute(note)

          expect(content).to be_empty
          expect(note.noteable.reload.time_estimate).to eq(0)
        end
      end

      context 'when the time estimate is invalid' do
        let(:note_text) { '/estimate a' }

        include_examples "does not update time_estimate and displays the correct error message"
      end

      context 'when the time estimate is partially invalid' do
        let(:note_text) { '/estimate 1d 3id' }

        include_examples "does not update time_estimate and displays the correct error message"
      end

      context 'when the time estimate is negative' do
        let(:note_text) { '/estimate -1h' }

        include_examples "does not update time_estimate and displays the correct error message"
      end
    end

    describe '/confidential' do
      let_it_be_with_reload(:noteable) { create(:work_item, :issue, project: project) }
      let_it_be(:note_text) { '/confidential' }
      let_it_be(:note) { create(:note, noteable: noteable, project: project, note: note_text) }

      context 'when work item does not have children' do
        it 'leaves the note empty' do
          expect(execute(note)).to be_empty
        end

        it 'marks work item as confidential' do
          expect { execute(note) }.to change { noteable.reload.confidential }.from(false).to(true)
        end
      end

      context 'when work item has children' do
        before do
          create(:parent_link, work_item: task, work_item_parent: noteable)
        end

        context 'when children are not confidential' do
          let(:task) { create(:work_item, :task, project: project) }

          it 'does not mark parent work item as confidential' do
            expect { execute(note) }.to not_change { noteable.reload.confidential }.from(false)
            expect(noteable.errors[:base]).to include('A confidential work item cannot have a parent that already has non-confidential children.')
          end
        end

        context 'when children are confidential' do
          let(:task) { create(:work_item, :confidential, :task, project: project) }

          it 'marks parent work item as confidential' do
            expect { execute(note) }.to change { noteable.reload.confidential }.from(false).to(true)
          end
        end
      end
    end

    describe 'note with command & text' do
      describe '/close, /label, /assign & /milestone' do
        let(:note_text) do
          %(HELLO\n/close\n/label ~#{labels.first.name} ~#{labels.last.name}\n/assign @#{assignee.username}\n/milestone %"#{milestone.name}"\nWORLD)
        end

        it 'closes noteable, sets labels, assigns, and sets milestone to noteable' do
          content = execute(note)

          expect(content).to eq "HELLO\nWORLD"
          expect(note.noteable).to be_closed
          expect(note.noteable.labels).to match_array(labels)
          expect(note.noteable.assignees).to eq([assignee])
          expect(note.noteable.milestone).to eq(milestone)
        end
      end

      describe '/reopen' do
        before do
          note.noteable.close
          expect(note.noteable).to be_closed
        end
        let(:note_text) { "HELLO\n/reopen\nWORLD" }

        it 'opens the noteable' do
          content = execute(note)

          expect(content).to eq "HELLO\nWORLD"
          expect(note.noteable).to be_open
        end
      end
    end

    describe '/milestone' do
      let(:issue) { create(:issue, project: project) }
      let(:note_text) { %(/milestone %"#{milestone.name}") }
      let(:note) { create(:note_on_issue, noteable: issue, project: project, note: note_text) }

      context 'on an incident' do
        before do
          issue.update!(work_item_type: WorkItems::Type.default_by_type(:incident))
        end

        it 'leaves the note empty' do
          expect(execute(note)).to be_empty
        end

        it 'assigns the milestone' do
          expect { execute(note) }.to change { issue.reload.milestone }.from(nil).to(milestone)
        end
      end

      context 'on a merge request' do
        let(:note_mr) { create(:note_on_merge_request, project: project, note: note_text) }

        it 'leaves the note empty' do
          expect(execute(note_mr)).to be_empty
        end

        it 'assigns the milestone' do
          expect { execute(note) }.to change { issue.reload.milestone }.from(nil).to(milestone)
        end
      end
    end

    describe '/remove_milestone' do
      let(:issue) { create(:issue, project: project, milestone: milestone) }
      let(:note_text) { '/remove_milestone' }
      let(:note) { create(:note_on_issue, noteable: issue, project: project, note: note_text) }

      context 'on an issue' do
        it 'leaves the note empty' do
          expect(execute(note)).to be_empty
        end

        it 'removes the milestone' do
          expect { execute(note) }.to change { issue.reload.milestone }.from(milestone).to(nil)
        end
      end

      context 'on an incident' do
        before do
          issue.update!(work_item_type: WorkItems::Type.default_by_type(:incident))
        end

        it 'leaves the note empty' do
          expect(execute(note)).to be_empty
        end

        it 'removes the milestone' do
          expect { execute(note) }.to change { issue.reload.milestone }.from(milestone).to(nil)
        end
      end

      context 'on a merge request' do
        let(:note_mr) { create(:note_on_merge_request, project: project, note: note_text) }

        it 'leaves the note empty' do
          expect(execute(note_mr)).to be_empty
        end

        it 'removes the milestone' do
          expect { execute(note) }.to change { issue.reload.milestone }.from(milestone).to(nil)
        end
      end
    end

    describe '/add_child' do
      let_it_be_with_reload(:noteable) { create(:work_item, :objective, project: project) }
      let_it_be_with_reload(:child) { create(:work_item, :objective, project: project) }
      let_it_be_with_reload(:second_child) { create(:work_item, :objective, project: project) }
      let_it_be(:note_text) { "/add_child #{child.to_reference}, #{second_child.to_reference}" }
      let_it_be(:note) { create(:note, noteable: noteable, project: project, note: note_text) }
      let_it_be(:children) { [child, second_child] }

      shared_examples 'adds child work items' do
        it 'leaves the note empty' do
          expect(execute(note)).to be_empty
        end

        it 'adds child work items' do
          execute(note)

          expect(noteable.valid?).to be_truthy
          expect(noteable.work_item_children).to eq(children)
        end
      end

      context 'when using work item reference' do
        let_it_be(:note_text) { "/add_child #{child.to_reference(full: true)},#{second_child.to_reference(full: true)}" }

        it_behaves_like 'adds child work items'
      end

      context 'when using work item iid' do
        it_behaves_like 'adds child work items'
      end

      context 'when using work item URL' do
        let_it_be(:project_path) { "#{Gitlab.config.gitlab.url}/#{project.full_path}" }
        let_it_be(:url) { "#{project_path}/work_items/#{child.iid},#{project_path}/work_items/#{second_child.iid}" }
        let_it_be(:note_text) { "/add_child #{url}" }

        it_behaves_like 'adds child work items'
      end
    end

    describe '/set_parent' do
      let_it_be_with_reload(:noteable) { create(:work_item, :objective, project: project) }
      let_it_be_with_reload(:parent) { create(:work_item, :objective, project: project) }
      let_it_be(:note_text) { "/set_parent #{parent.to_reference}" }
      let_it_be(:note) { create(:note, noteable: noteable, project: project, note: note_text) }

      shared_examples 'sets work item parent' do
        it 'leaves the note empty' do
          expect(execute(note)).to be_empty
        end

        it 'sets work item parent' do
          execute(note)

          expect(parent.valid?).to be_truthy
          expect(noteable.work_item_parent).to eq(parent)
        end
      end

      context 'when using work item reference' do
        let_it_be(:note_text) { "/set_parent #{project.full_path}#{parent.to_reference}" }

        it_behaves_like 'sets work item parent'
      end

      context 'when using work item iid' do
        let_it_be(:note_text) { "/set_parent #{parent.to_reference}" }

        it_behaves_like 'sets work item parent'
      end

      context 'when using work item URL' do
        let_it_be(:url) { "#{Gitlab.config.gitlab.url}/#{project.full_path}/work_items/#{parent.iid}" }
        let_it_be(:note_text) { "/set_parent #{url}" }

        it_behaves_like 'sets work item parent'
      end
    end

    describe '/promote_to' do
      shared_examples 'promotes work item' do |from:, to:|
        it 'leaves the note empty' do
          expect(execute(note)).to be_empty
        end

        it 'promotes to provided type' do
          expect { execute(note) }.to change { noteable.work_item_type.base_type }.from(from).to(to)
        end
      end

      context 'on a task' do
        let_it_be_with_reload(:noteable) { create(:work_item, :task, project: project) }
        let_it_be(:note_text) { '/promote_to Issue' }
        let_it_be(:note) { create(:note, noteable: noteable, project: project, note: note_text) }

        it_behaves_like 'promotes work item', from: 'task', to: 'issue'

        context 'when type name is lower case' do
          let_it_be(:note_text) { '/promote_to issue' }

          it_behaves_like 'promotes work item', from: 'task', to: 'issue'
        end
      end

      context 'on an issue' do
        let_it_be_with_reload(:noteable) { create(:work_item, :issue, project: project) }
        let_it_be(:note_text) { '/promote_to Incident' }
        let_it_be(:note) { create(:note, noteable: noteable, project: project, note: note_text) }

        it_behaves_like 'promotes work item', from: 'issue', to: 'incident'

        context 'when type name is lower case' do
          let_it_be(:note_text) { '/promote_to incident' }

          it_behaves_like 'promotes work item', from: 'issue', to: 'incident'
        end
      end
    end
  end

  describe '.supported?' do
    include_context 'note on noteable'

    let(:note) { create(:note_on_issue, project: project) }

    context 'with a note on an issue' do
      it 'returns true' do
        expect(described_class.supported?(note)).to be_truthy
      end
    end

    context 'with a note on a commit' do
      let(:note) { create(:note_on_commit, project: project) }

      it 'returns false' do
        expect(described_class.supported?(note)).to be_truthy
      end
    end
  end

  describe '#supported?' do
    include_context 'note on noteable'

    it 'delegates to the class method' do
      service = described_class.new(project, maintainer)
      note = create(:note_on_issue, project: project)

      expect(described_class).to receive(:supported?).with(note)

      service.supported?(note)
    end
  end

  describe '#execute' do
    let(:service) { described_class.new(project, maintainer) }

    it_behaves_like 'note on noteable that supports quick actions' do
      let_it_be(:issue, reload: true) { create(:issue, project: project) }
      let(:note) { build(:note_on_issue, project: project, noteable: issue) }
    end

    it_behaves_like 'note on noteable that supports quick actions' do
      let_it_be(:incident, reload: true) { create(:incident, project: project) }
      let(:note) { build(:note_on_issue, project: project, noteable: incident) }
    end

    it_behaves_like 'note on noteable that supports quick actions' do
      let(:merge_request) { create(:merge_request, source_project: project) }
      let(:note) { build(:note_on_merge_request, project: project, noteable: merge_request) }
    end

    context 'note on work item that supports quick actions' do
      include_context 'note on noteable'

      let_it_be(:work_item, reload: true) { create(:work_item, project: project) }

      let(:note) { build(:note_on_work_item, project: project, noteable: work_item) }

      let!(:labels) { create_pair(:label, project: project) }

      before do
        note.note = note_text
      end

      describe 'note with only command' do
        describe '/close, /label & /assign' do
          let(:note_text) do
            %(/close\n/label ~#{labels.first.name} ~#{labels.last.name}\n/assign @#{assignee.username}\n)
          end

          it 'closes noteable, sets labels, assigns and leave no note' do
            content = execute(note)

            expect(content).to be_empty
            expect(note.noteable).to be_closed
            expect(note.noteable.labels).to match_array(labels)
            expect(note.noteable.assignees).to eq([assignee])
          end
        end

        describe '/reopen' do
          before do
            note.noteable.close!
            expect(note.noteable).to be_closed
          end
          let(:note_text) { '/reopen' }

          it 'opens the noteable, and leave no note' do
            content = execute(note)

            expect(content).to be_empty
            expect(note.noteable).to be_open
          end
        end
      end

      describe 'note with command & text' do
        describe '/close, /label, /assign' do
          let(:note_text) do
            %(HELLO\n/close\n/label ~#{labels.first.name} ~#{labels.last.name}\n/assign @#{assignee.username}\nWORLD)
          end

          it 'closes noteable, sets labels, assigns, and sets milestone to noteable' do
            content = execute(note)

            expect(content).to eq "HELLO\nWORLD"
            expect(note.noteable).to be_closed
            expect(note.noteable.labels).to match_array(labels)
            expect(note.noteable.assignees).to eq([assignee])
          end
        end

        describe '/reopen' do
          before do
            note.noteable.close
            expect(note.noteable).to be_closed
          end
          let(:note_text) { "HELLO\n/reopen\nWORLD" }

          it 'opens the noteable' do
            content = execute(note)

            expect(content).to eq "HELLO\nWORLD"
            expect(note.noteable).to be_open
          end
        end
      end
    end
  end

  describe '#apply_updates' do
    include_context 'note on noteable'

    let_it_be(:issue) { create(:issue, project: project) }
    let_it_be(:work_item, reload: true) { create(:work_item, :issue, project: project) }
    let_it_be(:merge_request) { create(:merge_request, source_project: project) }
    let_it_be(:issue_note) { create(:note_on_issue, project: project, noteable: issue) }
    let_it_be(:work_item_note) { create(:note, project: project, noteable: work_item) }
    let_it_be(:mr_note) { create(:note_on_merge_request, project: project, noteable: merge_request) }
    let_it_be(:commit_note) { create(:note_on_commit, project: project) }
    let(:update_params) { {} }

    subject(:apply_updates) { described_class.new(project, maintainer).apply_updates(update_params, note) }

    context 'with a note on an issue' do
      let(:note) { issue_note }

      it 'returns successful service response if update returned no errors' do
        update_params[:confidential] = true
        expect(apply_updates.success?).to be true
      end

      it 'returns service response with errors if update failed' do
        update_params[:title] = ""
        expect(apply_updates.success?).to be false
        expect(apply_updates.message).to include("Title can't be blank")
      end
    end

    context 'with a note on a merge request' do
      let(:note) { mr_note }

      it 'returns successful service response if update returned no errors' do
        update_params[:title] = 'New title'
        expect(apply_updates.success?).to be true
      end

      it 'returns service response with errors if update failed' do
        update_params[:title] = ""
        expect(apply_updates.success?).to be false
        expect(apply_updates.message).to include("Title can't be blank")
      end
    end

    context 'with a note on a work item' do
      let(:note) { work_item_note }

      before do
        update_params[:confidential] = true
      end

      it 'returns successful service response if update returned no errors' do
        expect(apply_updates.success?).to be true
      end

      it 'returns service response with errors if update failed' do
        task = create(:work_item, :task, project: project)
        create(:parent_link, work_item: task, work_item_parent: work_item)

        expect(apply_updates.success?).to be false
        expect(apply_updates.message)
          .to include("A confidential work item cannot have a parent that already has non-confidential children.")
      end
    end

    context 'with a note on a commit' do
      let(:note) { commit_note }

      it 'returns successful service response if update returned no errors' do
        update_params[:tag_name] = 'test'
        expect(apply_updates.success?).to be true
      end

      it 'returns service response with errors if update failed' do
        update_params[:tag_name] = '-test'
        expect(apply_updates.success?).to be false
        expect(apply_updates.message).to include('Tag name invalid')
      end
    end
  end

  context 'CE restriction for issue assignees' do
    describe '/assign' do
      let(:project) { create(:project) }
      let(:assignee) { create(:user) }
      let(:maintainer) { create(:user) }
      let(:service) { described_class.new(project, maintainer) }
      let(:note) { create(:note_on_issue, note: note_text, project: project) }

      let(:note_text) do
        %(/assign @#{assignee.username} @#{maintainer.username}\n")
      end

      before do
        stub_licensed_features(multiple_issue_assignees: false)
        project.add_maintainer(maintainer)
        project.add_maintainer(assignee)
      end

      it 'adds only one assignee from the list' do
        execute(note)

        expect(note.noteable.assignees.count).to eq(1)
      end
    end
  end

  def execute(note)
    content, update_params = service.execute(note)
    service.apply_updates(update_params, note)

    content
  end
end


Instruction:
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true

module Notes
  class BuildService < ::BaseService
    def execute
      in_reply_to_discussion_id = params.delete(:in_reply_to_discussion_id)
      external_author = params.delete(:external_author)

      discussion = nil

      if external_author.present?
        note_metadata = Notes::NoteMetadata.new(email_participant: external_author)
        params[:note_metadata] = note_metadata
      end

      if in_reply_to_discussion_id.present?
        discussion = find_discussion(in_reply_to_discussion_id)

        return discussion_not_found unless discussion && can?(current_user, :create_note, discussion.noteable)

        discussion = discussion.convert_to_discussion! if discussion.can_convert_to_discussion?

        params.merge!(discussion.reply_attributes)
      end

      # The `confidential` param for notes is deprecated with 15.3
      # and renamed to `internal`.
      # We still accept `confidential` until the param gets removed from the API.
      # Until we have not migrated the database column to `internal` we need to rename
      # the parameter. Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/367923.
      params[:confidential] = params[:internal] || params[:confidential]
      params.delete(:internal)

      new_note(params, discussion)
    end

    private

    def new_note(params, discussion)
      note = Note.new(params)
      note.project = project
      note.author = current_user

      parent_confidential = discussion&.confidential?
      can_set_confidential = can?(current_user, :mark_note_as_internal, note)

      return discussion_not_found if parent_confidential && !can_set_confidential

      note.confidential = (parent_confidential.nil? && can_set_confidential ? params.delete(:confidential) : parent_confidential)
      note.resolve_without_save(current_user) if discussion&.resolved?
      note
    end

    def find_discussion(discussion_id)
      if project
        project.notes.find_discussion(discussion_id)
      else
        Note.find_discussion(discussion_id)
      end
    end

    def discussion_not_found
      note = Note.new
      note.errors.add(:base, _('Discussion to reply to cannot be found'))
      note
    end
  end
end

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Notes::BuildService, feature_category: :team_planning do
  include AdminModeHelper

  let_it_be(:project) { create(:project, :repository) }
  let_it_be(:note) { create(:discussion_note_on_issue, project: project) }
  let_it_be(:author) { note.author }
  let_it_be(:user) { author }
  let_it_be(:noteable_author) { create(:user) }
  let_it_be(:other_user) { create(:user) }
  let_it_be(:external) { create(:user, :external) }

  let(:base_params) { { note: 'Test' } }
  let(:params) { {} }

  subject(:new_note) { described_class.new(project, user, base_params.merge(params)).execute }

  describe '#execute' do
    context 'when in_reply_to_discussion_id is specified' do
      let(:params) { { in_reply_to_discussion_id: note.discussion_id } }

      context 'when a note with that original discussion ID exists' do
        it 'sets the note up to be in reply to that note' do
          expect(new_note).to be_valid
          expect(new_note.in_reply_to?(note)).to be_truthy
          expect(new_note.resolved?).to be_falsey
        end

        context 'when discussion is resolved' do
          let_it_be(:merge_request) { create(:merge_request, source_project: project) }
          let_it_be(:mr_note) { create(:discussion_note_on_merge_request, :resolved, noteable: merge_request, project: project, author: author) }

          let(:params) { { in_reply_to_discussion_id: mr_note.discussion_id } }

          it 'resolves the note' do
            expect(new_note).to be_valid
            expect(new_note.resolved?).to be_truthy
          end
        end
      end

      context 'when a note with that discussion ID exists' do
        it 'sets the note up to be in reply to that note' do
          expect(new_note).to be_valid
          expect(new_note.in_reply_to?(note)).to be_truthy
        end
      end

      context 'when no note with that discussion ID exists' do
        let(:params) { { in_reply_to_discussion_id: 'foo' } }

        it 'sets an error' do
          expect(new_note.errors[:base]).to include('Discussion to reply to cannot be found')
        end
      end

      context 'when user has no access to discussion' do
        let(:user) { other_user }

        it 'sets an error' do
          expect(new_note.errors[:base]).to include('Discussion to reply to cannot be found')
        end
      end

      context 'personal snippet note' do
        def reply(note, user = other_user)
          described_class.new(
            nil,
            user,
            note: 'Test',
            in_reply_to_discussion_id: note.discussion_id
          ).execute
        end

        let_it_be(:snippet_author) { noteable_author }

        context 'when a snippet is public' do
          it 'creates a reply note' do
            snippet = create(:personal_snippet, :public)
            note = create(:discussion_note_on_personal_snippet, noteable: snippet)

            new_note = reply(note)

            expect(new_note).to be_valid
            expect(new_note.in_reply_to?(note)).to be_truthy
          end
        end

        context 'when a snippet is private' do
          let_it_be(:snippet) { create(:personal_snippet, :private, author: snippet_author) }
          let_it_be(:note) { create(:discussion_note_on_personal_snippet, noteable: snippet) }

          it 'creates a reply note when the author replies' do
            new_note = reply(note, snippet_author)

            expect(new_note).to be_valid
            expect(new_note.in_reply_to?(note)).to be_truthy
          end

          it 'sets an error when another user replies' do
            new_note = reply(note)

            expect(new_note.errors[:base]).to include('Discussion to reply to cannot be found')
          end
        end

        context 'when a snippet is internal' do
          let_it_be(:snippet) { create(:personal_snippet, :internal, author: snippet_author) }
          let_it_be(:note) { create(:discussion_note_on_personal_snippet, noteable: snippet) }

          it 'creates a reply note when the author replies' do
            new_note = reply(note, snippet_author)

            expect(new_note).to be_valid
            expect(new_note.in_reply_to?(note)).to be_truthy
          end

          it 'creates a reply note when a regular user replies' do
            new_note = reply(note)

            expect(new_note).to be_valid
            expect(new_note.in_reply_to?(note)).to be_truthy
          end

          it 'sets an error when an external user replies' do
            new_note = reply(note, external)

            expect(new_note.errors[:base]).to include('Discussion to reply to cannot be found')
          end
        end
      end
    end

    context 'when replying to individual note' do
      let_it_be(:note) { create(:note_on_issue, project: project) }

      let(:params) { { in_reply_to_discussion_id: note.discussion_id } }

      it 'sets the note up to be in reply to that note' do
        expect(new_note).to be_valid
        expect(new_note).to be_a(DiscussionNote)
        expect(new_note.discussion_id).to eq(note.discussion_id)
      end

      context 'when noteable does not support replies' do
        let_it_be(:note) { create(:note_on_commit, project: project) }

        it 'builds another individual note' do
          expect(new_note).to be_valid
          expect(new_note).to be_a(Note)
          expect(new_note.discussion_id).not_to eq(note.discussion_id)
        end
      end
    end

    context 'confidential comments' do
      let_it_be(:project) { create(:project, :public) }
      let_it_be(:guest) { create(:user) }
      let_it_be(:reporter) { create(:user) }
      let_it_be(:admin) { create(:admin) }
      let_it_be(:issuable_assignee) { other_user }
      let_it_be(:issue) do
        create(:issue, project: project, author: noteable_author, assignees: [issuable_assignee])
      end

      before do
        project.add_guest(guest)
        project.add_reporter(reporter)
      end

      context 'when creating a new confidential comment' do
        let(:params) { { internal: true, noteable: issue } }

        shared_examples 'user allowed to set comment as confidential' do
          it { expect(new_note.confidential).to be_truthy }
        end

        shared_examples 'user not allowed to set comment as confidential' do
          it { expect(new_note.confidential).to be_falsey }
        end

        context 'reporter' do
          let(:user) { reporter }

          it_behaves_like 'user allowed to set comment as confidential'
        end

        context 'issuable author' do
          let(:user) { noteable_author }

          it_behaves_like 'user not allowed to set comment as confidential'
        end

        context 'issuable assignee' do
          let(:user) { issuable_assignee }

          it_behaves_like 'user not allowed to set comment as confidential'
        end

        context 'admin' do
          before do
            enable_admin_mode!(admin)
          end

          let(:user) { admin }

          it_behaves_like 'user allowed to set comment as confidential'
        end

        context 'external' do
          let(:user) { external }

          it_behaves_like 'user not allowed to set comment as confidential'
        end

        context 'guest' do
          let(:user) { guest }

          it_behaves_like 'user not allowed to set comment as confidential'
        end

        context 'when using the deprecated `confidential` parameter' do
          let(:params) { { internal: true, noteable: issue } }

          shared_examples 'user allowed to set comment as confidential' do
            it { expect(new_note.confidential).to be_truthy }
          end
        end
      end

      context 'when replying to a confidential comment' do
        let_it_be(:note) { create(:note_on_issue, confidential: true, noteable: issue, project: project) }

        let(:params) { { in_reply_to_discussion_id: note.discussion_id, confidential: false } }

        shared_examples 'returns `Discussion to reply to cannot be found` error' do
          it do
            expect(new_note.errors.added?(:base, "Discussion to reply to cannot be found")).to be true
          end
        end

        shared_examples 'confidential set to `true`' do
          it '`confidential` param is ignored to match the parent note confidentiality' do
            expect(new_note.confidential).to be_truthy
          end
        end

        context 'with reporter access' do
          let(:user) { reporter }

          it_behaves_like 'confidential set to `true`'
        end

        context 'with admin access' do
          let(:user) { admin }

          before do
            enable_admin_mode!(admin)
          end

          it_behaves_like 'confidential set to `true`'
        end

        context 'with noteable author' do
          let(:user) { note.noteable.author }

          it_behaves_like 'returns `Discussion to reply to cannot be found` error'
        end

        context 'with noteable assignee' do
          let(:user) { issuable_assignee }

          it_behaves_like 'returns `Discussion to reply to cannot be found` error'
        end

        context 'with guest access' do
          let(:user) { guest }

          it_behaves_like 'returns `Discussion to reply to cannot be found` error'
        end

        context 'with external user' do
          let(:user) { external }

          it_behaves_like 'returns `Discussion to reply to cannot be found` error'
        end
      end

      context 'when replying to a public comment' do
        let_it_be(:note) { create(:note_on_issue, confidential: false, noteable: issue, project: project) }

        let(:params) { { in_reply_to_discussion_id: note.discussion_id, confidential: true } }

        it '`confidential` param is ignored and set to `false`' do
          expect(new_note.confidential).to be_falsey
        end
      end
    end

    context 'when noteable is not set' do
      let(:params) { { noteable_type: note.noteable_type, noteable_id: note.noteable_id } }

      it 'builds a note without saving it' do
        expect(new_note).to be_valid
        expect(new_note).not_to be_persisted
      end
    end
  end
end


Instruction:
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true

module Notes
  class DestroyService < ::Notes::BaseService
    def execute(note)
      TodoService.new.destroy_target(note) do |note|
        note.destroy
      end

      clear_noteable_diffs_cache(note)
      track_note_removal_usage_for_issues(note) if note.for_issue?
      track_note_removal_usage_for_merge_requests(note) if note.for_merge_request?
      track_note_removal_usage_for_design(note) if note.for_design?
    end

    private

    def track_note_removal_usage_for_issues(note)
      Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_comment_removed_action(
        author: note.author,
        project: project
      )
    end

    def track_note_removal_usage_for_merge_requests(note)
      Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter.track_remove_comment_action(note: note)
    end

    def track_note_removal_usage_for_design(note)
      Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_design_comment_removed_action(
        author: note.author,
        project: project
      )
    end
  end
end

Notes::DestroyService.prepend_mod_with('Notes::DestroyService')

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Notes::DestroyService, feature_category: :team_planning do
  let_it_be(:project) { create(:project, :public) }
  let_it_be(:issue) { create(:issue, project: project) }

  let(:user) { issue.author }

  describe '#execute' do
    it 'deletes a note' do
      note = create(:note, project: project, noteable: issue)

      described_class.new(project, user).execute(note)

      expect(project.issues.find(issue.id).notes).not_to include(note)
    end

    it 'updates the todo counts for users with todos for the note' do
      note = create(:note, project: project, noteable: issue)
      create(:todo, note: note, target: issue, user: user, author: user, project: project)

      expect { described_class.new(project, user).execute(note) }
        .to change { user.todos_pending_count }.from(1).to(0)
    end

    describe 'comment removed event tracking', :snowplow do
      let(:event) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_COMMENT_REMOVED }
      let(:note) { create(:note, project: project, noteable: issue) }
      let(:service_action) { described_class.new(project, user).execute(note) }

      it 'tracks issue comment removal usage data', :clean_gitlab_redis_shared_state do
        counter = Gitlab::UsageDataCounters::HLLRedisCounter

        expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_comment_removed_action)
                                                                           .with(author: user, project: project)
                                                                           .and_call_original
        expect do
          service_action
        end.to change {
                 counter.unique_events(event_names: event, start_date: Date.today.beginning_of_week, end_date: 1.week.from_now)
               }.by(1)
      end

      it_behaves_like 'internal event tracking' do
        let(:namespace) { project.namespace }
        subject(:execute_service_action) { service_action }
      end
    end

    it 'tracks merge request usage data' do
      mr = create(:merge_request, source_project: project)
      note = create(:note, project: project, noteable: mr)
      expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter).to receive(:track_remove_comment_action).with(note: note)

      described_class.new(project, user).execute(note)
    end

    context 'in a merge request' do
      let_it_be(:repo_project) { create(:project, :repository) }
      let_it_be(:merge_request) do
        create(:merge_request, source_project: repo_project, target_project: repo_project)
      end

      let_it_be(:note) do
        create(:diff_note_on_merge_request, project: repo_project, noteable: merge_request)
      end

      it 'does not track issue comment removal usage data' do
        expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_comment_removed_action)

        described_class.new(repo_project, user).execute(note)
      end

      context 'noteable highlight cache clearing' do
        before do
          allow(note.position).to receive(:unfolded_diff?) { true }
        end

        it 'clears noteable diff cache when it was unfolded for the note position' do
          expect(merge_request).to receive_message_chain(:diffs, :clear_cache)

          described_class.new(repo_project, user).execute(note)
        end

        it 'does not clear cache when note is not the first of the discussion' do
          reply_note = create(:diff_note_on_merge_request,
            in_reply_to: note, project: repo_project, noteable: merge_request)

          expect(merge_request).not_to receive(:diffs)

          described_class.new(repo_project, user).execute(reply_note)
        end
      end
    end

    it 'tracks design comment removal' do
      note = create(:note_on_design, project: project)
      expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(
        :track_issue_design_comment_removed_action
      ).with(
        author: note.author,
        project: project
      )

      described_class.new(project, user).execute(note)
    end
  end
end


Instruction:
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true

module Notes
  class UpdateService < BaseService
    def execute(note)
      return note unless note.editable? && params.present?

      old_mentioned_users = note.mentioned_users(current_user).to_a

      note.assign_attributes(params)

      return note unless note.valid?

      track_note_edit_usage_for_issues(note) if note.for_issue?
      track_note_edit_usage_for_merge_requests(note) if note.for_merge_request?

      only_commands = false

      quick_actions_service = QuickActionsService.new(project, current_user)
      if quick_actions_service.supported?(note)
        content, update_params, message = quick_actions_service.execute(note, {})

        only_commands = content.empty?

        note.note = content
      end

      update_note(note, only_commands)
      note.save

      unless only_commands || note.for_personal_snippet?
        note.create_new_cross_references!(current_user)

        update_todos(note, old_mentioned_users)

        update_suggestions(note)
      end

      if quick_actions_service.commands_executed_count.to_i > 0
        if update_params.present?
          quick_actions_service.apply_updates(update_params, note)
          note.commands_changes = update_params
        end

        if only_commands
          delete_note(note, message)
        else
          note.save
        end
      end

      note
    end

    private

    def update_note(note, only_commands)
      return unless note.note_changed?

      note.assign_attributes(last_edited_at: Time.current, updated_by: current_user)
      note.check_for_spam(action: :update, user: current_user) unless only_commands
    end

    def delete_note(note, message)
      # We must add the error after we call #save because errors are reset
      # when #save is called
      note.errors.add(:commands_only, message.presence || _('Commands did not apply'))
      # Allow consumers to detect problems applying commands
      note.errors.add(:commands, _('Commands did not apply')) unless message.present?

      Notes::DestroyService.new(project, current_user).execute(note)
    end

    def update_suggestions(note)
      return unless note.supports_suggestion?

      Suggestion.transaction do
        note.suggestions.delete_all
        Suggestions::CreateService.new(note).execute
      end

      # We need to refresh the previous suggestions call cache
      # in order to get the new records.
      note.reset
    end

    def update_todos(note, old_mentioned_users)
      return unless note.previous_changes.include?('note')

      TodoService.new.update_note(note, current_user, old_mentioned_users)
    end

    def track_note_edit_usage_for_issues(note)
      Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_comment_edited_action(
        author: note.author,
        project: project
      )
    end

    def track_note_edit_usage_for_merge_requests(note)
      Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter.track_edit_comment_action(note: note)
    end
  end
end

Notes::UpdateService.prepend_mod_with('Notes::UpdateService')

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Notes::UpdateService, feature_category: :team_planning do
  let(:group) { create(:group, :public) }
  let(:project) { create(:project, :public, group: group) }
  let(:private_group) { create(:group, :private) }
  let(:private_project) { create(:project, :private, group: private_group) }
  let(:user) { create(:user) }
  let(:user2) { create(:user) }
  let(:user3) { create(:user) }
  let(:issue) { create(:issue, project: project) }
  let(:issue2) { create(:issue, project: private_project) }
  let(:note) { create(:note, project: project, noteable: issue, author: user, note: "Old note #{user2.to_reference}") }
  let(:markdown) do
    <<-MARKDOWN.strip_heredoc
      ```suggestion
        foo
      ```

      ```suggestion
        bar
      ```
    MARKDOWN
  end

  before do
    project.add_maintainer(user)
    project.add_developer(user2)
    project.add_developer(user3)
    group.add_developer(user3)
    private_group.add_developer(user)
    private_group.add_developer(user2)
    private_project.add_developer(user3)
  end

  describe '#execute' do
    def update_note(opts)
      @note = Notes::UpdateService.new(project, user, opts).execute(note)
      @note.reload
    end

    it 'does not update the note when params is blank' do
      travel_to(1.day.from_now) do
        expect { update_note({}) }.not_to change { note.reload.updated_at }
      end
    end

    context 'when the note is invalid' do
      let(:edit_note_text) { { note: 'new text' } }

      before do
        allow(note).to receive(:valid?).and_return(false)
      end

      it 'does not update the note' do
        travel_to(1.day.from_now) do
          expect { update_note(edit_note_text) }.not_to change { note.reload.updated_at }
        end
      end

      it 'returns the note' do
        expect(update_note(edit_note_text)).to eq(note)
      end
    end

    describe 'event tracking', :snowplow do
      let(:event) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_COMMENT_EDITED }

      it 'does not track usage data when params is blank' do
        expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_comment_edited_action)
        expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter).not_to receive(:track_edit_comment_action)

        update_note({})
      end

      it_behaves_like 'internal event tracking' do
        let(:event) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_COMMENT_EDITED }
        let(:namespace) { project.namespace }

        subject(:service_action) { update_note(note: 'new text') }
      end

      it 'tracks issue usage data', :clean_gitlab_redis_shared_state do
        counter = Gitlab::UsageDataCounters::HLLRedisCounter

        expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_comment_edited_action)
                                                                           .with(author: user, project: project)
                                                                           .and_call_original
        expect do
          update_note(note: 'new text')
        end.to change { counter.unique_events(event_names: event, start_date: Date.today.beginning_of_week, end_date: 1.week.from_now) }.by(1)
      end
    end

    context 'when note text was changed' do
      let!(:note) { create(:note, project: project, noteable: issue, author: user2, note: "Old note #{user3.to_reference}") }
      let(:edit_note_text) { update_note({ note: 'new text' }) }

      it 'update last_edited_at' do
        travel_to(1.day.from_now) do
          expect { edit_note_text }.to change { note.reload.last_edited_at }
        end
      end

      it 'update updated_by' do
        travel_to(1.day.from_now) do
          expect { edit_note_text }.to change { note.reload.updated_by }
        end
      end

      it 'checks for spam' do
        expect(note).to receive(:check_for_spam).with(action: :update, user: user)
        edit_note_text
      end

      context 'when quick action only update' do
        it "delete note and return commands_only error" do
          updated_note = described_class.new(project, user, { note: "/close\n" }).execute(note)

          expect(updated_note.destroyed?).to eq(true)
          expect(updated_note.errors).to match_array([
            "Note can't be blank",
            "Commands only Closed this issue."
          ])
        end
      end
    end

    context 'when note text was not changed' do
      let!(:note) { create(:note, project: project, noteable: issue, author: user2, note: "Old note #{user3.to_reference}") }
      let(:does_not_edit_note_text) { update_note({}) }

      it 'does not update last_edited_at' do
        travel_to(1.day.from_now) do
          expect { does_not_edit_note_text }.not_to change { note.reload.last_edited_at }
        end
      end

      it 'does not update updated_by' do
        travel_to(1.day.from_now) do
          expect { does_not_edit_note_text }.not_to change { note.reload.updated_by }
        end
      end

      it 'does not check for spam' do
        expect(note).not_to receive(:check_for_spam)
        does_not_edit_note_text
      end
    end

    context 'when the notable is a merge request' do
      let(:merge_request) { create(:merge_request, source_project: project) }
      let(:note) { create(:note, project: project, noteable: merge_request, author: user, note: "Old note #{user2.to_reference}") }

      it 'tracks merge request usage data' do
        expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter).to receive(:track_edit_comment_action).with(note: note)

        update_note(note: 'new text')
      end
    end

    context 'with system note' do
      before do
        note.update_column(:system, true)
      end

      it 'does not update the note' do
        expect { update_note(note: 'new text') }.not_to change { note.reload.note }
      end

      it 'does not track usage data' do
        expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_comment_edited_action)

        update_note(note: 'new text')
      end
    end

    context 'suggestions' do
      it 'refreshes note suggestions' do
        suggestion = create(:suggestion)
        note = suggestion.note

        expect { described_class.new(project, user, note: markdown).execute(note) }
          .to change { note.suggestions.count }.from(1).to(2)

        expect(note.suggestions.order(:relative_order).map(&:to_content))
          .to eq(["  foo\n", "  bar\n"])
      end
    end

    context 'todos' do
      shared_examples 'does not update todos' do
        it 'keep todos' do
          expect(todo.reload).to be_pending
        end

        it 'does not create any new todos' do
          expect(Todo.count).to eq(1)
        end
      end

      shared_examples 'creates one todo' do
        it 'marks todos as done' do
          expect(todo.reload).to be_done
        end

        it 'creates only 1 new todo' do
          expect(Todo.count).to eq(2)
        end
      end

      context 'when note includes a user mention' do
        let!(:todo) { create(:todo, :assigned, user: user, project: project, target: issue, author: user2) }

        context 'when the note does not change mentions' do
          before do
            update_note({ note: "Old note #{user2.to_reference}" })
          end

          it_behaves_like 'does not update todos'
        end

        context 'when the note changes to include one more user mention' do
          before do
            update_note({ note: "New note #{user2.to_reference} #{user3.to_reference}" })
          end

          it_behaves_like 'creates one todo'
        end

        context 'when the note changes to include a group mentions' do
          before do
            update_note({ note: "New note #{private_group.to_reference}" })
          end

          it_behaves_like 'creates one todo'
        end
      end

      context 'when note includes a group mention' do
        context 'when the group is public' do
          let(:note) { create(:note, project: project, noteable: issue, author: user, note: "Old note #{group.to_reference}") }
          let!(:todo) { create(:todo, :assigned, user: user, project: project, target: issue, author: user2) }

          context 'when the note does not change mentions' do
            before do
              update_note({ note: "Old note #{group.to_reference}" })
            end

            it_behaves_like 'does not update todos'
          end

          context 'when the note changes mentions' do
            before do
              update_note({ note: "New note #{user2.to_reference} #{user3.to_reference}" })
            end

            it_behaves_like 'creates one todo'
          end
        end

        context 'when the group is private' do
          let(:note) { create(:note, project: project, noteable: issue, author: user, note: "Old note #{private_group.to_reference}") }
          let!(:todo) { create(:todo, :assigned, user: user, project: project, target: issue, author: user2) }

          context 'when the note does not change mentions' do
            before do
              update_note({ note: "Old note #{private_group.to_reference}" })
            end

            it_behaves_like 'does not update todos'
          end

          context 'when the note changes mentions' do
            before do
              update_note({ note: "New note #{user2.to_reference} #{user3.to_reference}" })
            end

            it_behaves_like 'creates one todo'
          end
        end
      end
    end

    context 'for a personal snippet' do
      let_it_be(:snippet) { create(:personal_snippet, :public) }

      let(:note) { create(:note, project: nil, noteable: snippet, author: user, note: "Note on a snippet with reference #{issue.to_reference}") }

      it 'does not create todos' do
        expect { update_note({ note: "Mentioning user #{user2}" }) }.not_to change { note.todos.count }
      end

      it 'does not create suggestions' do
        expect { update_note({ note: "Updated snippet with markdown suggestion #{markdown}" }) }
          .not_to change { note.suggestions.count }
      end

      it 'does not create mentions' do
        expect(note).not_to receive(:create_new_cross_references!)
        update_note({ note: "Updated with new reference: #{issue.to_reference}" })
      end

      it 'does not track usage data' do
        expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_comment_edited_action)

        update_note(note: 'new text')
      end
    end
  end
end


Instruction:
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true

module Notes
  class RenderService < BaseRenderer
    # Renders a collection of Note instances.
    #
    # notes - The notes to render.
    #
    # Possible options:
    #
    # requested_path - The request path.
    # project_wiki - The project's wiki.
    # ref - The current Git reference.
    # only_path - flag to turn relative paths into absolute ones.
    # xhtml - flag to save the html in XHTML
    def execute(notes, options = {})
      Banzai::ObjectRenderer
        .new(user: current_user, redaction_context: options)
        .render(notes, :note)
    end
  end
end

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Notes::RenderService, feature_category: :team_planning do
  describe '#execute' do
    it 'renders a Note' do
      note = double(:note)
      wiki = double(:wiki)
      user = double(:user)

      expect(Banzai::ObjectRenderer)
        .to receive(:new)
        .with(
          user: user,
          redaction_context: {
              requested_path: 'foo',
              project_wiki: wiki,
              ref: 'bar',
              only_path: nil,
              xhtml: false
          }
        )
        .and_call_original

      expect_any_instance_of(Banzai::ObjectRenderer)
        .to receive(:render)
        .with([note], :note)

      described_class.new(user).execute(
        [note],
        requested_path: 'foo',
        project_wiki: wiki,
        ref: 'bar',
        only_path: nil,
        xhtml: false
      )
    end
  end
end