Skip to content

Commit

Permalink
test(server): status code and header info
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Jun 3, 2019
1 parent ba3599b commit 8886905
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions server/test/controllers/api/v1/statistics_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'test_helper'

class Api::V1::StatisticsControllerTest < ActionDispatch::IntegrationTest
test "should get success code when call index" do
valid_get api_v1_statistics_url

assert_response :success
end

test "should set right content type when call index" do
valid_get api_v1_statistics_url

assert_equal "application/vnd.api+json", response.content_type
end

test "should respond with 415 Unsupported Media Type when Content-Type is wrong" do
get api_v1_statistics_url, headers: { "Content-Type": "text/plain" }

assert_equal 415, response.status
end

test "should respond with error object when Content-Type is wrong" do
error_object = Api::V1::Exceptions::WrongContentTypeError.new
response_json = RequestErrorSerializer.new([error_object], message: error_object.title).serialized_json

get api_v1_statistics_url, headers: { "Content-Type": "text/plain" }

assert_equal response_json, response.body
end

test "should respond with 406 Not Acceptable when Accept is wrong" do
get api_v1_statistics_url, headers: { "Content-Type": "application/vnd.api+json", "Accept": "application/json" }

assert_equal 406, response.status
end

test "should respond with error object when Accept is wrong" do
error_object = Api::V1::Exceptions::WrongAcceptError.new
response_json = RequestErrorSerializer.new([error_object], message: error_object.title).serialized_json

get api_v1_statistics_url, headers: { "Content-Type": "application/vnd.api+json", "Accept": "application/json" }

assert_equal response_json, response.body
end
end

0 comments on commit 8886905

Please sign in to comment.