Commit a9957f4b3d91333b75a245ea46ee1e9baadb27d3
Committed by
Macartur Sousa
1 parent
e462d1d4
Exists in
elasticsearch_api
api: should content type return all text articles
Showing
3 changed files
with
27 additions
and
3 deletions
Show diff stats
app/api/helpers.rb
... | ... | @@ -407,9 +407,11 @@ module Api |
407 | 407 | |
408 | 408 | def parse_content_type(content_type) |
409 | 409 | return nil if content_type.blank? |
410 | - content_type.split(',').map do |content_type| | |
411 | - content_type.camelcase | |
410 | + content_types = content_type.split(',').map do |content_type| | |
411 | + content_type = content_type.camelcase | |
412 | + content_type == 'TextArticle' ? Article.text_article_types : content_type | |
412 | 413 | end |
414 | + content_types.flatten.uniq | |
413 | 415 | end |
414 | 416 | |
415 | 417 | def period(from_date, until_date) | ... | ... |
test/api/articles_test.rb
... | ... | @@ -34,6 +34,17 @@ class ArticlesTest < ActiveSupport::TestCase |
34 | 34 | assert_includes json["articles"].map { |a| a["id"] }, article.id |
35 | 35 | end |
36 | 36 | |
37 | + should 'list all text articles' do | |
38 | + profile = Community.create(identifier: 'my-community', name: 'name-my-community') | |
39 | + a1 = fast_create(TextArticle, :profile_id => profile.id) | |
40 | + a2 = fast_create(TextileArticle, :profile_id => profile.id) | |
41 | + a3 = fast_create(TinyMceArticle, :profile_id => profile.id) | |
42 | + params['content_type']='TextArticle' | |
43 | + get "api/v1/communities/#{profile.id}/articles?#{params.to_query}" | |
44 | + json = JSON.parse(last_response.body) | |
45 | + assert_equal 3, json['articles'].count | |
46 | + end | |
47 | + | |
37 | 48 | should 'get profile homepage' do |
38 | 49 | article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") |
39 | 50 | person.home_page=article |
... | ... | @@ -124,6 +135,17 @@ class ArticlesTest < ActiveSupport::TestCase |
124 | 135 | assert_equivalent [child1.id, child2.id], json["articles"].map { |a| a["id"] } |
125 | 136 | end |
126 | 137 | |
138 | + should 'list all text articles of children' do | |
139 | + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | |
140 | + child1 = fast_create(TextArticle, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing 1") | |
141 | + child2 = fast_create(TextileArticle, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing 2") | |
142 | + child3 = fast_create(TinyMceArticle, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing 3") | |
143 | + get "/api/v1/articles/#{article.id}/children?#{params.to_query}" | |
144 | + json = JSON.parse(last_response.body) | |
145 | + assert_equivalent [child1.id, child2.id, child3.id], json["articles"].map { |a| a["id"] } | |
146 | + end | |
147 | + | |
148 | + | |
127 | 149 | should 'list public article children for not logged in access' do |
128 | 150 | article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") |
129 | 151 | child1 = fast_create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing") | ... | ... |
test/api/helpers_test.rb
... | ... | @@ -99,7 +99,7 @@ class Api::HelpersTest < ActiveSupport::TestCase |
99 | 99 | end |
100 | 100 | |
101 | 101 | should 'parse_content_type return all content types as an array' do |
102 | - assert_equivalent ['TextArticle','TinyMceArticle'], parse_content_type("TextArticle,TinyMceArticle") | |
102 | + assert_equivalent ['TextileArticle','TinyMceArticle'], parse_content_type("TextileArticle,TinyMceArticle") | |
103 | 103 | end |
104 | 104 | |
105 | 105 | should 'find_article return article by id in list passed for user with permission' do | ... | ... |