From 336c09e072eb6b12af0cee189a778d06f38e5ca4 Mon Sep 17 00:00:00 2001 From: Tejaswini Chile Date: Wed, 28 Sep 2022 01:05:53 +0530 Subject: [PATCH] fix: Add all articles count to article API (#5497) --- app/views/api/v1/accounts/articles/index.json.jbuilder | 5 +++++ spec/controllers/api/v1/accounts/articles_controller_spec.rb | 2 ++ 2 files changed, 7 insertions(+) diff --git a/app/views/api/v1/accounts/articles/index.json.jbuilder b/app/views/api/v1/accounts/articles/index.json.jbuilder index fef8dc521..906cabae1 100644 --- a/app/views/api/v1/accounts/articles/index.json.jbuilder +++ b/app/views/api/v1/accounts/articles/index.json.jbuilder @@ -5,4 +5,9 @@ end json.meta do json.current_page @current_page json.articles_count @articles_count + json.all_articles_count @articles_count + json.archived_articles_count @articles.archived.size + json.published_count @articles.published.size + json.draft_articles_count @articles.draft.size + json.mine_articles_count @articles.search_by_author(current_user.id).size if current_user.present? end diff --git a/spec/controllers/api/v1/accounts/articles_controller_spec.rb b/spec/controllers/api/v1/accounts/articles_controller_spec.rb index 8e79ba7c3..a34079c69 100644 --- a/spec/controllers/api/v1/accounts/articles_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/articles_controller_spec.rb @@ -195,6 +195,8 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do json_response = JSON.parse(response.body) expect(json_response['payload'].count).to be 1 expect(json_response['meta']['articles_count']).to be 2 + expect(json_response['meta']['all_articles_count']).to be 2 + expect(json_response['meta']['mine_articles_count']).to be 1 end end