Commit 81e733e2 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'add-members-url-to-billmembapi' into 'master'

Add Source Members Url to Billable Memberships API

See merge request gitlab-org/gitlab!59312
parents eb3e98e8 2abb48ad
...@@ -4,11 +4,21 @@ module EE ...@@ -4,11 +4,21 @@ module EE
module API module API
module Entities module Entities
class BillableMembership < Grape::Entity class BillableMembership < Grape::Entity
include ::Gitlab::Routing
expose :id expose :id
expose :source_id expose :source_id
expose :source_full_name do |member| expose :source_full_name do |member|
member.source.full_name member.source.full_name
end end
expose :source_members_url do |member|
case member.source_type
when 'Namespace'
group_group_members_url(member.source)
when 'Project'
project_project_members_url(member.source)
end
end
expose :created_at expose :created_at
expose :expires_at expose :expires_at
expose :access_level do expose :access_level do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::EE::API::Entities::BillableMembership do
describe '#as_json' do
it 'returns source_members_url for a group' do
membership = create(:group_member)
group_members_url = Gitlab::Routing.url_helpers.group_group_members_url(membership.source)
expect(described_class.new(membership).as_json[:source_members_url]).to eq(group_members_url)
end
it 'returns source_members_url for a project' do
membership = create(:project_member)
project_members_url = Gitlab::Routing.url_helpers.project_project_members_url(membership.source)
expect(described_class.new(membership).as_json[:source_members_url]).to eq(project_members_url)
end
end
end
...@@ -522,6 +522,7 @@ RSpec.describe API::Members do ...@@ -522,6 +522,7 @@ RSpec.describe API::Members do
'id' => membership.id, 'id' => membership.id,
'source_id' => group.id, 'source_id' => group.id,
'source_full_name' => group.full_name, 'source_full_name' => group.full_name,
'source_members_url' => group_group_members_url(group),
'created_at' => membership.created_at.as_json, 'created_at' => membership.created_at.as_json,
'expires_at' => nil, 'expires_at' => nil,
'access_level' => { 'access_level' => {
......
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