fix: Update article count in portal admin dashboard (#5647)

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
Tejaswini Chile 2022-10-22 02:13:15 +05:30 committed by GitHub
parent 95cc55d043
commit 782165478b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 157 additions and 94 deletions

View file

@ -194,7 +194,8 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
expect(response).to have_http_status(:success)
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']['articles_count']).to be 1
expect(json_response['meta']['mine_articles_count']).to be 1
end
end

View file

@ -50,6 +50,25 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
expect(response).to have_http_status(:success)
json_response = JSON.parse(response.body)
expect(json_response['name']).to eq portal.name
expect(json_response['meta']['all_articles_count']).to eq 0
end
it 'returns portal articles metadata' do
portal.update(config: { allowed_locales: %w[en es], default_locale: 'en' })
en_cat = create(:category, locale: :en, portal_id: portal.id, slug: 'en-cat')
es_cat = create(:category, locale: :es, portal_id: portal.id, slug: 'es-cat')
create(:article, category_id: en_cat.id, portal_id: portal.id, author_id: agent.id)
create(:article, category_id: en_cat.id, portal_id: portal.id, author_id: admin.id)
create(:article, category_id: es_cat.id, portal_id: portal.id, author_id: agent.id)
get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}?locale=en",
headers: agent.create_new_auth_token
expect(response).to have_http_status(:success)
json_response = JSON.parse(response.body)
expect(json_response['name']).to eq portal.name
expect(json_response['meta']['all_articles_count']).to eq 2
expect(json_response['meta']['mine_articles_count']).to eq 1
end
end
end

View file

@ -126,20 +126,5 @@ RSpec.describe Article, type: :model do
expect(article.slug).to include('the-awesome-article-1')
end
end
context 'with pagination' do
it 'returns paginated articles' do
build_list(:article, 30) do |record, i|
record.category_id = category_2.id
record.title = "title #{i}"
record.portal_id = portal_2.id
record.author_id = user.id
record.save!
end
params = { category_slug: 'category_2' }
records = portal_2.articles.search(params)
expect(records.count).to eq(25)
end
end
end
end