diff --git a/app/controllers/api/v0/comments_controller.rb b/app/controllers/api/v0/comments_controller.rb index 264cd41d4..1cf85c150 100644 --- a/app/controllers/api/v0/comments_controller.rb +++ b/app/controllers/api/v0/comments_controller.rb @@ -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 diff --git a/app/views/api/v0/comments/_comment.json.jbuilder b/app/views/api/v0/comments/_comment.json.jbuilder index 025ab985f..d25ff827f 100644 --- a/app/views/api/v0/comments/_comment.json.jbuilder +++ b/app/views/api/v0/comments/_comment.json.jbuilder @@ -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 "

#{Comment::TITLE_DELETED}

" diff --git a/docs/api_v0.yml b/docs/api_v0.yml index 63f2dbc54..3db0c4084 100644 --- a/docs/api_v0.yml +++ b/docs/api_v0.yml @@ -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: | @@ -1221,6 +1226,7 @@ components: children: [] - type_of: comment id_code: m357 + created_at: 2020-07-02T17:19:40Z body_html: | @@ -1240,6 +1246,7 @@ components: children: - type_of: comment id_code: m35m + created_at: 2020-08-01T11:59:40Z body_html: | @@ -1310,6 +1317,7 @@ components: value: type_of: comment id_code: m357 + created_at: 2020-08-02T17:19:40Z body_html: | @@ -1329,6 +1337,7 @@ components: children: - type_of: comment id_code: m35m + created_at: 2020-07-02T17:19:40Z body_html: | diff --git a/spec/requests/api/v0/comments_spec.rb b/spec/requests/api/v0/comments_spec.rb index 6e63ba8fe..0cc440145 100644 --- a/spec/requests/api/v0/comments_spec.rb +++ b/spec/requests/api/v0/comments_spec.rb @@ -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)