From edfb6039655727884572c979b03156f31874a52d Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Fri, 10 Nov 2023 22:49:05 +0100 Subject: [PATCH] Fix API v1 schema for likes on comments and add test --- lib/schemas/api_v1.json | 8 ++++--- .../api/comments_controller_spec.rb | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/schemas/api_v1.json b/lib/schemas/api_v1.json index d3650856b..d46eeea9e 100644 --- a/lib/schemas/api_v1.json +++ b/lib/schemas/api_v1.json @@ -105,9 +105,11 @@ "interactions": { "type": "object", "properties" : { - "likes" : { "$ref": "https://diaspora.software/api/v1/schema.json#/definitions/likes"}, - "likes_count" : { "type": "integer"} - } + "liked" : { "type": "boolean" }, + "likes_count" : { "type": "integer" } + }, + "required": ["liked", "likes_count"], + "additionalProperties": false } }, "required": ["guid", "created_at", "author", "body", "reported", "interactions"], diff --git a/spec/integration/api/comments_controller_spec.rb b/spec/integration/api/comments_controller_spec.rb index 3c90195c9..3db9823c2 100644 --- a/spec/integration/api/comments_controller_spec.rb +++ b/spec/integration/api/comments_controller_spec.rb @@ -159,6 +159,23 @@ describe Api::V1::CommentsController do expect_to_match_json_schema(comments.to_json, "#/definitions/comments") end + it "retrieves own like state" do + like_service.create_for_comment(@comment1.id) + + get( + api_v1_post_comments_path(post_id: @status.guid), + params: {access_token: access_token} + ) + expect(response.status).to eq(200) + comments = response_body(response) + expect(comments[0]["interactions"]["liked"]).to eq(true) + expect(comments[0]["interactions"]["likes_count"]).to eq(1) + expect(comments[1]["interactions"]["liked"]).to eq(false) + expect(comments[1]["interactions"]["likes_count"]).to eq(0) + + expect_to_match_json_schema(comments.to_json, "#/definitions/comments") + end + it "returns reported status of a comment" do auth_minimum_scopes.user.reports.create!(item: @comment1, text: "Meh!") get( @@ -443,6 +460,10 @@ describe Api::V1::CommentsController do CommentService.new(user) end + def like_service(user=auth.user) + LikeService.new(user) + end + def response_body(response) JSON.parse(response.body) end