diff --git a/spec/controllers/api/v1/comments_controller_spec.rb b/spec/controllers/api/v1/comments_controller_spec.rb index 5d375de..2d5aa04 100644 --- a/spec/controllers/api/v1/comments_controller_spec.rb +++ b/spec/controllers/api/v1/comments_controller_spec.rb @@ -13,7 +13,9 @@ before do post "/api/v1/username/posts/#{post_with_no_media.id}/comment", params: { - body: body + comment: { + body: body + } }, headers: { Authorization: "Token api_key=#{bot.api_key} api_secret=#{bot.api_secret}" } @@ -33,7 +35,9 @@ context 'When creating a comment with no body' do before do post "/api/v1/username/posts/#{post_with_no_media.id}/comment", params: { - body: '' + comment: { + body: '' + } }, headers: { Authorization: "Token api_key=#{bot.api_key} api_secret=#{bot.api_secret}" } @@ -49,27 +53,9 @@ end end - context 'When fetching a comment' do - before do - get "/api/v1/username/posts/#{comment.post_id}/comment/#{comment.id}", headers: { - Authorization: "Token api_key=#{bot.api_key} api_secret=#{bot.api_secret}" - } - end - - it 'returns 200' do - expect(response.status).to eq(200) - end - - it 'returns success message and comment data' do - expect(json['status']).to eq('success') - expect(json['message']).to eq('Comment loaded') - expect(json['data']['body']).to eq(comment.body) - end - end - context 'When deleting another bot comment' do before do - delete "/api/v1/username/posts/#{comment.post_id}/comment/#{comment.id}", headers: { + delete "/api/v1/username/posts/#{comment.commentable_id}/comment/#{comment.id}", headers: { Authorization: "Token api_key=#{bot.api_key} api_secret=#{bot.api_secret}" } end diff --git a/spec/controllers/api/v1/likes_controller_spec.rb b/spec/controllers/api/v1/likes_controller_spec.rb index 15876a2..1f36f27 100644 --- a/spec/controllers/api/v1/likes_controller_spec.rb +++ b/spec/controllers/api/v1/likes_controller_spec.rb @@ -79,4 +79,47 @@ expect(json['message']).to eq('Cannot unlike') end end + + let(:comment) { create_comment } + + context 'When liking a comment' do + before do + post "/api/v1/username/posts/#{post_with_no_media.id}/comment", params: { + comment: { + body: 'Comment' + } + }, headers: { + Authorization: "Token api_key=#{bot.api_key} api_secret=#{bot.api_secret}" + } + post "/api/v1/username/posts/#{post_with_no_media.id}/comments/#{comment.id}/like", headers: { + Authorization: "Token api_key=#{bot.api_key} api_secret=#{bot.api_secret}" + } + end + + it 'returns 201' do + expect(response.status).to eq(201) + end + end + + context 'When unliking a comment' do + before do + post "/api/v1/username/posts/#{post_with_no_media.id}/comment", params: { + comment: { + body: 'Comment' + } + }, headers: { + Authorization: "Token api_key=#{bot.api_key} api_secret=#{bot.api_secret}" + } + post "/api/v1/username/posts/#{post_with_no_media.id}/comments/#{comment.id}/like", headers: { + Authorization: "Token api_key=#{bot.api_key} api_secret=#{bot.api_secret}" + } + delete "/api/v1/username/posts/#{post_with_no_media.id}/comments/#{comment.id}/like", headers: { + Authorization: "Token api_key=#{bot.api_key} api_secret=#{bot.api_secret}" + } + end + + it 'returns 202' do + expect(response.status).to eq(202) + end + end end diff --git a/spec/factories/bot.rb b/spec/factories/bot.rb index 6f217b0..126751d 100644 --- a/spec/factories/bot.rb +++ b/spec/factories/bot.rb @@ -2,8 +2,8 @@ FactoryBot.define do factory :bot do - name { Faker::Name.name[4..32] } - username { SecureRandom.hex(10) } + name { Faker::Name.name[0..32] } + username { SecureRandom.hex(10) } bio { Faker::Book.title[1..512] } developer_id { FactoryBot.create(:developer).id } api_key { SecureRandom.hex(16) } diff --git a/spec/factories/developer.rb b/spec/factories/developer.rb index cde15cb..ea5df5d 100644 --- a/spec/factories/developer.rb +++ b/spec/factories/developer.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :developer do - name { Faker::Name.name[4..32] } + name { Faker::Name.name[0..32] } username { SecureRandom.hex(10) } email { Faker::Internet.unique.email[0..32] } end diff --git a/spec/factories/post.rb b/spec/factories/post.rb index 4ae8bf1..c98544c 100644 --- a/spec/factories/post.rb +++ b/spec/factories/post.rb @@ -3,6 +3,6 @@ FactoryBot.define do factory :post do body { Faker::Games::Minecraft.achievement[0..32] } - bot_id { FactoryBot.create(:bot).id[0..32] } + bot_id { FactoryBot.create(:bot).id } end end diff --git a/spec/support/bot_helpers.rb b/spec/support/bot_helpers.rb index 94dd79c..500c3b6 100644 --- a/spec/support/bot_helpers.rb +++ b/spec/support/bot_helpers.rb @@ -6,7 +6,7 @@ module BotHelpers def create_bot FactoryBot.create(:bot, - name: Faker::Name.name[4..32], + name: Faker::Name.name[0..32], username: SecureRandom.hex(10), api_key: SecureRandom.hex(16), api_secret: SecureRandom.hex(16), diff --git a/spec/support/comment_helpers.rb b/spec/support/comment_helpers.rb index 14e8f16..e62b6d9 100644 --- a/spec/support/comment_helpers.rb +++ b/spec/support/comment_helpers.rb @@ -7,7 +7,9 @@ module CommentHelpers def create_comment FactoryBot.create(:comment, body: Faker::Games::Fallout.quote, - post_id: FactoryBot.create(:post).id, - bot_id: FactoryBot.create(:bot).id) + commentable_id: FactoryBot.create(:post).id, + commentable_type: 'Post', + commenter_id: FactoryBot.create(:bot).id, + commenter_type: 'Bot') end end