Skip to content

Commit eddf27d

Browse files
committed
Adds urns for page link type improve some tests
1 parent e4664da commit eddf27d

4 files changed

Lines changed: 45 additions & 9 deletions

File tree

modules/wikis/lib/api/v3/page_links/page_link_collection_representer.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ module V3
3333
module PageLinks
3434
class PageLinkCollectionRepresenter < Decorators::OffsetPaginatedCollection
3535
property :count, getter: ->(*) { count(:id) }
36+
37+
def _type = "WikiPageLinkCollection"
3638
end
3739
end
3840
end

modules/wikis/lib/api/v3/page_links/page_link_representer.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,22 @@
3131
module API
3232
module V3
3333
module PageLinks
34+
URN_INLINE_PAGE_LINK = "#{URN_PREFIX}wikiPageLinks:Inline".freeze
35+
URN_RELATION_PAGE_LINK = "#{::API::V3::URN_PREFIX}wikiPageLinks:Relation".freeze
36+
37+
URN_PAGE_LINK_TYPE = {
38+
"Wikis::RelationPageLink" => URN_RELATION_PAGE_LINK,
39+
"Wikis::InlinePageLink" => URN_INLINE_PAGE_LINK
40+
}.freeze
41+
3442
class PageLinkRepresenter < Decorators::Single
3543
include Decorators::LinkedResource
3644
include Decorators::DateProperty
3745
include Caching::CachedRepresenter
3846

3947
property :id
4048
property :identifier
49+
property :wiki_page_link_type, exec_context: :decorator
4150

4251
date_time_property :created_at
4352
date_time_property :updated_at
@@ -71,7 +80,9 @@ class PageLinkRepresenter < Decorators::Single
7180
representer: ::API::V3::WorkPackages::WorkPackageRepresenter,
7281
skip_render: ->(*) { represented.linkable_id.nil? || represented.linkable_type != "WorkPackage" }
7382

74-
def _type = represented.class.name.demodulize
83+
def _type = "WikiPageLink"
84+
85+
def wiki_page_link_type = URN_PAGE_LINK_TYPE[represented.class.name]
7586

7687
private
7788

modules/wikis/spec/lib/api/v3/page_links/page_link_representer_spec.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,34 @@ module PageLinks
113113
end
114114

115115
describe "properties" do
116+
describe "wiki_page_link_type" do
117+
context "when InlinePageLink" do
118+
let(:represented) { inline_page_link }
119+
120+
it_behaves_like "property", :wikiPageLinkType do
121+
let(:value) { URN_INLINE_PAGE_LINK }
122+
end
123+
end
124+
125+
context "when RelationPageLink" do
126+
it_behaves_like "property", :wikiPageLinkType do
127+
let(:value) { URN_RELATION_PAGE_LINK }
128+
end
129+
end
130+
end
131+
116132
describe "_type" do
117133
context "when InlinePageLink" do
118134
let(:represented) { inline_page_link }
119135

120136
it_behaves_like "property", :_type do
121-
let(:value) { "InlinePageLink" }
137+
let(:value) { "WikiPageLink" }
122138
end
123139
end
124140

125141
context "when RelationPageLink" do
126142
it_behaves_like "property", :_type do
127-
let(:value) { "RelationPageLink" }
143+
let(:value) { "WikiPageLink" }
128144
end
129145
end
130146
end

modules/wikis/spec/requests/api/v3/page_links/page_links_api_spec.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,24 @@
3535

3636
let(:work_package) { create(:work_package) }
3737
let(:internal_wiki) { create(:internal_wiki_provider) }
38+
let(:xwiki_provider) { create(:xwiki_provider) }
3839

3940
let(:project) { work_package.project }
4041

4142
let(:user) { create(:user, member_with_permissions: { project => %i(view_work_packages view_wiki_page_links) }) }
4243

43-
let(:relation_page_links) { create_list(:relation_wiki_page_link, 3, provider: internal_wiki, linkable: work_package) }
44+
let(:relation_page_links) { create_list(:relation_wiki_page_link, 3, provider: xwiki_provider, linkable: work_package) }
45+
let(:inline_page_links) { create_list(:inline_wiki_page_link, 3, provider: internal_wiki, linkable: work_package) }
46+
47+
let(:unrelated_page_links) do
48+
create_list(:inline_wiki_page_link, 3, provider: internal_wiki, linkable: create(:work_package, project: project))
49+
end
4450

4551
before do
4652
login_as user
4753
relation_page_links
54+
inline_page_links
55+
unrelated_page_links
4856
end
4957

5058
describe "GET /api/v3/work_packages/:id/wiki_page_links" do
@@ -53,21 +61,20 @@
5361
context "with all preconditions met (happy path)" do
5462
before { get path }
5563

56-
it_behaves_like "API V3 collection response", 3, 3, "RelationPageLink", "Collection" do
57-
let(:elements) { relation_page_links.reverse }
64+
it_behaves_like "API V3 collection response", 6, 6, "WikiPageLink", "WikiPageLinkCollection" do
65+
let(:elements) { Wikis::PageLink.where(linkable: work_package).order(id: :desc).all }
5866
end
5967
end
6068

6169
context "when filtered by provider" do
6270
let(:filter) { [{ provider: { operator: "=", values: [internal_wiki.universal_identifier] } }] }
6371

6472
before do
65-
create_list(:relation_wiki_page_link, 3, provider: create(:xwiki_provider), linkable: work_package)
6673
get "#{path}?filters=#{CGI.escape(filter.to_json)}"
6774
end
6875

69-
it_behaves_like "API V3 collection response", 3, 3, "RelationPageLink", "Collection" do
70-
let(:elements) { relation_page_links.reverse }
76+
it_behaves_like "API V3 collection response", 3, 3, "WikiPageLink", "WikiPageLinkCollection" do
77+
let(:elements) { Wikis::PageLink.where(linkable: work_package, provider: internal_wiki).order(id: :desc).all }
7178
end
7279
end
7380
end

0 commit comments

Comments
 (0)