Commit 0d360b01 authored by Anastasia McDonald's avatar Anastasia McDonald

Merge branch 'qa-refactor-epic-milestone-e2e' into 'master'

Refactor epic milestone e2e to reduce flakiness

See merge request gitlab-org/gitlab!74647
parents 36e9d9f3 9dd9a9ae
...@@ -15,7 +15,11 @@ module QA ...@@ -15,7 +15,11 @@ module QA
:due_date_is_fixed, :due_date_is_fixed,
:due_date_fixed, :due_date_fixed,
:confidential, :confidential,
:author :author,
:start_date,
:due_date,
:start_date_from_milestones,
:due_date_from_milestones
attribute :group do attribute :group do
QA::Resource::Group.fabricate! QA::Resource::Group.fabricate!
......
...@@ -20,6 +20,10 @@ module QA ...@@ -20,6 +20,10 @@ module QA
@description = "My awesome project milestone." @description = "My awesome project milestone."
end end
def api_delete_path
"/projects/#{project.id}/milestones/#{id}"
end
def api_get_path def api_get_path
"/projects/#{project.id}/milestones/#{id}" "/projects/#{project.id}/milestones/#{id}"
end end
......
...@@ -6,151 +6,140 @@ module QA ...@@ -6,151 +6,140 @@ module QA
RSpec.describe 'Plan' do RSpec.describe 'Plan' do
# TODO: Convert back to reliable once proved to be stable. Related issue: https://gitlab.com/gitlab-org/gitlab/-/issues/219495 # TODO: Convert back to reliable once proved to be stable. Related issue: https://gitlab.com/gitlab-org/gitlab/-/issues/219495
describe 'Epics milestone dates API' do describe 'Epics milestone dates API' do
before(:context) do let(:milestone_start_date) { (Date.today.to_date + 100).strftime("%Y-%m-%d") }
@api_client = Runtime::API::Client.new(:gitlab) let(:milestone_due_date) { (Date.today.to_date + 120).strftime("%Y-%m-%d") }
@group_id = Resource::Group.fabricate_via_api!.id let(:fixed_start_date) { Date.today.to_date.strftime("%Y-%m-%d") }
@project_id = create_project let(:fixed_due_date) { (Date.today.to_date + 90).strftime("%Y-%m-%d") }
@milestone_start_date = (Date.today.to_date + 100).strftime("%Y-%m-%d") let(:api_client) { Runtime::API::Client.new(:gitlab) }
@milestone_due_date = (Date.today.to_date + 120).strftime("%Y-%m-%d")
@fixed_start_date = Date.today.to_date.strftime("%Y-%m-%d") let(:group) do
@fixed_due_date = (Date.today.to_date + 90).strftime("%Y-%m-%d") Resource::Group.fabricate_via_api! do |group|
group.path = "epic-milestone-group-#{SecureRandom.hex(8)}"
end
end end
it 'changes epic dates when updating milestones', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1480' do let(:project) do
epic_iid, milestone_id = create_epic_issue_milestone Resource::Project.fabricate_via_api! do |project|
milestone_start_date = Date.today.to_date.strftime("%Y-%m-%d") project.name = "epic-milestone-project-#{SecureRandom.hex(8)}"
milestone_due_date = (Date.today.to_date + 30).strftime("%Y-%m-%d") project.group = group
end
end
it 'updates epic dates when updating milestones', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1480' do
epic, milestone = create_epic_issue_milestone
new_milestone_start_date = (Date.today.to_date + 20).strftime("%Y-%m-%d")
new_milestone_due_date = (Date.today.to_date + 30).strftime("%Y-%m-%d")
# Update Milestone to different dates and see it reflecting in the epics # Update Milestone to different dates and see it reflecting in the epics
request = create_request("/projects/#{@project_id}/milestones/#{milestone_id}") request = create_request("/projects/#{project.id}/milestones/#{milestone.id}")
put request.url, start_date: milestone_start_date, due_date: milestone_due_date put request.url, start_date: new_milestone_start_date, due_date: new_milestone_due_date
expect_status(200) expect_status(200)
# Get Epic Details epic.reload!
request = create_request("/groups/#{@group_id}/epics/#{epic_iid}")
get request.url
expect_status(200)
expect_json('start_date_from_milestones', milestone_start_date) expect(epic.start_date_from_milestones).to eq(new_milestone_start_date)
expect_json('due_date_from_milestones', milestone_due_date) expect(epic.due_date_from_milestones).to eq(new_milestone_due_date)
expect_json('start_date', milestone_start_date) expect(epic.start_date).to eq(new_milestone_start_date)
expect_json('due_date', milestone_due_date) expect(epic.due_date).to eq(new_milestone_due_date)
end end
it 'updates epic dates when adding another issue', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1483' do it 'updates epic dates when adding another issue', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1483' do
epic_iid = create_epic_issue_milestone[0] epic = create_epic_issue_milestone[0]
milestone_start_date = Date.today.to_date.strftime("%Y-%m-%d") new_milestone_start_date = Date.today.to_date.strftime("%Y-%m-%d")
milestone_due_date = (Date.today.to_date + 150).strftime("%Y-%m-%d") new_milestone_due_date = (Date.today.to_date + 150).strftime("%Y-%m-%d")
# Add another Issue and milestone # Add another Issue and milestone
second_milestone_id = create_milestone(milestone_start_date, milestone_due_date) second_milestone = create_milestone(new_milestone_start_date, new_milestone_due_date)
second_issue_id = create_issue(second_milestone_id) second_issue = create_issue(second_milestone)
request = create_request("/groups/#{@group_id}/epics/#{epic_iid}/issues/#{second_issue_id}") add_issue_to_epic(epic, second_issue)
post request.url
expect_status(201)
# and check milestone dates epic.reload!
request = create_request("/groups/#{@group_id}/epics/#{epic_iid}")
get request.url
expect_status(200)
expect_json('start_date_from_milestones', milestone_start_date) expect(epic.start_date_from_milestones).to eq(new_milestone_start_date)
expect_json('due_date_from_milestones', milestone_due_date) expect(epic.due_date_from_milestones).to eq(new_milestone_due_date)
expect_json('start_date', milestone_start_date) expect(epic.start_date).to eq(new_milestone_start_date)
expect_json('due_date', milestone_due_date) expect(epic.due_date).to eq(new_milestone_due_date)
end end
it 'updates epic dates when removing issue', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1481' do it 'updates epic dates when removing issue', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1481' do
epic_iid = create_epic_issue_milestone[0] epic = create_epic_issue_milestone[0]
# Get epic_issue_id # Get epic_issue_id
request = create_request("/groups/#{@group_id}/epics/#{epic_iid}/issues") request = create_request("/groups/#{group.id}/epics/#{epic.iid}/issues")
get request.url get request.url
expect_status(200) expect_status(200)
epic_issue_id = json_body[0][:epic_issue_id] epic_issue_id = json_body[0][:epic_issue_id]
# Remove Issue # Remove Issue
request = create_request("/groups/#{@group_id}/epics/#{epic_iid}/issues/#{epic_issue_id}") request = create_request("/groups/#{group.id}/epics/#{epic.iid}/issues/#{epic_issue_id}")
delete request.url delete request.url
expect_status(200) expect_status(200)
# and check milestone dates epic.reload!
request = create_request("/groups/#{@group_id}/epics/#{epic_iid}")
get request.url
expect_status(200)
expect_json('start_date_from_milestones', nil) expect(epic.start_date_from_milestones).to be_nil
expect_json('due_date_from_milestones', nil) expect(epic.due_date_from_milestones).to be_nil
expect_json('start_date', nil) expect(epic.start_date).to be_nil
expect_json('due_date', nil) expect(epic.due_date).to be_nil
end end
it 'updates epic dates when deleting milestones', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1482' do it 'updates epic dates when deleting milestones', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1482' do
epic_iid, milestone_id = create_epic_issue_milestone epic, milestone = create_epic_issue_milestone
# Delete Milestone milestone.remove_via_api!
request = create_request("/projects/#{@project_id}/milestones/#{milestone_id}") epic.reload!
delete request.url
expect_status(204)
# and check milestone dates expect(epic.start_date_from_milestones).to be_nil
request = create_request("/groups/#{@group_id}/epics/#{epic_iid}") expect(epic.due_date_from_milestones).to be_nil
get request.url expect(epic.start_date).to be_nil
expect_status(200) expect(epic.due_date).to be_nil
expect_json('start_date_from_milestones', nil)
expect_json('due_date_from_milestones', nil)
expect_json('start_date', nil)
expect_json('due_date', nil)
end end
private private
def create_epic_issue_milestone def create_epic_issue_milestone
epic_iid = create_epic epic = create_epic
milestone_id = create_milestone(@milestone_start_date, @milestone_due_date) milestone = create_milestone(milestone_start_date, milestone_due_date)
issue_id = create_issue(milestone_id) issue = create_issue(milestone)
add_issue_to_epic(epic_iid, issue_id) add_issue_to_epic(epic, issue)
use_epics_milestone_dates(epic_iid) use_epics_milestone_dates(epic)
[epic_iid, milestone_id] [epic, milestone]
end end
def create_request(api_endpoint) def create_request(api_endpoint)
Runtime::API::Request.new(@api_client, api_endpoint) Runtime::API::Request.new(api_client, api_endpoint)
end
def create_project
project_name = "project_#{SecureRandom.hex(8)}"
create_project_request = create_request('/projects')
post create_project_request.url, path: project_name, name: project_name, namespace_id: @group_id
expect_status(201)
json_body[:id]
end end
def create_issue(milestone_id) def create_issue(milestone)
request = create_request("/projects/#{@project_id}/issues") Resource::Issue.fabricate_via_api! do |issue|
post request.url, title: 'My Test Issue', milestone_id: milestone_id issue.title = 'My Test Issue'
expect_status(201) issue.project = project
json_body[:id] issue.milestone = milestone
end
end end
def create_milestone(start_date, due_date) def create_milestone(start_date, due_date)
request = create_request("/projects/#{@project_id}/milestones") Resource::ProjectMilestone.fabricate_via_api! do |milestone|
post request.url, title: "Test_Milestone_#{SecureRandom.hex(8)}", due_date: due_date, start_date: start_date milestone.project = project
expect_status(201) milestone.start_date = start_date
json_body[:id] milestone.due_date = due_date
end
end end
def create_epic def create_epic
request = create_request("/groups/#{@group_id}/epics") EE::Resource::Epic.fabricate_via_api! do |epic|
post request.url, title: 'My New Epic', due_date_fixed: @fixed_due_date, start_date_fixed: @fixed_start_date, start_date_is_fixed: true, due_date_is_fixed: true epic.group = group
expect_status(201) epic.title = 'My New Epic'
json_body[:iid] epic.due_date_fixed = fixed_due_date
epic.start_date_fixed = fixed_start_date
epic.start_date_is_fixed = true
epic.due_date_is_fixed = true
end
end end
def add_issue_to_epic(epic_iid, issue_id) def add_issue_to_epic(epic, issue)
# Add Issue with milestone to an epic # Add Issue with milestone to an epic
request = create_request("/groups/#{@group_id}/epics/#{epic_iid}/issues/#{issue_id}") request = create_request("/groups/#{group.id}/epics/#{epic.iid}/issues/#{issue.id}")
post request.url post request.url
expect_status(201) expect_status(201)
...@@ -158,18 +147,20 @@ module QA ...@@ -158,18 +147,20 @@ module QA
expect_json('issue.title', 'My Test Issue') expect_json('issue.title', 'My Test Issue')
end end
def use_epics_milestone_dates(epic_iid) def use_epics_milestone_dates(epic)
# Update Epic to use Milestone Dates # Update Epic to use Milestone Dates
request = create_request("/groups/#{@group_id}/epics/#{epic_iid}") request = create_request("/groups/#{group.id}/epics/#{epic.iid}")
put request.url, start_date_is_fixed: false, due_date_is_fixed: false put request.url, start_date_is_fixed: false, due_date_is_fixed: false
expect_status(200) expect_status(200)
expect_json('start_date_from_milestones', @milestone_start_date)
expect_json('due_date_from_milestones', @milestone_due_date) epic.reload!
expect_json('due_date_fixed', @fixed_due_date)
expect_json('start_date_fixed', @fixed_start_date) expect(epic.start_date_from_milestones).to eq(milestone_start_date)
expect_json('start_date', @milestone_start_date) expect(epic.due_date_from_milestones).to eq(milestone_due_date)
expect_json('due_date', @milestone_due_date) expect(epic.start_date_fixed).to eq(fixed_start_date)
expect(epic.due_date_fixed).to eq(fixed_due_date)
expect(epic.start_date).to eq(milestone_start_date)
expect(epic.due_date).to eq(milestone_due_date)
end 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