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
:due_date_is_fixed,
:due_date_fixed,
:confidential,
:author
:author,
:start_date,
:due_date,
:start_date_from_milestones,
:due_date_from_milestones
attribute :group do
QA::Resource::Group.fabricate!
......
......@@ -20,6 +20,10 @@ module QA
@description = "My awesome project milestone."
end
def api_delete_path
"/projects/#{project.id}/milestones/#{id}"
end
def api_get_path
"/projects/#{project.id}/milestones/#{id}"
end
......
......@@ -6,151 +6,140 @@ module QA
RSpec.describe 'Plan' do
# 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
before(:context) do
@api_client = Runtime::API::Client.new(:gitlab)
@group_id = Resource::Group.fabricate_via_api!.id
@project_id = create_project
@milestone_start_date = (Date.today.to_date + 100).strftime("%Y-%m-%d")
@milestone_due_date = (Date.today.to_date + 120).strftime("%Y-%m-%d")
@fixed_start_date = Date.today.to_date.strftime("%Y-%m-%d")
@fixed_due_date = (Date.today.to_date + 90).strftime("%Y-%m-%d")
let(:milestone_start_date) { (Date.today.to_date + 100).strftime("%Y-%m-%d") }
let(:milestone_due_date) { (Date.today.to_date + 120).strftime("%Y-%m-%d") }
let(:fixed_start_date) { Date.today.to_date.strftime("%Y-%m-%d") }
let(:fixed_due_date) { (Date.today.to_date + 90).strftime("%Y-%m-%d") }
let(:api_client) { Runtime::API::Client.new(:gitlab) }
let(:group) do
Resource::Group.fabricate_via_api! do |group|
group.path = "epic-milestone-group-#{SecureRandom.hex(8)}"
end
end
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = "epic-milestone-project-#{SecureRandom.hex(8)}"
project.group = group
end
end
it 'changes epic dates when updating milestones', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1480' do
epic_iid, milestone_id = create_epic_issue_milestone
milestone_start_date = Date.today.to_date.strftime("%Y-%m-%d")
milestone_due_date = (Date.today.to_date + 30).strftime("%Y-%m-%d")
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
request = create_request("/projects/#{@project_id}/milestones/#{milestone_id}")
put request.url, start_date: milestone_start_date, due_date: milestone_due_date
request = create_request("/projects/#{project.id}/milestones/#{milestone.id}")
put request.url, start_date: new_milestone_start_date, due_date: new_milestone_due_date
expect_status(200)
# Get Epic Details
request = create_request("/groups/#{@group_id}/epics/#{epic_iid}")
get request.url
expect_status(200)
epic.reload!
expect_json('start_date_from_milestones', milestone_start_date)
expect_json('due_date_from_milestones', milestone_due_date)
expect_json('start_date', milestone_start_date)
expect_json('due_date', milestone_due_date)
expect(epic.start_date_from_milestones).to eq(new_milestone_start_date)
expect(epic.due_date_from_milestones).to eq(new_milestone_due_date)
expect(epic.start_date).to eq(new_milestone_start_date)
expect(epic.due_date).to eq(new_milestone_due_date)
end
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]
milestone_start_date = Date.today.to_date.strftime("%Y-%m-%d")
milestone_due_date = (Date.today.to_date + 150).strftime("%Y-%m-%d")
epic = create_epic_issue_milestone[0]
new_milestone_start_date = Date.today.to_date.strftime("%Y-%m-%d")
new_milestone_due_date = (Date.today.to_date + 150).strftime("%Y-%m-%d")
# Add another Issue and milestone
second_milestone_id = create_milestone(milestone_start_date, milestone_due_date)
second_issue_id = create_issue(second_milestone_id)
request = create_request("/groups/#{@group_id}/epics/#{epic_iid}/issues/#{second_issue_id}")
post request.url
expect_status(201)
second_milestone = create_milestone(new_milestone_start_date, new_milestone_due_date)
second_issue = create_issue(second_milestone)
add_issue_to_epic(epic, second_issue)
# and check milestone dates
request = create_request("/groups/#{@group_id}/epics/#{epic_iid}")
get request.url
expect_status(200)
epic.reload!
expect_json('start_date_from_milestones', milestone_start_date)
expect_json('due_date_from_milestones', milestone_due_date)
expect_json('start_date', milestone_start_date)
expect_json('due_date', milestone_due_date)
expect(epic.start_date_from_milestones).to eq(new_milestone_start_date)
expect(epic.due_date_from_milestones).to eq(new_milestone_due_date)
expect(epic.start_date).to eq(new_milestone_start_date)
expect(epic.due_date).to eq(new_milestone_due_date)
end
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
request = create_request("/groups/#{@group_id}/epics/#{epic_iid}/issues")
request = create_request("/groups/#{group.id}/epics/#{epic.iid}/issues")
get request.url
expect_status(200)
epic_issue_id = json_body[0][:epic_issue_id]
# 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
expect_status(200)
# and check milestone dates
request = create_request("/groups/#{@group_id}/epics/#{epic_iid}")
get request.url
expect_status(200)
epic.reload!
expect_json('start_date_from_milestones', nil)
expect_json('due_date_from_milestones', nil)
expect_json('start_date', nil)
expect_json('due_date', nil)
expect(epic.start_date_from_milestones).to be_nil
expect(epic.due_date_from_milestones).to be_nil
expect(epic.start_date).to be_nil
expect(epic.due_date).to be_nil
end
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
# Delete Milestone
request = create_request("/projects/#{@project_id}/milestones/#{milestone_id}")
delete request.url
expect_status(204)
epic, milestone = create_epic_issue_milestone
# and check milestone dates
request = create_request("/groups/#{@group_id}/epics/#{epic_iid}")
get request.url
expect_status(200)
milestone.remove_via_api!
epic.reload!
expect_json('start_date_from_milestones', nil)
expect_json('due_date_from_milestones', nil)
expect_json('start_date', nil)
expect_json('due_date', nil)
expect(epic.start_date_from_milestones).to be_nil
expect(epic.due_date_from_milestones).to be_nil
expect(epic.start_date).to be_nil
expect(epic.due_date).to be_nil
end
private
def create_epic_issue_milestone
epic_iid = create_epic
milestone_id = create_milestone(@milestone_start_date, @milestone_due_date)
issue_id = create_issue(milestone_id)
add_issue_to_epic(epic_iid, issue_id)
use_epics_milestone_dates(epic_iid)
[epic_iid, milestone_id]
epic = create_epic
milestone = create_milestone(milestone_start_date, milestone_due_date)
issue = create_issue(milestone)
add_issue_to_epic(epic, issue)
use_epics_milestone_dates(epic)
[epic, milestone]
end
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]
def create_issue(milestone)
Resource::Issue.fabricate_via_api! do |issue|
issue.title = 'My Test Issue'
issue.project = project
issue.milestone = milestone
end
def create_issue(milestone_id)
request = create_request("/projects/#{@project_id}/issues")
post request.url, title: 'My Test Issue', milestone_id: milestone_id
expect_status(201)
json_body[:id]
end
def create_milestone(start_date, due_date)
request = create_request("/projects/#{@project_id}/milestones")
post request.url, title: "Test_Milestone_#{SecureRandom.hex(8)}", due_date: due_date, start_date: start_date
expect_status(201)
json_body[:id]
Resource::ProjectMilestone.fabricate_via_api! do |milestone|
milestone.project = project
milestone.start_date = start_date
milestone.due_date = due_date
end
end
def create_epic
request = create_request("/groups/#{@group_id}/epics")
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
expect_status(201)
json_body[:iid]
EE::Resource::Epic.fabricate_via_api! do |epic|
epic.group = group
epic.title = 'My New Epic'
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
def add_issue_to_epic(epic_iid, issue_id)
def add_issue_to_epic(epic, issue)
# 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
expect_status(201)
......@@ -158,18 +147,20 @@ module QA
expect_json('issue.title', 'My Test Issue')
end
def use_epics_milestone_dates(epic_iid)
def use_epics_milestone_dates(epic)
# 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
expect_status(200)
expect_json('start_date_from_milestones', @milestone_start_date)
expect_json('due_date_from_milestones', @milestone_due_date)
expect_json('due_date_fixed', @fixed_due_date)
expect_json('start_date_fixed', @fixed_start_date)
expect_json('start_date', @milestone_start_date)
expect_json('due_date', @milestone_due_date)
epic.reload!
expect(epic.start_date_from_milestones).to eq(milestone_start_date)
expect(epic.due_date_from_milestones).to eq(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
......
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