-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(server): status code and header info
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
server/test/controllers/api/v1/statistics_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |