summaryrefslogtreecommitdiff
path: root/spec/migrations/update_default_scan_method_of_dast_site_profile_spec.rb
blob: b73aa7016a141946f1830bde24c6e5cc7b67a752 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

require 'spec_helper'
require_migration!

RSpec.describe UpdateDefaultScanMethodOfDastSiteProfile do
  let(:namespaces) { table(:namespaces) }
  let(:projects) { table(:projects) }
  let(:dast_sites) { table(:dast_sites) }
  let(:dast_site_profiles) { table(:dast_site_profiles) }

  before do
    namespace = namespaces.create!(name: 'test', path: 'test')
    project = projects.create!(id: 12, namespace_id: namespace.id, name: 'gitlab', path: 'gitlab')
    dast_site = dast_sites.create!(id: 1, url: 'https://www.gitlab.com', project_id: project.id)

    dast_site_profiles.create!(id: 1, project_id: project.id, dast_site_id: dast_site.id,
                               name: "#{FFaker::Product.product_name.truncate(192)} #{SecureRandom.hex(4)} - 0",
                               scan_method: 0, target_type: 0)

    dast_site_profiles.create!(id: 2, project_id: project.id, dast_site_id: dast_site.id,
                               name: "#{FFaker::Product.product_name.truncate(192)} #{SecureRandom.hex(4)} - 1",
                               scan_method: 0, target_type: 1)
  end

  it 'updates the scan_method to 1 for profiles with target_type 1' do
    migrate!

    expect(dast_site_profiles.where(scan_method: 1).count).to eq 1
    expect(dast_site_profiles.where(scan_method: 0).count).to eq 1
  end
end