Commit ab90fe8b authored by Andrejs Cunskis's avatar Andrejs Cunskis

E2E: Group badge migration validation

Fix badge

Override web_url method
parent 2428ecbd
# frozen_string_literal: true
module QA
module Resource
class GroupBadge < Base
attributes :id,
:name,
:link_url,
:image_url,
:group
# API get path
#
# @return [String]
def api_get_path
"/groups/#{CGI.escape(group.full_path)}/badges/#{id}"
end
# API post path
#
# @return [String]
def api_post_path
"/groups/#{CGI.escape(group.full_path)}/badges"
end
# Params for label creation
#
# @return [Hash]
def api_post_body
{
link_url: link_url,
image_url: image_url
}
end
# Override base method as this particular resource does not expose a web_url property
#
# @param [Hash] resource
# @return [String]
def resource_web_url(_resource); end
# Object comparison
#
# @param [QA::Resource::GroupBadge] other
# @return [Boolean]
def ==(other)
other.is_a?(GroupBadge) && comparable_badge == other.comparable_badge
end
# Override inspect for a better rspec failure diff output
#
# @return [String]
def inspect
JSON.pretty_generate(comparable_badge)
end
protected
# Return subset of fields for comparing badges
#
# @return [Hash]
def comparable_badge
reload! unless api_response
api_response.slice(
:name,
:link_url,
:image_url
)
end
end
end
end
...@@ -46,6 +46,22 @@ module QA ...@@ -46,6 +46,22 @@ module QA
end end
end end
# Get group badges
#
# @return [Array<QA::Resource::GroupBadge>]
def badges
parse_body(api_get_from("#{api_get_path}/badges")).map do |badge|
GroupBadge.init do |resource|
resource.api_client = api_client
resource.group = self
resource.id = badge[:id]
resource.name = badge[:name]
resource.link_url = badge[:link_url]
resource.image_url = badge[:image_url]
end
end
end
# API get path # API get path
# #
# @return [String] # @return [String]
......
...@@ -89,7 +89,7 @@ module QA ...@@ -89,7 +89,7 @@ module QA
end end
end end
context 'with milestones' do context 'with milestones and badges' do
let(:source_milestone) do let(:source_milestone) do
Resource::GroupMilestone.fabricate_via_api! do |milestone| Resource::GroupMilestone.fabricate_via_api! do |milestone|
milestone.api_client = api_client milestone.api_client = api_client
...@@ -99,10 +99,17 @@ module QA ...@@ -99,10 +99,17 @@ module QA
before do before do
source_milestone source_milestone
Resource::GroupBadge.fabricate_via_api! do |badge|
badge.api_client = api_client
badge.group = source_group
badge.link_url = "http://example.com/badge"
badge.image_url = "http://shields.io/badge"
end
end end
it( it(
'successfully imports group milestones', 'successfully imports group milestones and badges',
testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/2245' testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/2245'
) do ) do
expect { imported_group.import_status }.to eventually_eq('finished').within(import_wait_duration) expect { imported_group.import_status }.to eventually_eq('finished').within(import_wait_duration)
...@@ -113,6 +120,8 @@ module QA ...@@ -113,6 +120,8 @@ module QA
expect(imported_milestone.iid).to eq(source_milestone.iid) expect(imported_milestone.iid).to eq(source_milestone.iid)
expect(imported_milestone.created_at).to eq(source_milestone.created_at) expect(imported_milestone.created_at).to eq(source_milestone.created_at)
expect(imported_milestone.updated_at).to eq(source_milestone.updated_at) expect(imported_milestone.updated_at).to eq(source_milestone.updated_at)
expect(imported_group.badges).to eq(source_group.badges)
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