API: Add reading_time_minutes to /api/articles/me (#14318)
This commit is contained in:
parent
47543f6da8
commit
0d58de830b
3 changed files with 25 additions and 1 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue