Commit b7ee782d authored by Andrejs Cunskis's avatar Andrejs Cunskis

E2E: Add milestone migration validation spec

parent b1ab29f0
...@@ -30,6 +30,22 @@ module QA ...@@ -30,6 +30,22 @@ module QA
end end
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 # API get path
# #
# @return [String] # @return [String]
......
...@@ -3,11 +3,14 @@ ...@@ -3,11 +3,14 @@
module QA module QA
module Resource module Resource
class GroupMilestone < Base class GroupMilestone < Base
attr_writer :start_date, :due_date attributes :id,
:iid,
attribute :id :title,
attribute :title :description,
attribute :description :start_date,
:due_date,
:updated_at,
:created_at
attribute :group do attribute :group do
Group.fabricate_via_api! do |resource| Group.fabricate_via_api! do |resource|
...@@ -20,6 +23,21 @@ module QA ...@@ -20,6 +23,21 @@ module QA
@description = "My awesome group milestone." @description = "My awesome group milestone."
end 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 def api_get_path
"/groups/#{group.id}/milestones/#{id}" "/groups/#{group.id}/milestones/#{id}"
end end
...@@ -38,19 +56,36 @@ module QA ...@@ -38,19 +56,36 @@ module QA
end end
end end
def fabricate! # Object comparison
group.visit! #
# @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) # Override inspect for a better rspec failure diff output
Page::Group::Milestone::Index.perform(&:click_new_milestone_link) #
# @return [String]
def inspect
JSON.pretty_generate(comparable_milestone)
end
Page::Group::Milestone::New.perform do |new_milestone| protected
new_milestone.set_title(@title)
new_milestone.set_description(@description) # Return subset of fields for comparing milestones
new_milestone.set_start_date(@start_date) if @start_date #
new_milestone.set_due_date(@due_date) if @due_date # @return [Hash]
new_milestone.click_create_milestone_button def comparable_milestone
end reload! unless api_response
api_response.slice(
:title,
:description,
:state,
:due_date,
:start_date
)
end end
end end
end end
......
...@@ -64,9 +64,9 @@ module QA ...@@ -64,9 +64,9 @@ module QA
JSON.pretty_generate(comparable_label) JSON.pretty_generate(comparable_label)
end end
# protected protected
# Return subset of fields for comparing groups # Return subset of fields for comparing labels
# #
# @return [Hash] # @return [Hash]
def comparable_label def comparable_label
......
...@@ -5,6 +5,7 @@ module QA ...@@ -5,6 +5,7 @@ module QA
describe 'Bulk group import' do describe 'Bulk group import' do
let!(:staging?) { Runtime::Scenario.gitlab_address.include?('staging.gitlab.com') } 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(:admin_api_client) { Runtime::API::Client.as_admin }
let(:user) do let(:user) do
Resource::User.fabricate_via_api! do |usr| Resource::User.fabricate_via_api! do |usr|
...@@ -14,7 +15,6 @@ module QA ...@@ -14,7 +15,6 @@ module QA
end end
let(:api_client) { Runtime::API::Client.new(user: user) } let(:api_client) { Runtime::API::Client.new(user: user) }
let(:personal_access_token) { api_client.personal_access_token }
let(:sandbox) do let(:sandbox) do
Resource::Sandbox.fabricate_via_api! do |group| Resource::Sandbox.fabricate_via_api! do |group|
...@@ -29,22 +29,6 @@ module QA ...@@ -29,22 +29,6 @@ module QA
end end
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 let(:imported_group) do
Resource::BulkImportGroup.fabricate_via_api! do |group| Resource::BulkImportGroup.fabricate_via_api! do |group|
group.api_client = api_client group.api_client = api_client
...@@ -57,33 +41,79 @@ module QA ...@@ -57,33 +41,79 @@ module QA
Runtime::Feature.enable(:top_level_group_creation_enabled) if staging? Runtime::Feature.enable(:top_level_group_creation_enabled) if staging?
sandbox.add_member(user, Resource::Members::AccessLevel::MAINTAINER) sandbox.add_member(user, Resource::Members::AccessLevel::MAINTAINER)
end
Resource::GroupLabel.fabricate_via_api! do |label| context 'with subgroups and labels' do
label.api_client = api_client let(:subgroup) do
label.group = source_group Resource::Group.fabricate_via_api! do |group|
label.title = "source-group-#{SecureRandom.hex(4)}" group.api_client = api_client
group.sandbox = source_group
group.path = "subgroup-for-import-#{SecureRandom.hex(4)}"
end
end end
Resource::GroupLabel.fabricate_via_api! do |label|
label.api_client = api_client let(:imported_subgroup) do
label.group = subgroup Resource::Group.init do |group|
label.title = "subgroup-#{SecureRandom.hex(4)}" 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
end end
it( context 'with milestones' do
'imports group with subgroups and labels', let(:source_milestone) do
testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1873' Resource::GroupMilestone.fabricate_via_api! do |milestone|
) do milestone.api_client = api_client
expect { imported_group.import_status }.to( milestone.group = source_group
eventually_eq('finished').within(max_duration: 300, sleep_interval: 2) end
) end
before do
source_milestone
end
aggregate_failures do it(
expect(imported_group.reload!).to eq(source_group) 'successfully imports group milestones',
expect(imported_group.labels).to include(*source_group.labels) 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) imported_milestone = imported_group.reload!.milestones.find { |ml| ml.title == source_milestone.title }
expect(imported_subgroup.labels).to include(*subgroup.labels) 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
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