API: return mentioned_people for comments
This commit is contained in:
parent
08d4f87a2d
commit
04d0d6dccb
4 changed files with 52 additions and 18 deletions
|
|
@ -1,27 +1,28 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CommentPresenter < BasePresenter
|
||||
def initialize(comment)
|
||||
@comment = comment
|
||||
end
|
||||
|
||||
def as_json(opts={})
|
||||
{
|
||||
id: @comment.id,
|
||||
guid: @comment.guid,
|
||||
text: @comment.message.plain_text_for_json,
|
||||
author: @comment.author.as_api_response(:backbone),
|
||||
created_at: @comment.created_at,
|
||||
mentioned_people: @comment.mentioned_people.as_api_response(:backbone)
|
||||
id: id,
|
||||
guid: guid,
|
||||
text: message.plain_text_for_json,
|
||||
author: author.as_api_response(:backbone),
|
||||
created_at: created_at,
|
||||
mentioned_people: mentioned_people.as_api_response(:backbone)
|
||||
}
|
||||
end
|
||||
|
||||
def as_api_response
|
||||
{
|
||||
guid: @comment.guid,
|
||||
body: @comment.message.plain_text_for_json,
|
||||
author: PersonPresenter.new(@comment.author).as_api_json,
|
||||
created_at: @comment.created_at
|
||||
guid: guid,
|
||||
body: message.plain_text_for_json,
|
||||
author: PersonPresenter.new(author).as_api_json,
|
||||
created_at: created_at,
|
||||
mentioned_people: build_mentioned_people_json
|
||||
}
|
||||
end
|
||||
|
||||
def build_mentioned_people_json
|
||||
mentioned_people.map {|m| PersonPresenter.new(m).as_api_json }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
"oneOf": [
|
||||
{"$ref": "https://diaspora.software/api/v1/schema.json#/definitions/aspects"},
|
||||
{"$ref": "https://diaspora.software/api/v1/schema.json#/definitions/aspect"},
|
||||
{"$ref": "https://diaspora.software/api/v1/schema.json#/definitions/comments_or_messages"},
|
||||
{"$ref": "https://diaspora.software/api/v1/schema.json#/definitions/comments"},
|
||||
{"$ref": "https://diaspora.software/api/v1/schema.json#/definitions/messages"},
|
||||
{"$ref": "https://diaspora.software/api/v1/schema.json#/definitions/users"},
|
||||
{"$ref": "https://diaspora.software/api/v1/schema.json#/definitions/conversations"},
|
||||
{"$ref": "https://diaspora.software/api/v1/schema.json#/definitions/conversation"},
|
||||
|
|
@ -87,7 +88,26 @@
|
|||
"additionalProperties": false
|
||||
},
|
||||
|
||||
"comments_or_messages": {
|
||||
"comments": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"guid": { "$ref": "https://diaspora.software/api/v1/schema.json#/definitions/guid" },
|
||||
"created_at": { "$ref": "https://diaspora.software/api/v1/schema.json#/definitions/timestamp" },
|
||||
"author": { "$ref": "https://diaspora.software/api/v1/schema.json#/definitions/short_profile" },
|
||||
"body": { "type": "string" },
|
||||
"mentioned_people": {
|
||||
"type": "array",
|
||||
"items": { "$ref": "https://diaspora.software/api/v1/schema.json#/definitions/short_profile" }
|
||||
}
|
||||
},
|
||||
"required": ["guid", "created_at", "author", "body"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
|
||||
"messages": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
|
|
|
|||
|
|
@ -72,6 +72,19 @@ describe Api::V1::CommentsController do
|
|||
comment = response_body(response)
|
||||
confirm_comment_format(comment, auth.user, comment_text)
|
||||
end
|
||||
|
||||
it "creates with mentions" do
|
||||
comment_text = "hello @{#{alice.diaspora_handle}} from Bob!"
|
||||
post(
|
||||
api_v1_post_comments_path(post_id: @status.guid),
|
||||
params: {body: comment_text, access_token: access_token}
|
||||
)
|
||||
expect(response.status).to eq(201)
|
||||
comment = response_body(response)
|
||||
confirm_comment_format(comment, auth.user, comment_text)
|
||||
expect(comment["mentioned_people"].size).to eq(1)
|
||||
expect(comment["mentioned_people"][0]).to include("diaspora_id" => alice.diaspora_handle)
|
||||
end
|
||||
end
|
||||
|
||||
context "wrong post id" do
|
||||
|
|
@ -142,7 +155,7 @@ describe Api::V1::CommentsController do
|
|||
confirm_comment_format(comments[0], auth.user, @comment_text1)
|
||||
confirm_comment_format(comments[1], auth.user, @comment_text2)
|
||||
|
||||
expect(comments.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/comments_or_messages")
|
||||
expect(comments.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/comments")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ describe Api::V1::MessagesController do
|
|||
messages = response_body_data(response)
|
||||
expect(messages.length).to eq(1)
|
||||
|
||||
expect(messages.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/comments_or_messages")
|
||||
expect(messages.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/messages")
|
||||
|
||||
confirm_message_format(messages[0], "first message", auth.user)
|
||||
conversation = get_conversation(@conversation_guid)
|
||||
|
|
|
|||
Loading…
Reference in a new issue