Commit f3d1ede57a2542c090802763696c3614d62e93ed
1 parent
06a73d67
Exists in
staging
and in
41 other branches
Add tests for json api pagination
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>
Showing
2 changed files
with
43 additions
and
0 deletions
Show diff stats
test/unit/api/articles_test.rb
| ... | ... | @@ -82,6 +82,28 @@ class ArticlesTest < ActiveSupport::TestCase |
| 82 | 82 | assert_not_includes json['articles'].map {|a| a['id']}, child.id |
| 83 | 83 | end |
| 84 | 84 | |
| 85 | + should 'list articles with pagination' do | |
| 86 | + Article.destroy_all | |
| 87 | + article_one = fast_create(Article, :profile_id => user.person.id, :name => "Another thing") | |
| 88 | + article_two = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | |
| 89 | + | |
| 90 | + params[:page] = 1 | |
| 91 | + params[:per_page] = 1 | |
| 92 | + get "/api/v1/articles/?#{params.to_query}" | |
| 93 | + json_page_one = JSON.parse(last_response.body) | |
| 94 | + | |
| 95 | + params[:page] = 2 | |
| 96 | + params[:per_page] = 1 | |
| 97 | + get "/api/v1/articles/?#{params.to_query}" | |
| 98 | + json_page_two = JSON.parse(last_response.body) | |
| 99 | + | |
| 100 | + assert_includes json_page_one["articles"].map { |a| a["id"] }, article_two.id | |
| 101 | + assert_not_includes json_page_one["articles"].map { |a| a["id"] }, article_one.id | |
| 102 | + | |
| 103 | + assert_includes json_page_two["articles"].map { |a| a["id"] }, article_one.id | |
| 104 | + assert_not_includes json_page_two["articles"].map { |a| a["id"] }, article_two.id | |
| 105 | + end | |
| 106 | + | |
| 85 | 107 | ############################# |
| 86 | 108 | # Profile Articles # |
| 87 | 109 | ############################# | ... | ... |
test/unit/api/communities_test.rb
| ... | ... | @@ -120,4 +120,25 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 120 | 120 | assert_equivalent [c1.id], json['communities'].map {|c| c['id']} |
| 121 | 121 | end |
| 122 | 122 | |
| 123 | + should 'list communities with pagination' do | |
| 124 | + community1 = fast_create(Community, :public_profile => true) | |
| 125 | + community2 = fast_create(Community) | |
| 126 | + | |
| 127 | + params[:page] = 2 | |
| 128 | + params[:per_page] = 1 | |
| 129 | + get "/api/v1/communities?#{params.to_query}" | |
| 130 | + json_page_two = JSON.parse(last_response.body) | |
| 131 | + | |
| 132 | + params[:page] = 1 | |
| 133 | + params[:per_page] = 1 | |
| 134 | + get "/api/v1/communities?#{params.to_query}" | |
| 135 | + json_page_one = JSON.parse(last_response.body) | |
| 136 | + | |
| 137 | + | |
| 138 | + assert_includes json_page_one["communities"].map { |a| a["id"] }, community1.id | |
| 139 | + assert_not_includes json_page_one["communities"].map { |a| a["id"] }, community2.id | |
| 140 | + | |
| 141 | + assert_includes json_page_two["communities"].map { |a| a["id"] }, community2.id | |
| 142 | + assert_not_includes json_page_two["communities"].map { |a| a["id"] }, community1.id | |
| 143 | + end | |
| 123 | 144 | end | ... | ... |