Commit 7043b942 authored by Andrejs Cunskis's avatar Andrejs Cunskis

Merge branch 'acunskis-milestone-migration' into 'master'

E2E: Add milestone migration validation spec

See merge request gitlab-org/gitlab!69616
parents 3539ff1f b7ee782d
......@@ -30,6 +30,22 @@ module QA
end
end
# Get group milestones
#
# @return [Array<QA::Resource::GroupMilestone>]
def milestones
parse_body(api_get_from("#{api_get_path}/milestones")).map do |milestone|
GroupMilestone.init do |resource|
resource.api_client = api_client
resource.group = self
resource.id = milestone[:id]
resource.iid = milestone[:iid]
resource.title = milestone[:title]
resource.description = milestone[:description]
end
end
end
# API get path
#
# @return [String]
......
......@@ -3,11 +3,14 @@
module QA
module Resource
class GroupMilestone < Base
attr_writer :start_date, :due_date
attribute :id
attribute :title
attribute :description
attributes :id,
:iid,
:title,
:description,
:start_date,
:due_date,
:updated_at,
:created_at
attribute :group do
Group.fabricate_via_api! do |resource|
......@@ -20,6 +23,21 @@ module QA
@description = "My awesome group milestone."
end
def fabricate!
group.visit!
Page::Group::Menu.perform(&:go_to_milestones)
Page::Group::Milestone::Index.perform(&:click_new_milestone_link)
Page::Group::Milestone::New.perform do |new_milestone|
new_milestone.set_title(@title)
new_milestone.set_description(@description)
new_milestone.set_start_date(@start_date) if @start_date
new_milestone.set_due_date(@due_date) if @due_date
new_milestone.click_create_milestone_button
end
end
def api_get_path
"/groups/#{group.id}/milestones/#{id}"
end
......@@ -38,19 +56,36 @@ module QA
end
end
def fabricate!
group.visit!
# Object comparison
#
# @param [QA::Resource::GroupMilestone] other
# @return [Boolean]
def ==(other)
other.is_a?(GroupMilestone) && comparable_milestone == other.comparable_milestone
end
Page::Group::Menu.perform(&:go_to_milestones)
Page::Group::Milestone::Index.perform(&:click_new_milestone_link)
# Override inspect for a better rspec failure diff output
#
# @return [String]
def inspect
JSON.pretty_generate(comparable_milestone)
end
Page::Group::Milestone::New.perform do |new_milestone|
new_milestone.set_title(@title)
new_milestone.set_description(@description)
new_milestone.set_start_date(@start_date) if @start_date
new_milestone.set_due_date(@due_date) if @due_date
new_milestone.click_create_milestone_button
end
protected
# Return subset of fields for comparing milestones
#
# @return [Hash]
def comparable_milestone
reload! unless api_response
api_response.slice(
:title,
:description,
:state,
:due_date,
:start_date
)
end
end
end
......
......@@ -64,9 +64,9 @@ module QA
JSON.pretty_generate(comparable_label)
end
# protected
protected
# Return subset of fields for comparing groups
# Return subset of fields for comparing labels
#
# @return [Hash]
def comparable_label
......
......@@ -5,6 +5,7 @@ module QA
describe 'Bulk group import' do
let!(:staging?) { Runtime::Scenario.gitlab_address.include?('staging.gitlab.com') }
let(:import_wait_duration) { { max_duration: 300, sleep_interval: 2 } }
let(:admin_api_client) { Runtime::API::Client.as_admin }
let(:user) do
Resource::User.fabricate_via_api! do |usr|
......@@ -14,7 +15,6 @@ module QA
end
let(:api_client) { Runtime::API::Client.new(user: user) }
let(:personal_access_token) { api_client.personal_access_token }
let(:sandbox) do
Resource::Sandbox.fabricate_via_api! do |group|
......@@ -29,22 +29,6 @@ module QA
end
end
let(:subgroup) do
Resource::Group.fabricate_via_api! do |group|
group.api_client = api_client
group.sandbox = source_group
group.path = "subgroup-for-import-#{SecureRandom.hex(4)}"
end
end
let(:imported_subgroup) do
Resource::Group.init do |group|
group.api_client = api_client
group.sandbox = imported_group
group.path = subgroup.path
end
end
let(:imported_group) do
Resource::BulkImportGroup.fabricate_via_api! do |group|
group.api_client = api_client
......@@ -57,33 +41,79 @@ module QA
Runtime::Feature.enable(:top_level_group_creation_enabled) if staging?
sandbox.add_member(user, Resource::Members::AccessLevel::MAINTAINER)
end
Resource::GroupLabel.fabricate_via_api! do |label|
label.api_client = api_client
label.group = source_group
label.title = "source-group-#{SecureRandom.hex(4)}"
context 'with subgroups and labels' do
let(:subgroup) do
Resource::Group.fabricate_via_api! do |group|
group.api_client = api_client
group.sandbox = source_group
group.path = "subgroup-for-import-#{SecureRandom.hex(4)}"
end
end
Resource::GroupLabel.fabricate_via_api! do |label|
label.api_client = api_client
label.group = subgroup
label.title = "subgroup-#{SecureRandom.hex(4)}"
let(:imported_subgroup) do
Resource::Group.init do |group|
group.api_client = api_client
group.sandbox = imported_group
group.path = subgroup.path
end
end
before do
Resource::GroupLabel.fabricate_via_api! do |label|
label.api_client = api_client
label.group = source_group
label.title = "source-group-#{SecureRandom.hex(4)}"
end
Resource::GroupLabel.fabricate_via_api! do |label|
label.api_client = api_client
label.group = subgroup
label.title = "subgroup-#{SecureRandom.hex(4)}"
end
end
it(
'successfully imports groups and labels',
testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1873'
) do
expect { imported_group.import_status }.to eventually_eq('finished').within(import_wait_duration)
aggregate_failures do
expect(imported_group.reload!).to eq(source_group)
expect(imported_group.labels).to include(*source_group.labels)
expect(imported_subgroup.reload!).to eq(subgroup)
expect(imported_subgroup.labels).to include(*subgroup.labels)
end
end
end
it(
'imports group with subgroups and labels',
testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1873'
) do
expect { imported_group.import_status }.to(
eventually_eq('finished').within(max_duration: 300, sleep_interval: 2)
)
context 'with milestones' do
let(:source_milestone) do
Resource::GroupMilestone.fabricate_via_api! do |milestone|
milestone.api_client = api_client
milestone.group = source_group
end
end
before do
source_milestone
end
aggregate_failures do
expect(imported_group.reload!).to eq(source_group)
expect(imported_group.labels).to include(*source_group.labels)
it(
'successfully imports group milestones',
testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/2245'
) do
expect { imported_group.import_status }.to eventually_eq('finished').within(import_wait_duration)
expect(imported_subgroup.reload!).to eq(subgroup)
expect(imported_subgroup.labels).to include(*subgroup.labels)
imported_milestone = imported_group.reload!.milestones.find { |ml| ml.title == source_milestone.title }
aggregate_failures do
expect(imported_milestone).to eq(source_milestone)
expect(imported_milestone.iid).to eq(source_milestone.iid)
expect(imported_milestone.created_at).to eq(source_milestone.created_at)
expect(imported_milestone.updated_at).to eq(source_milestone.updated_at)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment