Skip to content

Commit

Permalink
Merge 65e000b into 2e7526b
Browse files Browse the repository at this point in the history
  • Loading branch information
jhass committed Feb 3, 2020
2 parents 2e7526b + 65e000b commit 6882463
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 18 deletions.
29 changes: 15 additions & 14 deletions app/presenters/comment_presenter.rb
@@ -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
24 changes: 22 additions & 2 deletions lib/schemas/api_v1.json
Expand Up @@ -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"},
Expand Down Expand Up @@ -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",
Expand Down
15 changes: 14 additions & 1 deletion spec/integration/api/comments_controller_spec.rb
Expand Up @@ -72,6 +72,19 @@
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
Expand Down Expand Up @@ -142,7 +155,7 @@
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

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/api/messages_controller_spec.rb
Expand Up @@ -128,7 +128,7 @@
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)
Expand Down

0 comments on commit 6882463

Please sign in to comment.