Ensure API responses adhere to documented error format

This commit is contained in:
Jonne Haß 2020-01-29 23:32:33 +01:00
parent 9e762fcc31
commit e8b9a70fbf
31 changed files with 189 additions and 278 deletions

View file

@ -23,7 +23,7 @@ module Api
if aspect
render json: aspect_as_json(aspect, true)
else
render json: I18n.t("api.endpoint_errors.aspects.not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.aspects.not_found")
end
end
@ -33,24 +33,24 @@ module Api
if aspect&.save
render json: aspect_as_json(aspect, true)
else
render json: I18n.t("api.endpoint_errors.aspects.cant_create"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.aspects.cant_create")
end
rescue ActionController::ParameterMissing
render json: I18n.t("api.endpoint_errors.aspects.cant_create"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.aspects.cant_create")
end
def update
aspect = current_user.aspects.where(id: params[:id]).first
if !aspect
render json: I18n.t("api.endpoint_errors.aspects.cant_update"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.aspects.cant_update")
elsif aspect.update!(aspect_params(true))
render json: aspect_as_json(aspect, true)
else
render json: I18n.t("api.endpoint_errors.aspects.cant_update"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.aspects.cant_update")
end
rescue ActionController::ParameterMissing, ActiveRecord::RecordInvalid
render json: I18n.t("api.endpoint_errors.aspects.cant_update"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.aspects.cant_update")
end
def destroy
@ -58,7 +58,7 @@ module Api
if aspect&.destroy
head :no_content
else
render json: I18n.t("api.endpoint_errors.aspects.cant_delete"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.aspects.cant_delete")
end
end

View file

@ -58,6 +58,10 @@ module Api
render json: page[:data]
end
def render_error(code, message)
render json: {code: code, message: message}, status: code
end
def time_pager(query)
Api::Paging::RestPaginatorBuilder.new(query, request).time_pager(params)
end

View file

@ -12,18 +12,18 @@ module Api
end
rescue_from ActiveRecord::RecordNotFound do
render json: I18n.t("api.endpoint_errors.posts.post_not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.posts.post_not_found")
end
rescue_from ActiveRecord::RecordInvalid do
render json: I18n.t("api.endpoint_errors.comments.not_allowed"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.comments.not_allowed")
end
def create
find_post
comment = comment_service.create(params.require(:post_id), params.require(:body))
rescue ActiveRecord::RecordNotFound
render json: I18n.t("api.endpoint_errors.posts.post_not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.posts.post_not_found")
else
render json: comment_as_json(comment), status: :created
end
@ -45,7 +45,7 @@ module Api
head :no_content
end
rescue ActiveRecord::RecordInvalid
render json: I18n.t("api.endpoint_errors.comments.no_delete"), status: :forbidden
render_error 403, I18n.t("api.endpoint_errors.comments.no_delete")
end
def report
@ -64,7 +64,7 @@ module Api
if report.save
head :no_content
else
render json: I18n.t("api.endpoint_errors.comments.duplicate_report"), status: :conflict
render_error 409, I18n.t("api.endpoint_errors.comments.duplicate_report")
end
end
@ -72,10 +72,10 @@ module Api
def comment_and_post_validate(post_guid, comment_guid)
if !comment_exists(comment_guid)
render json: I18n.t("api.endpoint_errors.comments.not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.comments.not_found")
false
elsif !comment_is_for_post(post_guid, comment_guid)
render json: I18n.t("api.endpoint_errors.comments.not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.comments.not_found")
false
else
true

View file

@ -14,7 +14,7 @@ module Api
end
rescue_from ActiveRecord::RecordNotFound do
render json: I18n.t("api.endpoint_errors.aspects.not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.aspects.not_found")
end
def index
@ -34,10 +34,10 @@ module Api
if aspect_membership
head :no_content
else
render json: I18n.t("api.endpoint_errors.contacts.cant_create"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.contacts.cant_create")
end
rescue ActiveRecord::RecordNotUnique
render json: I18n.t("api.endpoint_errors.contacts.cant_create"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.contacts.cant_create")
end
def destroy
@ -48,10 +48,10 @@ module Api
if result && result[:success]
head :no_content
else
render json: I18n.t("api.endpoint_errors.contacts.cant_delete"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.contacts.cant_delete")
end
rescue ActiveRecord::RecordNotFound
render json: I18n.t("api.endpoint_errors.contacts.not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.contacts.not_found")
end
def aspects_membership_service

View file

@ -10,7 +10,7 @@ module Api
end
rescue_from ActiveRecord::RecordNotFound do
render json: I18n.t("api.endpoint_errors.conversations.not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.conversations.not_found")
end
def index
@ -40,7 +40,7 @@ module Api
Diaspora::Federation::Dispatcher.defer_dispatch(current_user, conversation)
render json: conversation_as_json(conversation), status: :created
rescue ActiveRecord::RecordInvalid, ActionController::ParameterMissing, ActiveRecord::RecordNotFound
render json: I18n.t("api.endpoint_errors.conversations.cant_process"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.conversations.cant_process")
end
def destroy

View file

@ -12,11 +12,11 @@ module Api
end
rescue_from ActiveRecord::RecordNotFound do
render json: I18n.t("api.endpoint_errors.posts.post_not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.posts.post_not_found")
end
rescue_from ActiveRecord::RecordInvalid do
render json: I18n.t("api.endpoint_errors.likes.user_not_allowed_to_like"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.likes.user_not_allowed_to_like")
end
def show
@ -35,8 +35,9 @@ module Api
like_service.create(params[:post_id])
rescue ActiveRecord::RecordInvalid => e
return render json: I18n.t("api.endpoint_errors.likes.like_exists"), status: :unprocessable_entity if
e.message == "Validation failed: Target has already been taken"
if e.message == "Validation failed: Target has already been taken"
return render_error 422, I18n.t("api.endpoint_errors.likes.like_exists")
end
raise
else
@ -51,7 +52,7 @@ module Api
if success
head :no_content
else
render json: I18n.t("api.endpoint_errors.likes.no_like"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.likes.no_like")
end
end

View file

@ -8,7 +8,7 @@ module Api
end
rescue_from ActiveRecord::RecordNotFound do
render json: I18n.t("api.endpoint_errors.conversations.not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.conversations.not_found")
end
def create
@ -19,7 +19,7 @@ module Api
Diaspora::Federation::Dispatcher.defer_dispatch(current_user, message)
render json: message_json(message), status: :created
rescue ActionController::ParameterMissing
render json: I18n.t("api.endpoint_errors.conversations.cant_process"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.conversations.cant_process")
end
def index

View file

@ -8,7 +8,7 @@ module Api
end
rescue_from ActiveRecord::RecordNotFound do
render json: I18n.t("api.endpoint_errors.notifications.not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.notifications.not_found")
end
def show
@ -17,7 +17,7 @@ module Api
if notification
render json: NotificationPresenter.new(notification).as_api_json(true)
else
render json: I18n.t("api.endpoint_errors.notifications.not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.notifications.not_found")
end
end
@ -31,7 +31,7 @@ module Api
end
render_paged_api_response notifications_page
rescue ArgumentError
render json: I18n.t("api.endpoint_errors.notifications.cant_process"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.notifications.cant_process")
end
def update
@ -39,10 +39,10 @@ module Api
if service.update_status_by_guid(params[:id], read)
head :no_content
else
render json: I18n.t("api.endpoint_errors.notifications.cant_process"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.notifications.cant_process")
end
rescue ActionController::ParameterMissing
render json: I18n.t("api.endpoint_errors.notifications.cant_process"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.notifications.cant_process")
end
private

View file

@ -12,7 +12,7 @@ module Api
end
rescue_from ActiveRecord::RecordNotFound do
render json: I18n.t("api.endpoint_errors.photos.not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.photos.not_found")
end
def index
@ -46,7 +46,7 @@ module Api
render json: photo_json(photo)
rescue CarrierWave::IntegrityError, ActionController::ParameterMissing, RuntimeError
render json: I18n.t("api.endpoint_errors.photos.failed_create"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.photos.failed_create")
end
def destroy
@ -58,7 +58,7 @@ module Api
if current_user.retract(photo)
head :no_content
else
render json: I18n.t("api.endpoint_errors.photos.failed_delete"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.photos.failed_delete")
end
end

View file

@ -10,7 +10,7 @@ module Api
end
rescue_from ActiveRecord::RecordNotFound do
render json: I18n.t("api.endpoint_errors.posts.post_not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.posts.post_not_found")
end
def subscribe
@ -18,7 +18,7 @@ module Api
current_user.participate!(post)
head :no_content
rescue ActiveRecord::RecordInvalid
render json: I18n.t("api.endpoint_errors.interactions.cant_subscribe"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.interactions.cant_subscribe")
end
def hide
@ -45,27 +45,27 @@ module Api
if report.save
head :no_content
else
render json: I18n.t("api.endpoint_errors.posts.cant_report"), status: :conflict
render_error 409, I18n.t("api.endpoint_errors.posts.cant_report")
end
rescue ActionController::ParameterMissing
render json: I18n.t("api.endpoint_errors.posts.cant_report"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.posts.cant_report")
end
def vote
post = find_post
begin
post = find_post
poll_vote = poll_service.vote(post.id, params[:poll_answer_id])
rescue ActiveRecord::RecordNotFound
render json: I18n.t("api.endpoint_errors.posts.post_not_found"), status: :not_found
return
# This, but not the find_post above, should return a 422,
# we just keep poll_vote nil so it goes into the else below
end
poll_vote = poll_service.vote(post.id, params[:poll_answer_id])
if poll_vote
head :no_content
else
render json: I18n.t("api.endpoint_errors.interactions.cant_vote"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.interactions.cant_vote")
end
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotFound
render json: I18n.t("api.endpoint_errors.interactions.cant_vote"), status: :unprocessable_entity
rescue ActiveRecord::RecordInvalid
render_error 422, I18n.t("api.endpoint_errors.interactions.cant_vote")
end
private

View file

@ -14,7 +14,7 @@ module Api
end
rescue_from ActiveRecord::RecordNotFound do
render json: I18n.t("api.endpoint_errors.posts.post_not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.posts.post_not_found")
end
def show
@ -31,14 +31,14 @@ module Api
@status_message = creation_service.create(creation_params)
render json: PostPresenter.new(@status_message, current_user).as_api_response
rescue StandardError
render json: I18n.t("api.endpoint_errors.posts.failed_create"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.posts.failed_create")
end
def destroy
post_service.destroy(params[:id], private_modify?)
head :no_content
rescue Diaspora::NotMine, Diaspora::NonPublic
render json: I18n.t("api.endpoint_errors.posts.failed_delete"), status: :forbidden
render_error 403, I18n.t("api.endpoint_errors.posts.failed_delete")
end
private

View file

@ -12,11 +12,11 @@ module Api
end
rescue_from ActiveRecord::RecordNotFound do
render json: I18n.t("api.endpoint_errors.posts.post_not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.posts.post_not_found")
end
rescue_from Diaspora::NonPublic do
render json: I18n.t("api.endpoint_errors.posts.post_not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.posts.post_not_found")
end
def show
@ -35,7 +35,7 @@ module Api
def create
reshare = reshare_service.create(params.require(:post_id))
rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid, RuntimeError
render plain: I18n.t("reshares.create.error"), status: :unprocessable_entity
render_error 422, I18n.t("reshares.create.error")
else
render json: PostPresenter.new(reshare, current_user).as_api_response
end

View file

@ -8,7 +8,7 @@ module Api
end
rescue_from ActionController::ParameterMissing, RuntimeError do
render json: I18n.t("api.endpoint_errors.search.cant_process"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.search.cant_process")
end
def user_index

View file

@ -19,7 +19,7 @@ module Api
tag_followings_service.create(params.require(:name))
head :no_content
rescue StandardError
render json: I18n.t("api.endpoint_errors.tags.cant_process"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.tags.cant_process")
end
def destroy

View file

@ -22,7 +22,7 @@ module Api
end
rescue_from ActiveRecord::RecordNotFound do
render json: I18n.t("api.endpoint_errors.users.not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.users.not_found")
end
def show
@ -42,15 +42,15 @@ module Api
if params_to_update && current_user.update_profile(params_to_update)
render json: PersonPresenter.new(current_user.person, current_user).profile_hash_as_api_json
else
render json: I18n.t("api.endpoint_errors.users.cant_update"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.users.cant_update")
end
rescue RuntimeError
render json: I18n.t("api.endpoint_errors.users.cant_update"), status: :unprocessable_entity
render_error 422, I18n.t("api.endpoint_errors.users.cant_update")
end
def contacts
if params.require(:user_id) != current_user.guid
render json: I18n.t("api.endpoint_errors.users.not_found"), status: :not_found
render_error 404, I18n.t("api.endpoint_errors.users.not_found")
return
end

View file

@ -0,0 +1,8 @@
# frozen_string_literal: true
require "spec_helper"
def confirm_api_error(response, code, message)
expect(response.status).to eq(code)
expect(JSON.parse(response.body)).to eq("code" => code, "message" => message)
end

View file

@ -1,6 +1,6 @@
# frozen_sTring_literal: true
require "spec_helper"
require_relative "api_spec_helper"
describe Api::V1::AspectsController do
let(:auth) {
@ -91,8 +91,7 @@ describe Api::V1::AspectsController do
api_v1_aspect_path("-1"),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.aspects.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.aspects.not_found"))
end
end
@ -137,8 +136,7 @@ describe Api::V1::AspectsController do
params: {name: @aspect1.name, access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.aspects.cant_create"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.aspects.cant_create"))
end
end
@ -149,8 +147,7 @@ describe Api::V1::AspectsController do
params: {order: 0, access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.aspects.cant_create"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.aspects.cant_create"))
end
end
@ -237,8 +234,7 @@ describe Api::V1::AspectsController do
params: {name: @aspect1.name, access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.aspects.cant_update"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.aspects.cant_update"))
end
it "fails with bad id" do
@ -247,8 +243,7 @@ describe Api::V1::AspectsController do
params: {name: "NewAspectName", access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.aspects.cant_update"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.aspects.cant_update"))
end
end
@ -289,8 +284,7 @@ describe Api::V1::AspectsController do
api_v1_aspect_path("-1"),
params: {access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.aspects.cant_delete"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.aspects.cant_delete"))
end
end

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
require "spec_helper"
require_relative "api_spec_helper"
describe Api::V1::CommentsController do
let(:auth) {
@ -80,8 +80,7 @@ describe Api::V1::CommentsController do
api_v1_post_comments_path(post_id: "999_999_999"),
params: {body: "text", access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
end
@ -102,8 +101,7 @@ describe Api::V1::CommentsController do
api_v1_post_comments_path(post_id: @private_post.guid),
params: {body: "comment text", access_token: access_token_public_only}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
it "fails without interactions scope" do
@ -154,8 +152,7 @@ describe Api::V1::CommentsController do
api_v1_post_comments_path(post_id: "999_999_999"),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
end
@ -165,8 +162,7 @@ describe Api::V1::CommentsController do
api_v1_post_comments_path(post_id: @private_post.guid),
params: {access_token: access_token_public_only}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
it "fails without valid token" do
@ -210,8 +206,7 @@ describe Api::V1::CommentsController do
),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
end
@ -237,8 +232,7 @@ describe Api::V1::CommentsController do
),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.comments.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.comments.not_found"))
end
end
@ -252,8 +246,7 @@ describe Api::V1::CommentsController do
),
params: {access_token: access_token}
)
expect(response.status).to eq(403)
expect(response.body).to eq(I18n.t("api.endpoint_errors.comments.no_delete"))
confirm_api_error(response, 403, I18n.t("api.endpoint_errors.comments.no_delete"))
end
end
@ -316,8 +309,7 @@ describe Api::V1::CommentsController do
access_token: access_token
}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.comments.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.comments.not_found"))
end
end
@ -333,8 +325,7 @@ describe Api::V1::CommentsController do
access_token: access_token
}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
end
@ -350,8 +341,7 @@ describe Api::V1::CommentsController do
access_token: access_token
}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
end
@ -367,8 +357,7 @@ describe Api::V1::CommentsController do
access_token: access_token
}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.comments.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.comments.not_found"))
end
end
@ -396,8 +385,7 @@ describe Api::V1::CommentsController do
access_token: access_token
}
)
expect(response.status).to eq(409)
expect(response.body).to eq(I18n.t("api.endpoint_errors.comments.duplicate_report"))
confirm_api_error(response, 409, I18n.t("api.endpoint_errors.comments.duplicate_report"))
end
end
@ -413,8 +401,7 @@ describe Api::V1::CommentsController do
access_token: access_token_public_only
}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
it "fails without valid token" do

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
require "spec_helper"
require_relative "api_spec_helper"
describe Api::V1::ContactsController do
let(:auth) {
@ -68,8 +68,7 @@ describe Api::V1::ContactsController do
api_v1_aspect_contacts_path(-1),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.aspects.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.aspects.not_found"))
end
it "fails for other user's Aspect ID" do
@ -77,8 +76,7 @@ describe Api::V1::ContactsController do
api_v1_aspect_contacts_path(@eve_aspect.id),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.aspects.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.aspects.not_found"))
end
end
@ -119,8 +117,7 @@ describe Api::V1::ContactsController do
api_v1_aspect_contacts_path(@aspect2.id),
params: {person_guid: alice.guid, access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.contacts.cant_create"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.contacts.cant_create"))
end
end
@ -130,8 +127,7 @@ describe Api::V1::ContactsController do
api_v1_aspect_contacts_path(-1),
params: {person_guid: alice.guid, access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.aspects.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.aspects.not_found"))
end
it "fails for other user's Aspect ID" do
@ -139,8 +135,7 @@ describe Api::V1::ContactsController do
api_v1_aspect_contacts_path(@eve_aspect.id),
params: {person_guid: alice.guid, access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.aspects.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.aspects.not_found"))
end
end
@ -150,8 +145,7 @@ describe Api::V1::ContactsController do
api_v1_aspect_contacts_path(@aspect2.id),
params: {person_guid: "999_999_999", access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.contacts.cant_create"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.contacts.cant_create"))
end
end
@ -194,8 +188,7 @@ describe Api::V1::ContactsController do
api_v1_aspect_contact_path(@aspect2.id, eve.guid),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.contacts.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.contacts.not_found"))
end
end
@ -205,8 +198,7 @@ describe Api::V1::ContactsController do
api_v1_aspect_contact_path(-1, eve.guid),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.contacts.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.contacts.not_found"))
end
it "fails for other user's Aspect ID" do
@ -214,8 +206,7 @@ describe Api::V1::ContactsController do
api_v1_aspect_contact_path(@eve_aspect.id, eve.guid),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.contacts.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.contacts.not_found"))
end
end
@ -225,8 +216,7 @@ describe Api::V1::ContactsController do
api_v1_aspect_contact_path(@aspect2.id, "999_999_999"),
params: {access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.contacts.cant_delete"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.contacts.cant_delete"))
end
end

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
require "spec_helper"
require_relative "api_spec_helper"
describe Api::V1::ConversationsController do
let(:auth) {
@ -57,8 +57,7 @@ describe Api::V1::ConversationsController do
context "without valid data" do
it "fails with empty body" do
post api_v1_conversations_path, params: {access_token: access_token}
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.conversations.cant_process"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.conversations.cant_process"))
end
it "fails with missing subject " do
@ -68,8 +67,7 @@ describe Api::V1::ConversationsController do
access_token: access_token
}
post api_v1_conversations_path, params: incomplete_conversation
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.conversations.cant_process"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.conversations.cant_process"))
end
it "fails with missing body " do
@ -79,8 +77,7 @@ describe Api::V1::ConversationsController do
access_token: access_token
}
post api_v1_conversations_path, params: incomplete_conversation
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.conversations.cant_process"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.conversations.cant_process"))
end
it "fails with missing recipients " do
@ -90,8 +87,7 @@ describe Api::V1::ConversationsController do
access_token: access_token
}
post api_v1_conversations_path, params: incomplete_conversation
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.conversations.cant_process"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.conversations.cant_process"))
end
it "fails with bad recipient ID " do
@ -102,8 +98,7 @@ describe Api::V1::ConversationsController do
access_token: access_token
}
post api_v1_conversations_path, params: incomplete_conversation
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.conversations.cant_process"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.conversations.cant_process"))
end
it "fails with invalid recipient (not allowed to message) " do
@ -114,8 +109,7 @@ describe Api::V1::ConversationsController do
access_token: access_token
}
post api_v1_conversations_path, params: incomplete_conversation
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.conversations.cant_process"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.conversations.cant_process"))
end
end
@ -237,8 +231,7 @@ describe Api::V1::ConversationsController do
api_v1_conversation_path(-1),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.conversations.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.conversations.not_found"))
end
end
@ -291,8 +284,7 @@ describe Api::V1::ConversationsController do
@conversation_guid,
params: {access_token: access_token}
)
expect(response.status).to eq 404
expect(response.body).to eq(I18n.t("api.endpoint_errors.conversations.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.conversations.not_found"))
get api_v1_conversation_path(
@conversation_guid,
params: {access_token: access_token_participant}
@ -317,8 +309,7 @@ describe Api::V1::ConversationsController do
@conversation_guid,
params: {access_token: access_token_participant}
)
expect(response.status).to eq 404
expect(response.body).to eq(I18n.t("api.endpoint_errors.conversations.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.conversations.not_found"))
expect {
Conversation.find(guid: @conversation_guid)
@ -332,8 +323,7 @@ describe Api::V1::ConversationsController do
api_v1_conversation_path(42),
params: {access_token: access_token}
)
expect(response.status).to eq 404
expect(response.body).to eq(I18n.t("api.endpoint_errors.conversations.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.conversations.not_found"))
end
end

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
require "spec_helper"
require_relative "api_spec_helper"
describe Api::V1::LikesController do
let(:auth) {
@ -85,8 +85,7 @@ describe Api::V1::LikesController do
api_v1_post_likes_path(post_id: "badguid"),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
end
@ -97,8 +96,7 @@ describe Api::V1::LikesController do
api_v1_post_likes_path(post_id: @private_status.guid),
params: {access_token: access_token_public_only}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.likes.user_not_allowed_to_like"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.likes.user_not_allowed_to_like"))
end
end
@ -136,8 +134,7 @@ describe Api::V1::LikesController do
api_v1_post_likes_path(post_id: @status.guid),
params: {access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.likes.like_exists"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.likes.like_exists"))
likes = like_service.find_for_post(@status.guid)
expect(likes.length).to eq(1)
@ -151,8 +148,7 @@ describe Api::V1::LikesController do
api_v1_post_likes_path(post_id: 99_999_999),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
end
@ -210,8 +206,7 @@ describe Api::V1::LikesController do
api_v1_post_likes_path(post_id: @status.guid),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.likes.no_like"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.likes.no_like"))
likes = like_service.find_for_post(@status.guid)
expect(likes.length).to eq(0)
@ -224,8 +219,7 @@ describe Api::V1::LikesController do
api_v1_post_likes_path(post_id: 99_999_999),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
end
@ -236,8 +230,7 @@ describe Api::V1::LikesController do
api_v1_post_likes_path(post_id: @private_status.guid),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
it "fails in unliking post without interactions" do

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
require "spec_helper"
require_relative "api_spec_helper"
describe Api::V1::MessagesController do
let(:auth) {
@ -71,8 +71,7 @@ describe Api::V1::MessagesController do
api_v1_conversation_messages_path(@conversation_guid),
params: {access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq I18n.t("api.endpoint_errors.conversations.cant_process")
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.conversations.cant_process"))
end
it "empty string returns a unprocessable entity (422)" do
@ -80,8 +79,7 @@ describe Api::V1::MessagesController do
api_v1_conversation_messages_path(@conversation_guid),
params: {body: "", access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq I18n.t("api.endpoint_errors.conversations.cant_process")
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.conversations.cant_process"))
end
end
@ -91,8 +89,7 @@ describe Api::V1::MessagesController do
api_v1_conversation_messages_path(42),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq I18n.t("api.endpoint_errors.conversations.not_found")
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.conversations.not_found"))
end
end

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
require "spec_helper"
require_relative "api_spec_helper"
describe Api::V1::NotificationsController do
let(:auth) {
@ -87,8 +87,7 @@ describe Api::V1::NotificationsController do
api_v1_notifications_path,
params: {only_after: "January 1, 2018", access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.notifications.cant_process"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.notifications.cant_process"))
end
it "with insufficient credentials" do
@ -130,8 +129,7 @@ describe Api::V1::NotificationsController do
api_v1_notification_path("999_999_999"),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.notifications.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.notifications.not_found"))
end
it "on someone else's notification" do
@ -147,8 +145,7 @@ describe Api::V1::NotificationsController do
api_v1_notification_path(alice_notification.guid),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.notifications.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.notifications.not_found"))
end
it "with insufficient credentials" do
@ -193,8 +190,7 @@ describe Api::V1::NotificationsController do
api_v1_notification_path("999_999_999"),
params: {access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.notifications.cant_process"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.notifications.cant_process"))
end
it "with proper missing read field" do
@ -202,8 +198,7 @@ describe Api::V1::NotificationsController do
api_v1_notification_path(@notification.guid),
params: {access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.notifications.cant_process"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.notifications.cant_process"))
end
it "with insufficient credentials" do

View file

@ -1,6 +1,6 @@
# frozen_sTring_literal: true
require "spec_helper"
require_relative "api_spec_helper"
describe Api::V1::PhotosController do
let(:auth) {
@ -109,8 +109,7 @@ describe Api::V1::PhotosController do
api_v1_photo_path(@shared_photo1.guid),
params: {access_token: access_token_public_only_read_only}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.photos.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.photos.not_found"))
end
it "with other user's private photo" do
@ -118,8 +117,7 @@ describe Api::V1::PhotosController do
api_v1_photo_path(@private_photo1.guid),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.photos.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.photos.not_found"))
end
it "with invalid GUID" do
@ -127,8 +125,7 @@ describe Api::V1::PhotosController do
api_v1_photo_path("999_999_999"),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.photos.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.photos.not_found"))
end
it "with invalid access token" do
@ -244,8 +241,7 @@ describe Api::V1::PhotosController do
api_v1_photos_path,
params: {access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.photos.failed_create"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.photos.failed_create"))
end
it "with non-image file" do
@ -257,8 +253,7 @@ describe Api::V1::PhotosController do
api_v1_photos_path,
params: {image: text_file, access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.photos.failed_create"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.photos.failed_create"))
end
it "with impromperly identified file" do
@ -270,8 +265,7 @@ describe Api::V1::PhotosController do
api_v1_photos_path,
params: {image: text_file, access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.photos.failed_create"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.photos.failed_create"))
end
it "with invalid access token" do
@ -319,8 +313,7 @@ describe Api::V1::PhotosController do
api_v1_photo_path(@alice_public_photo.guid),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.photos.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.photos.not_found"))
end
it "with other invalid GUID" do
@ -328,8 +321,7 @@ describe Api::V1::PhotosController do
api_v1_photo_path("999_999_999"),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.photos.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.photos.not_found"))
end
it "with invalid access token" do

View file

@ -1,6 +1,6 @@
# frozen_sTring_literal: true
require "spec_helper"
require_relative "api_spec_helper"
describe Api::V1::PostInteractionsController do
let(:auth) {
@ -82,8 +82,7 @@ describe Api::V1::PostInteractionsController do
access_token: access_token
}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
it "with insufficient token" do
@ -141,8 +140,7 @@ describe Api::V1::PostInteractionsController do
access_token: access_token
}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
it "with insufficient token" do
@ -210,8 +208,7 @@ describe Api::V1::PostInteractionsController do
access_token: access_token
}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
it "when not subscribed already" do
@ -288,8 +285,7 @@ describe Api::V1::PostInteractionsController do
access_token: access_token
}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
it "when already reported" do
@ -308,8 +304,7 @@ describe Api::V1::PostInteractionsController do
access_token: access_token
}
)
expect(response.status).to eq(409)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.cant_report"))
confirm_api_error(response, 409, I18n.t("api.endpoint_errors.posts.cant_report"))
end
it "when missing reason" do
@ -319,8 +314,7 @@ describe Api::V1::PostInteractionsController do
access_token: access_token
}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.cant_report"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.posts.cant_report"))
end
it "with insufficient token" do
@ -395,8 +389,7 @@ describe Api::V1::PostInteractionsController do
access_token: access_token
}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.interactions.cant_vote"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.interactions.cant_vote"))
end
it "fails with bad answer id" do
@ -407,8 +400,7 @@ describe Api::V1::PostInteractionsController do
access_token: access_token
}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.interactions.cant_vote"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.interactions.cant_vote"))
end
it "fails with bad post id" do
@ -419,8 +411,7 @@ describe Api::V1::PostInteractionsController do
access_token: access_token
}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
it "with insufficient token" do

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
require "spec_helper"
require_relative "api_spec_helper"
describe Api::V1::PostsController do
let(:auth) {
@ -128,8 +128,7 @@ describe Api::V1::PostsController do
access_token: access_token
}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
end
@ -146,8 +145,7 @@ describe Api::V1::PostsController do
access_token: access_token_public_only_read_only
}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
get(
api_v1_post_path(shared_post.guid),
@ -167,8 +165,7 @@ describe Api::V1::PostsController do
access_token: access_token
}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
end
@ -322,8 +319,7 @@ describe Api::V1::PostsController do
photos: ["999_999_999"]
}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.failed_create"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.posts.failed_create"))
end
it "creates with poll" do
@ -364,8 +360,7 @@ describe Api::V1::PostsController do
}
}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.failed_create"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.posts.failed_create"))
end
it "fails poll with blank answer" do
@ -382,8 +377,7 @@ describe Api::V1::PostsController do
}
}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.failed_create"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.posts.failed_create"))
end
it "fails poll with blank question and message text" do
@ -399,8 +393,7 @@ describe Api::V1::PostsController do
}
}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.failed_create"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.posts.failed_create"))
end
it "creates with location" do
@ -476,8 +469,7 @@ describe Api::V1::PostsController do
public: true
}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.failed_create"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.posts.failed_create"))
end
it "fails when no public field and no aspects" do
@ -489,8 +481,7 @@ describe Api::V1::PostsController do
body: message_text
}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.failed_create"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.posts.failed_create"))
end
it "fails when private no aspects" do
@ -503,8 +494,7 @@ describe Api::V1::PostsController do
public: false
}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.failed_create"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.posts.failed_create"))
end
it "fails when unknown aspect IDs" do
@ -518,8 +508,7 @@ describe Api::V1::PostsController do
aspects: ["-1"]
}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.failed_create"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.posts.failed_create"))
end
it "fails when no public field but aspects" do
@ -534,8 +523,7 @@ describe Api::V1::PostsController do
aspects: [aspect.id]
}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.failed_create"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.posts.failed_create"))
end
end
@ -638,8 +626,7 @@ describe Api::V1::PostsController do
api_v1_post_path("999_999_999"),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
end
@ -656,8 +643,7 @@ describe Api::V1::PostsController do
api_v1_post_path(status.guid),
params: {access_token: access_token}
)
expect(response.status).to eq(403)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.failed_delete"))
confirm_api_error(response, 403, I18n.t("api.endpoint_errors.posts.failed_delete"))
end
end
end

View file

@ -1,6 +1,6 @@
# frozen_sTring_literal: true
require "spec_helper"
require_relative "api_spec_helper"
describe Api::V1::ResharesController do
let(:auth) {
@ -85,8 +85,7 @@ describe Api::V1::ResharesController do
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
it "fails with private post it shouldn't see" do
@ -97,8 +96,7 @@ describe Api::V1::ResharesController do
access_token: access_token
}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
end
@ -139,8 +137,7 @@ describe Api::V1::ResharesController do
params: {access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("reshares.create.error"))
confirm_api_error(response, 422, I18n.t("reshares.create.error"))
end
end
@ -151,8 +148,7 @@ describe Api::V1::ResharesController do
params: {access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("reshares.create.error"))
confirm_api_error(response, 422, I18n.t("reshares.create.error"))
end
it "fails with own post" do
@ -161,8 +157,7 @@ describe Api::V1::ResharesController do
params: {access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("reshares.create.error"))
confirm_api_error(response, 422, I18n.t("reshares.create.error"))
end
it "fails with private post it shouldn't see" do
@ -173,8 +168,7 @@ describe Api::V1::ResharesController do
access_token: access_token
}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("reshares.create.error"))
confirm_api_error(response, 422, I18n.t("reshares.create.error"))
end
it "fails with private post it can see" do
@ -185,8 +179,7 @@ describe Api::V1::ResharesController do
access_token: access_token
}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.posts.post_not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.posts.post_not_found"))
end
end

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
require "spec_helper"
require_relative "api_spec_helper"
describe Api::V1::SearchController do
let(:auth) {
@ -128,8 +128,7 @@ describe Api::V1::SearchController do
"/api/v1/search/users",
params: {tag: "tag1", name_or_handle: "name", access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.search.cant_process"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.search.cant_process"))
end
it "fails with no fields" do
@ -137,8 +136,7 @@ describe Api::V1::SearchController do
"/api/v1/search/users",
params: {access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.search.cant_process"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.search.cant_process"))
end
it "fails with bad credentials" do
@ -210,8 +208,7 @@ describe Api::V1::SearchController do
"/api/v1/search/posts",
params: {access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.search.cant_process"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.search.cant_process"))
end
it "fails with bad credentials" do

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
require "spec_helper"
require_relative "api_spec_helper"
describe Api::V1::StreamsController do
let(:auth_read_only) {

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
require "spec_helper"
require_relative "api_spec_helper"
describe Api::V1::TagFollowingsController do
let(:auth) {
@ -56,8 +56,7 @@ describe Api::V1::TagFollowingsController do
params: {access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.tags.cant_process"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.tags.cant_process"))
end
end
@ -68,8 +67,7 @@ describe Api::V1::TagFollowingsController do
params: {name: "tag3", access_token: access_token}
)
expect(response.status).to eq(422)
expect(response.body).to eq(I18n.t("api.endpoint_errors.tags.cant_process"))
confirm_api_error(response, 422, I18n.t("api.endpoint_errors.tags.cant_process"))
end
end

View file

@ -1,6 +1,6 @@
# frozen_sTring_literal: true
require "spec_helper"
require_relative "api_spec_helper"
describe Api::V1::UsersController do
include PeopleHelper
@ -168,8 +168,7 @@ describe Api::V1::UsersController do
"/api/v1/users/999_999_999",
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.users.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.users.not_found"))
end
end
end
@ -335,8 +334,7 @@ describe Api::V1::UsersController do
api_v1_user_contacts_path("999_999_999"),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.users.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.users.not_found"))
end
it "fails with other user's GUID" do
@ -344,8 +342,7 @@ describe Api::V1::UsersController do
api_v1_user_contacts_path(alice.guid),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.users.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.users.not_found"))
end
it "fails if insufficient scope token" do
@ -427,8 +424,7 @@ describe Api::V1::UsersController do
api_v1_user_photos_path("999_999_999"),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.users.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.users.not_found"))
end
it "fails if invalid token" do
@ -501,8 +497,7 @@ describe Api::V1::UsersController do
api_v1_user_posts_path("999_999_999"),
params: {access_token: access_token}
)
expect(response.status).to eq(404)
expect(response.body).to eq(I18n.t("api.endpoint_errors.users.not_found"))
confirm_api_error(response, 404, I18n.t("api.endpoint_errors.users.not_found"))
end
it "fails if invalid token" do