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

# Creates a new project with an associated project export file to be imported
# The associated project export file might be associated with different strategies
# to acquire the file to be imported, the default file_acquisition_strategy
# is uploading a file (Import::GitlabProjects::FileAcquisitionStrategies::FileUpload)
module Import
  module GitlabProjects
    class CreateProjectService
      include ActiveModel::Validations
      include ::Services::ReturnServiceResponses

      validates_presence_of :path, :namespace

      # Creates a new CreateProjectService.
      #
      # @param [User] current_user
      # @param [Hash] :params
      # @param [Import::GitlabProjects::FileAcquisitionStrategies::*] :file_acquisition_strategy
      def initialize(current_user, params:, file_acquisition_strategy: FileAcquisitionStrategies::FileUpload)
        @current_user = current_user
        @params = params.dup
        @strategy = file_acquisition_strategy.new(current_user: current_user, params: params)
      end

      # Creates a project with the strategy parameters
      #
      # @return [Services::ServiceReponse]
      def execute
        return error(errors.full_messages) unless valid?
        return error(project.errors.full_messages) unless project.saved?

        success(project)
      rescue StandardError => e
        error(e.message)
      end

      # Cascade the validation to strategy
      def valid?
        super && strategy.valid?
      end

      # Merge with strategy's errors
      def errors
        super.tap { _1.merge!(strategy.errors) }
      end

      def read_attribute_for_validation(key)
        params[key]
      end

      private

      attr_reader :current_user, :params, :strategy

      def error(messages)
        messages = Array.wrap(messages)
        message = messages.shift
        super(message, :bad_request, pass_back: { other_errors: messages })
      end

      def project
        @project ||= ::Projects::GitlabProjectsImportService.new(
          current_user,
          project_params,
          params[:override]
        ).execute
      end

      def project_params
        {
          name: params[:name],
          path: params[:path],
          namespace_id: params[:namespace].id,
          overwrite: params[:overwrite],
          import_type: 'gitlab_project'
        }.merge(strategy.project_params)
      end
    end
  end
end

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ::Import::GitlabProjects::CreateProjectService, :aggregate_failures, feature_category: :importers do
  let(:fake_file_acquisition_strategy) do
    Class.new do
      attr_reader :errors

      def initialize(...)
        @errors = ActiveModel::Errors.new(self)
      end

      def valid?
        true
      end

      def project_params
        {}
      end
    end
  end

  let(:params) do
    {
      path: 'path',
      namespace: user.namespace,
      name: 'name'
    }
  end

  let_it_be(:user) { create(:user) }

  subject { described_class.new(user, params: params, file_acquisition_strategy: FakeStrategy) }

  before do
    stub_const('FakeStrategy', fake_file_acquisition_strategy)
    stub_application_setting(import_sources: ['gitlab_project'])
  end

  describe 'validation' do
    it { expect(subject).to be_valid }

    it 'validates presence of path' do
      params[:path] = nil

      invalid = described_class.new(user, params: params, file_acquisition_strategy: FakeStrategy)

      expect(invalid).not_to be_valid
      expect(invalid.errors.full_messages).to include("Path can't be blank")
    end

    it 'validates presence of name' do
      params[:namespace] = nil

      invalid = described_class.new(user, params: params, file_acquisition_strategy: FakeStrategy)

      expect(invalid).not_to be_valid
      expect(invalid.errors.full_messages).to include("Namespace can't be blank")
    end

    it 'is invalid if the strategy is invalid' do
      expect_next_instance_of(FakeStrategy) do |strategy|
        allow(strategy).to receive(:valid?).and_return(false)
        allow(strategy).to receive(:errors).and_wrap_original do |original|
          original.call.tap do |errors|
            errors.add(:base, "some error")
          end
        end
      end

      invalid = described_class.new(user, params: params, file_acquisition_strategy: FakeStrategy)

      expect(invalid).not_to be_valid
      expect(invalid.errors.full_messages).to include("some error")
      expect(invalid.errors.full_messages).to include("some error")
    end
  end

  describe '#execute' do
    it 'creates a project successfully' do
      response = nil
      expect { response = subject.execute }
        .to change(Project, :count).by(1)

      expect(response).to be_success
      expect(response.http_status).to eq(:ok)
      expect(response.payload).to be_instance_of(Project)
      expect(response.payload.name).to eq('name')
      expect(response.payload.path).to eq('path')
      expect(response.payload.namespace).to eq(user.namespace)

      project = Project.last
      expect(project.name).to eq('name')
      expect(project.path).to eq('path')
      expect(project.namespace_id).to eq(user.namespace.id)
      expect(project.import_type).to eq('gitlab_project')
    end

    context 'when the project creation raises an error' do
      it 'fails to create a project' do
        expect_next_instance_of(Projects::GitlabProjectsImportService) do |service|
          expect(service).to receive(:execute).and_raise(StandardError, "failed to create project")
        end

        response = nil
        expect { response = subject.execute }
          .to change(Project, :count).by(0)

        expect(response).to be_error
        expect(response.http_status).to eq(:bad_request)
        expect(response.message).to eq("failed to create project")
        expect(response.payload).to eq(other_errors: [])
      end
    end

    context 'when the validation fail' do
      it 'fails to create a project' do
        params.delete(:path)

        response = nil
        expect { response = subject.execute }
          .to change(Project, :count).by(0)

        expect(response).to be_error
        expect(response.http_status).to eq(:bad_request)
        expect(response.message).to eq("Path can't be blank")
        expect(response.payload).to eq(other_errors: [])
      end

      context 'when the project contains multiple errors' do
        it 'fails to create a project' do
          params.merge!(name: '_ an invalid name _', path: '_ an invalid path _')

          response = nil
          expect { response = subject.execute }
            .to change(Project, :count).by(0)

          expect(response).to be_error
          expect(response.http_status).to eq(:bad_request)
          expect(response.message).to eq(
            'Project namespace path must not start or end with a special character and must not contain consecutive ' \
            'special characters.'
          )
          expect(response.payload).to eq(
            other_errors: [
              %(Project namespace path can contain only letters, digits, '_', '-' and '.'. Cannot start with '-', end in '.git' or end in '.atom'),
              %(Path can contain only letters, digits, '_', '-' and '.'. Cannot start with '-', end in '.git' or end in '.atom'),
              %(Path must not start or end with a special character and must not contain consecutive special characters.)
            ])
        end
      end
    end

    context 'when the strategy adds project parameters' do
      before do
        expect_next_instance_of(FakeStrategy) do |strategy|
          expect(strategy).to receive(:project_params).and_return(name: 'the strategy name')
        end

        subject.valid?
      end

      it 'merges the strategy project parameters' do
        response = nil
        expect { response = subject.execute }
          .to change(Project, :count).by(1)

        expect(response).to be_success
        expect(response.http_status).to eq(:ok)
        expect(response.payload).to be_instance_of(Project)
        expect(response.payload.name).to eq('the strategy name')
        expect(response.payload.path).to eq('path')
        expect(response.payload.namespace).to eq(user.namespace)

        project = Project.last
        expect(project.name).to eq('the strategy name')
        expect(project.path).to eq('path')
        expect(project.namespace_id).to eq(user.namespace.id)
        expect(project.import_type).to eq('gitlab_project')
      end
    end
  end
end


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

module Import
  module GitlabProjects
    module FileAcquisitionStrategies
      class FileUpload
        include ActiveModel::Validations

        validate :uploaded_file

        def initialize(params:, current_user: nil)
          @params = params
        end

        def project_params
          @project_params ||= @params.slice(:file)
        end

        def file
          @file ||= @params[:file]
        end

        private

        def uploaded_file
          return if file.present? && file.is_a?(UploadedFile)

          errors.add(:file, 'must be uploaded')
        end
      end
    end
  end
end

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ::Import::GitlabProjects::FileAcquisitionStrategies::FileUpload, :aggregate_failures, feature_category: :importers do
  let(:file) { UploadedFile.new(File.join('spec', 'features', 'projects', 'import_export', 'test_project_export.tar.gz')) }

  describe 'validation' do
    it 'validates presence of file' do
      valid = described_class.new(params: { file: file })
      expect(valid).to be_valid

      invalid = described_class.new(params: {})
      expect(invalid).not_to be_valid
      expect(invalid.errors.full_messages).to include("File must be uploaded")
    end
  end

  describe '#project_params' do
    it 'returns the file to upload in the params' do
      subject = described_class.new(params: { file: file })

      expect(subject.project_params).to eq(file: file)
    end
  end
end


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

module Import
  module GitlabProjects
    module FileAcquisitionStrategies
      class RemoteFileS3
        include ActiveModel::Validations
        include Gitlab::Utils::StrongMemoize

        def self.allow_local_requests?
          ::Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?
        end

        validates_presence_of :region, :bucket_name, :file_key, :access_key_id, :secret_access_key
        validates :file_url, addressable_url: {
          schemes: %w[https],
          allow_localhost: allow_local_requests?,
          allow_local_network: allow_local_requests?,
          dns_rebind_protection: true
        }

        validates_with RemoteFileValidator

        # The import itself has a limit of 24h, since the URL is created before the import starts
        # we add an expiration a bit longer to ensure it won't expire during the import.
        URL_EXPIRATION = 28.hours.seconds

        def initialize(params:, current_user: nil)
          @params = params
        end

        def project_params
          @project_parms ||= {
            import_export_upload: ::ImportExportUpload.new(remote_import_url: file_url)
          }
        end

        def file_url
          @file_url ||= s3_object&.presigned_url(:get, expires_in: URL_EXPIRATION.to_i)
        end

        def content_type
          @content_type ||= s3_object&.content_type
        end

        def content_length
          @content_length ||= s3_object&.content_length.to_i
        end

        # Make the validated params/methods accessible
        def read_attribute_for_validation(key)
          return file_url if key == :file_url

          params[key]
        end

        private

        attr_reader :params

        def s3_object
          strong_memoize(:s3_object) do
            build_s3_options
          end
        end

        def build_s3_options
          object = Aws::S3::Object.new(
            params[:bucket_name],
            params[:file_key],
            client: Aws::S3::Client.new(
              region: params[:region],
              access_key_id: params[:access_key_id],
              secret_access_key: params[:secret_access_key]
            )
          )

          # Force validate if the object exists and is accessible
          # Some exceptions are only raised when trying to access the object data
          unless object.exists?
            errors.add(:base, "File not found '#{params[:file_key]}' in '#{params[:bucket_name]}'")
            return
          end

          object
        rescue StandardError => e
          errors.add(:base, "Failed to open '#{params[:file_key]}' in '#{params[:bucket_name]}': #{e.message}")
          nil
        end
      end
    end
  end
end

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ::Import::GitlabProjects::FileAcquisitionStrategies::RemoteFileS3, :aggregate_failures, feature_category: :importers do
  let(:region_name) { 'region_name' }
  let(:bucket_name) { 'bucket_name' }
  let(:file_key) { 'file_key' }
  let(:access_key_id) { 'access_key_id' }
  let(:secret_access_key) { 'secret_access_key' }
  let(:file_exists) { true }
  let(:content_type) { 'application/x-tar' }
  let(:content_length) { 10.megabytes }
  let(:presigned_url) { 'https://external.file.path/file.tar.gz?PRESIGNED=true&TOKEN=some-token' }

  let(:s3_double) do
    instance_double(
      Aws::S3::Object,
      exists?: file_exists,
      content_type: content_type,
      content_length: content_length,
      presigned_url: presigned_url
    )
  end

  let(:params) do
    {
      region: region_name,
      bucket_name: bucket_name,
      file_key: file_key,
      access_key_id: access_key_id,
      secret_access_key: secret_access_key
    }
  end

  subject { described_class.new(params: params) }

  before do
    # Avoid network requests
    expect(Aws::S3::Client).to receive(:new).and_return(double)
    expect(Aws::S3::Object).to receive(:new).and_return(s3_double)

    stub_application_setting(max_import_remote_file_size: 10)
  end

  describe 'validation' do
    it { expect(subject).to be_valid }

    %i[region bucket_name file_key access_key_id secret_access_key].each do |key|
      context "#{key} validation" do
        before do
          params[key] = nil
        end

        it "validates presence of #{key}" do
          expect(subject).not_to be_valid
          expect(subject.errors.full_messages)
            .to include("#{key.to_s.humanize} can't be blank")
        end
      end
    end

    context 'content-length validation' do
      let(:content_length) { 11.megabytes }

      it 'validates the remote content-length' do
        expect(subject).not_to be_valid
        expect(subject.errors.full_messages)
          .to include('Content length is too big (should be at most 10 MiB)')
      end
    end

    context 'content-type validation' do
      let(:content_type) { 'unknown' }

      it 'validates the remote content-type' do
        expect(subject).not_to be_valid
        expect(subject.errors.full_messages)
          .to include("Content type 'unknown' not allowed. (Allowed: application/gzip, application/x-tar, application/x-gzip)")
      end
    end

    context 'file_url validation' do
      let(:presigned_url) { 'ftp://invalid.url/file.tar.gz' }

      it 'validates the file_url scheme' do
        expect(subject).not_to be_valid
        expect(subject.errors.full_messages)
          .to include("File url is blocked: Only allowed schemes are https")
      end

      context 'when localhost urls are not allowed' do
        let(:presigned_url) { 'https://localhost:3000/file.tar.gz' }

        it 'validates the file_url' do
          stub_application_setting(allow_local_requests_from_web_hooks_and_services: false)

          expect(subject).not_to be_valid
          expect(subject.errors.full_messages)
            .to include("File url is blocked: Requests to localhost are not allowed")
        end
      end
    end

    context 'when the remote file does not exist' do
      it 'foo' do
        expect(s3_double).to receive(:exists?).and_return(false)

        expect(subject).not_to be_valid
        expect(subject.errors.full_messages)
          .to include("File not found 'file_key' in 'bucket_name'")
      end
    end

    context 'when it fails to build the s3 object' do
      it 'foo' do
        expect(s3_double).to receive(:exists?).and_raise(StandardError, "some error")

        expect(subject).not_to be_valid
        expect(subject.errors.full_messages)
          .to include("Failed to open 'file_key' in 'bucket_name': some error")
      end
    end
  end

  describe '#project_params' do
    it 'returns import_export_upload in the params' do
      subject = described_class.new(params: { remote_import_url: presigned_url })

      expect(subject.project_params).to match(
        import_export_upload: an_instance_of(::ImportExportUpload)
      )
      expect(subject.project_params[:import_export_upload]).to have_attributes(
        remote_import_url: presigned_url
      )
    end
  end
end


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

module Import
  module GitlabProjects
    module FileAcquisitionStrategies
      class RemoteFile
        include ActiveModel::Validations

        def self.allow_local_requests?
          ::Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?
        end

        validates :file_url, addressable_url: {
          schemes: %w[https],
          allow_localhost: allow_local_requests?,
          allow_local_network: allow_local_requests?,
          dns_rebind_protection: true
        }

        validates_with RemoteFileValidator, if: -> { !s3_request? }

        def initialize(params:, current_user: nil)
          @params = params
        end

        def project_params
          @project_parms ||= {
            import_export_upload: ::ImportExportUpload.new(remote_import_url: file_url)
          }
        end

        def file_url
          @file_url ||= params[:remote_import_url]
        end

        def content_type
          @content_type ||= headers['content-type']
        end

        def content_length
          @content_length ||= headers['content-length'].to_i
        end

        private

        attr_reader :params

        def s3_request?
          headers['Server'] == 'AmazonS3' && headers['x-amz-request-id'].present?
        end

        def headers
          return {} if file_url.blank?

          @headers ||= Gitlab::HTTP.head(file_url, timeout: 1.second).headers
        rescue StandardError => e
          errors.add(:base, "Failed to retrive headers: #{e.message}")

          {}
        end
      end
    end
  end
end

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ::Import::GitlabProjects::FileAcquisitionStrategies::RemoteFile, :aggregate_failures, feature_category: :importers do
  let(:remote_url) { 'https://external.file.path/file.tar.gz' }
  let(:params) { { remote_import_url: remote_url } }

  subject { described_class.new(params: params) }

  before do
    stub_application_setting(max_import_remote_file_size: 10)

    stub_headers_for(remote_url, {
      'content-length' => 10.megabytes,
      'content-type' => 'application/gzip'
    })
  end

  describe 'validation' do
    it { expect(subject).to be_valid }

    context 'file_url validation' do
      let(:remote_url) { 'ftp://invalid.url/file.tar.gz' }

      it 'validates the file_url scheme' do
        expect(subject).not_to be_valid
        expect(subject.errors.full_messages)
          .to include("File url is blocked: Only allowed schemes are https")
      end

      context 'when localhost urls are not allowed' do
        let(:remote_url) { 'https://localhost:3000/file.tar.gz' }

        it 'validates the file_url' do
          stub_application_setting(allow_local_requests_from_web_hooks_and_services: false)

          expect(subject).not_to be_valid
          expect(subject.errors.full_messages)
            .to include("File url is blocked: Requests to localhost are not allowed")
        end
      end
    end

    context 'when the HTTP request fails to recover the headers' do
      it 'adds the error message' do
        expect(Gitlab::HTTP)
          .to receive(:head)
          .and_raise(StandardError, 'request invalid')

        expect(subject).not_to be_valid
        expect(subject.errors.full_messages)
          .to include('Failed to retrive headers: request invalid')
      end
    end

    context 'when request is not from an S3 server' do
      it 'validates the remote content-length' do
        stub_application_setting(max_import_remote_file_size: 1)

        expect(subject).not_to be_valid
        expect(subject.errors.full_messages)
          .to include('Content length is too big (should be at most 1 MiB)')
      end

      it 'validates the remote content-type' do
        stub_headers_for(remote_url, { 'content-type' => 'unknown' })

        expect(subject).not_to be_valid
        expect(subject.errors.full_messages)
          .to include("Content type 'unknown' not allowed. (Allowed: application/gzip, application/x-tar, application/x-gzip)")
      end
    end

    context 'when request is from an S3 server' do
      it 'does not validate the remote content-length or content-type' do
        stub_headers_for(
          remote_url,
          'Server' => 'AmazonS3',
          'x-amz-request-id' => 'some-id',
          'content-length' => 11.gigabytes,
          'content-type' => 'unknown'
        )

        expect(subject).to be_valid
      end
    end
  end

  describe '#project_params' do
    it 'returns import_export_upload in the params' do
      subject = described_class.new(params: { remote_import_url: remote_url })

      expect(subject.project_params).to match(
        import_export_upload: an_instance_of(::ImportExportUpload)
      )
      expect(subject.project_params[:import_export_upload]).to have_attributes(
        remote_import_url: remote_url
      )
    end
  end

  def stub_headers_for(url, headers = {})
    allow(Gitlab::HTTP)
      .to receive(:head)
      .with(remote_url, timeout: 1.second)
      .and_return(double(headers: headers)) # rubocop: disable RSpec/VerifiedDoubles
  end
end


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

module Import
  module Github
    class GistsImportService < ::BaseService
      def initialize(user, client, params)
        @current_user = user
        @params = params
        @client = client
      end

      def execute
        return error('Import already in progress', 422) if import_status.started?

        check_user_token
        start_import
        success
      rescue Octokit::Unauthorized
        error('Access denied to the GitHub account.', 401)
      end

      private

      def import_status
        @import_status ||= Gitlab::GithubGistsImport::Status.new(current_user.id)
      end

      def encrypted_token
        Gitlab::CryptoHelper.aes256_gcm_encrypt(params[:github_access_token])
      end

      def start_import
        Gitlab::GithubGistsImport::StartImportWorker.perform_async(current_user.id, encrypted_token)
        import_status.start!
      end

      def check_user_token
        @client.octokit.user.present?
      end
    end
  end
end

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Import::Github::GistsImportService, feature_category: :importers do
  subject(:import) { described_class.new(user, client, params) }

  let_it_be(:user) { create(:user) }
  let(:params) { { github_access_token: 'token' } }
  let(:import_status) { instance_double('Gitlab::GithubGistsImport::Status') }
  let(:client) { Gitlab::GithubImport::Client.new(params[:github_access_token]) }
  let(:octokit_user) { { login: 'user_login' } }

  describe '#execute', :aggregate_failures do
    before do
      allow(Gitlab::GithubGistsImport::Status).to receive(:new).and_return(import_status)
      allow(client.octokit).to receive(:user).and_return(octokit_user)
    end

    context 'when import in progress' do
      let(:expected_result) do
        {
          status: :error,
          http_status: 422,
          message: 'Import already in progress'
        }
      end

      it 'returns error' do
        expect(import_status).to receive(:started?).and_return(true)
        expect(import.execute).to eq(expected_result)
      end
    end

    context 'when import was not started' do
      it 'returns success' do
        encrypted_token = Gitlab::CryptoHelper.aes256_gcm_encrypt(params[:github_access_token])
        expect(import_status).to receive(:started?).and_return(false)
        expect(Gitlab::CryptoHelper)
          .to receive(:aes256_gcm_encrypt).with(params[:github_access_token])
          .and_return(encrypted_token)
        expect(Gitlab::GithubGistsImport::StartImportWorker)
          .to receive(:perform_async).with(user.id, encrypted_token)
        expect(import_status).to receive(:start!)

        expect(import.execute).to eq({ status: :success })
      end
    end

    context 'when user token is invalid' do
      before do
        allow(client.octokit).to receive(:user).and_raise(Octokit::Unauthorized)
        allow(import_status).to receive(:started?).and_return(false)
      end

      let(:expected_result) do
        {
          http_status: 401,
          message: 'Access denied to the GitHub account.',
          status: :error
        }
      end

      it 'returns 401 error' do
        expect(import.execute).to eq(expected_result)
      end
    end
  end
end


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

module Import
  module Github
    class CancelProjectImportService < ::BaseService
      def execute
        return error('Not Found', :not_found) unless authorized_to_read?
        return error('Unauthorized access', :forbidden) unless authorized_to_cancel?

        if project.import_state.completed?
          error(cannot_cancel_error_message, :bad_request)
        else
          project.import_state.cancel
          metrics.track_canceled_import

          success(project: project)
        end
      end

      private

      def authorized_to_read?
        can?(current_user, :read_project, project)
      end

      def authorized_to_cancel?
        can?(current_user, :owner_access, project)
      end

      def cannot_cancel_error_message
        format(
          _('The import cannot be canceled because it is %{project_status}'),
          project_status: project.import_state.status
        )
      end

      def metrics
        @metrics ||= Gitlab::Import::Metrics.new(:github_importer, project)
      end
    end
  end
end

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Import::Github::CancelProjectImportService, feature_category: :importers do
  subject(:import_cancel) { described_class.new(project, project.owner) }

  let_it_be(:user) { create(:user) }
  let_it_be_with_reload(:project) { create(:project, :import_started, import_type: 'github', import_url: 'https://fake.url') }

  describe '.execute' do
    context 'when user is an owner' do
      context 'when import is in progress' do
        it 'update import state to be canceled' do
          expect(import_cancel.execute).to eq({ status: :success, project: project })
        end

        it 'tracks canceled imports' do
          metrics_double = instance_double('Gitlab::Import::Metrics')

          expect(Gitlab::Import::Metrics)
            .to receive(:new)
            .with(:github_importer, project)
            .and_return(metrics_double)
          expect(metrics_double).to receive(:track_canceled_import)

          import_cancel.execute
        end
      end

      context 'when import is finished' do
        let(:expected_result) do
          {
            status: :error,
            http_status: :bad_request,
            message: 'The import cannot be canceled because it is finished'
          }
        end

        before do
          project.import_state.finish!
        end

        it 'returns error' do
          expect(import_cancel.execute).to eq(expected_result)
        end
      end
    end

    context 'when user is not allowed to read project' do
      it 'returns 404' do
        expect(described_class.new(project, user).execute)
          .to eq({ status: :error, http_status: :not_found, message: 'Not Found' })
      end
    end

    context 'when user is not allowed to cancel project' do
      before do
        project.add_developer(user)
      end

      it 'returns 403' do
        expect(described_class.new(project, user).execute)
          .to eq({ status: :error, http_status: :forbidden, message: 'Unauthorized access' })
      end
    end
  end
end


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

module Import
  module Github
    module Notes
      class CreateService < ::Notes::CreateService
        # Github does not have support to quick actions in notes (like /assign)
        # Therefore, when importing notes we skip the quick actions processing
        def quick_actions_supported?(_note)
          false
        end
      end
    end
  end
end

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Import::Github::Notes::CreateService, feature_category: :importers do
  it 'does not support quick actions' do
    project = create(:project, :repository)
    user = create(:user)
    merge_request = create(:merge_request, source_project: project)

    project.add_maintainer(user)

    note = described_class.new(
      project,
      user,
      note: '/close',
      noteable_type: 'MergeRequest',
      noteable_id: merge_request.id
    ).execute

    expect(note.note).to eq('/close')
    expect(note.noteable.closed?).to be(false)
  end
end


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

module QuickActions
  class TargetService < BaseService
    def execute(type, type_iid)
      case type&.downcase
      when 'workitem'
        work_item(type_iid)
      when 'issue'
        issue(type_iid)
      when 'mergerequest'
        merge_request(type_iid)
      when 'commit'
        commit(type_iid)
      end
    end

    private

    # rubocop: disable CodeReuse/ActiveRecord
    def work_item(type_iid)
      WorkItems::WorkItemsFinder.new(current_user, project_id: project.id).find_by(iid: type_iid)
    end
    # rubocop: enable CodeReuse/ActiveRecord

    # rubocop: disable CodeReuse/ActiveRecord
    def issue(type_iid)
      return project.issues.build if type_iid.nil?

      IssuesFinder.new(current_user, project_id: project.id).find_by(iid: type_iid) || project.issues.build
    end
    # rubocop: enable CodeReuse/ActiveRecord

    # rubocop: disable CodeReuse/ActiveRecord
    def merge_request(type_iid)
      return project.merge_requests.build if type_iid.nil?

      MergeRequestsFinder.new(current_user, project_id: project.id).find_by(iid: type_iid) || project.merge_requests.build
    end
    # rubocop: enable CodeReuse/ActiveRecord

    def commit(type_iid)
      project.commit(type_iid)
    end
  end
end

QuickActions::TargetService.prepend_mod_with('QuickActions::TargetService')

```

Response:
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe QuickActions::TargetService, feature_category: :team_planning do
  let(:project) { create(:project) }
  let(:user) { create(:user) }
  let(:service) { described_class.new(project, user) }

  before do
    project.add_maintainer(user)
  end

  describe '#execute' do
    shared_examples 'no target' do |type_iid:|
      it 'returns nil' do
        target = service.execute(type, type_iid)

        expect(target).to be_nil
      end
    end

    shared_examples 'find target' do
      it 'returns the target' do
        found_target = service.execute(type, target_iid)

        expect(found_target).to eq(target)
      end
    end

    shared_examples 'build target' do |type_iid:|
      it 'builds a new target' do
        target = service.execute(type, type_iid)

        expect(target.project).to eq(project)
        expect(target).to be_new_record
      end
    end

    context 'for issue' do
      let(:target) { create(:issue, project: project) }
      let(:target_iid) { target.iid }
      let(:type) { 'Issue' }

      it_behaves_like 'find target'
      it_behaves_like 'build target', type_iid: nil
      it_behaves_like 'build target', type_iid: -1
    end

    context 'for work item' do
      let(:target) { create(:work_item, :task, project: project) }
      let(:target_iid) { target.iid }
      let(:type) { 'WorkItem' }

      it_behaves_like 'find target'
    end

    context 'for merge request' do
      let(:target) { create(:merge_request, source_project: project) }
      let(:target_iid) { target.iid }
      let(:type) { 'MergeRequest' }

      it_behaves_like 'find target'
      it_behaves_like 'build target', type_iid: nil
      it_behaves_like 'build target', type_iid: -1
    end

    context 'for commit' do
      let(:project) { create(:project, :repository) }
      let(:target) { project.commit.parent }
      let(:target_iid) { target.sha }
      let(:type) { 'Commit' }

      it_behaves_like 'find target'
      it_behaves_like 'no target', type_iid: 'invalid_sha'

      context 'with nil target_iid' do
        let(:target) { project.commit }
        let(:target_iid) { nil }

        it_behaves_like 'find target'
      end
    end

    context 'for unknown type' do
      let(:type) { 'unknown' }

      it_behaves_like 'no target', type_iid: :unused
    end
  end
end