API: Add reading_time_minutes to /api/articles/me (#14318)

This commit is contained in:
rhymes 2021-07-26 17:47:50 +02:00 committed by GitHub
parent 47543f6da8
commit 0d58de830b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View file

@ -28,7 +28,7 @@ module Api
id user_id organization_id
title description main_image published published_at cached_tag_list
slug path canonical_url comments_count public_reactions_count
page_views_count crossposted_at body_markdown updated_at
page_views_count crossposted_at body_markdown updated_at reading_time
].freeze
private_constant :ME_ATTRIBUTES_FOR_SERIALIZATION

View file

@ -12,6 +12,7 @@ json.array! @articles do |article|
json.cover_image cloud_cover_url(article.main_image)
json.tag_list article.cached_tag_list_array
json.canonical_url article.processed_canonical_url
json.reading_time_minutes article.reading_time
json.partial! "api/v0/shared/user", user: article.user

View file

@ -513,6 +513,22 @@ RSpec.describe "Api::V0::Articles", type: :request do
expect(response.parsed_body.length).to eq(1)
end
it "has correct keys in the response" do
article = create(:article, user: user)
article.update_columns(organization_id: organization.id)
get me_api_articles_path, params: { access_token: access_token.token }
keys = %w[
type_of id title description published published_at slug path url
comments_count public_reactions_count page_views_count
published_timestamp body_markdown positive_reactions_count cover_image
tag_list canonical_url reading_time_minutes user organization flare_tag
]
expect(response.parsed_body.first.keys).to match_array(keys)
end
it "only includes published articles by default" do
create(:article, published: false, published_at: nil, user: user)
get me_api_articles_path, params: { access_token: access_token.token }
@ -549,6 +565,13 @@ RSpec.describe "Api::V0::Articles", type: :request do
expected_order = response.parsed_body.map { |resp| resp["published"] }
expect(expected_order).to eq([false, true])
end
it "correctly returns reading time in minutes" do
create(:article, user: user)
get me_api_articles_path, params: { access_token: access_token.token }
expect(response.parsed_body.first["reading_time_minutes"]).to eq(article.reading_time)
end
end
end