[deploy] API: add created_at datetime to comments (#9829)

* added created_at to comments in api response

* added test to ensure a date is returned for comment

* fix offenses in test

* updated docs to include addition of created_at to comment api response
This commit is contained in:
jkrsn98 2020-08-17 20:10:24 -04:00 committed by GitHub
parent 5342602298
commit dbdc6ead38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 1 deletions

View file

@ -4,7 +4,7 @@ module Api
before_action :set_cache_control_headers, only: %i[index show]
ATTRIBUTES_FOR_SERIALIZATION = %i[
id processed_html user_id ancestry deleted hidden_by_commentable_user
id processed_html user_id ancestry deleted hidden_by_commentable_user created_at
].freeze
private_constant :ATTRIBUTES_FOR_SERIALIZATION

View file

@ -1,5 +1,6 @@
json.type_of "comment"
json.id_code comment.id_code_generated
json.created_at utc_iso_timestamp(comment.created_at)
if comment.deleted?
json.body_html "<p>#{Comment::TITLE_DELETED}</p>"

View file

@ -607,6 +607,7 @@ components:
required:
- type_of
- id_code
- created_at
- body_html
- user
- children
@ -615,6 +616,9 @@ components:
type: string
id_code:
type: string
created_at:
type: string
format: date-time
body_html:
description: HTML formatted comment
type: string
@ -1204,6 +1208,7 @@ components:
value:
- type_of: comment
id_code: m3m0
created_at: 2020-07-01T17:59:43Z
body_html: |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
@ -1221,6 +1226,7 @@ components:
children: []
- type_of: comment
id_code: m357
created_at: 2020-07-02T17:19:40Z
body_html: |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
@ -1240,6 +1246,7 @@ components:
children:
- type_of: comment
id_code: m35m
created_at: 2020-08-01T11:59:40Z
body_html: |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
@ -1310,6 +1317,7 @@ components:
value:
type_of: comment
id_code: m357
created_at: 2020-08-02T17:19:40Z
body_html: |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
@ -1329,6 +1337,7 @@ components:
children:
- type_of: comment
id_code: m35m
created_at: 2020-07-02T17:19:40Z
body_html: |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>

View file

@ -97,6 +97,13 @@ RSpec.describe "Api::V0::Comments", type: :request do
expect(response.headers["surrogate-key"].split.to_set).to eq(expected_key)
end
it "returns date created" do
get api_comments_path(a_id: article.id)
expect(find_root_comment(response)).to include(
"created_at" => article.created_at.utc.iso8601,
)
end
context "when a comment is deleted" do
before do
child_comment.update(deleted: true)
@ -166,6 +173,7 @@ RSpec.describe "Api::V0::Comments", type: :request do
get api_comments_path(p_id: "asdfghjkl")
expect(response).to have_http_status(:not_found)
end
it "returns comment if good podcast episode id" do
get api_comments_path(p_id: podcast_episode.id)
expect(response).to have_http_status(:ok)