-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tests for get request to index models
- Loading branch information
1 parent
340976a
commit cf0fb9e
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
spec/requests/app/controllers/api/v3/models_index_api_spec.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,42 @@ | ||
require 'rails_helper' | ||
RSpec.describe Api::V3::ApiController, type: :request do | ||
Setup::Models.all.each do |model| | ||
model_name_array = model.name.to_s.split('::') | ||
namespace = model_name_array.first.downcase | ||
underscore_model_name = model_name_array.last.underscore | ||
|
||
if namespace == "setup" || namespace == "cenit" | ||
describe "GET /api/v3/#{namespace}/#{underscore_model_name}" do | ||
context "fail retrieve all existing #{underscore_model_name}" do | ||
it "with missing header request" do | ||
get "/api/v3/#{namespace}/#{underscore_model_name}" | ||
expect(response).to have_http_status(:forbidden) | ||
expect(json_response[:error]).to eq("insufficient_scope") | ||
expect(json_response[:error_description]).to eq("The requested action is out of the access token scope") | ||
end | ||
|
||
it "with unauthorized token request" do | ||
get "/api/v3/#{namespace}/#{underscore_model_name}", headers: { | ||
Authorization: "Bearer unauthorized_token }" | ||
} | ||
expect(response).to have_http_status(:unauthorized) | ||
expect(json_response[:error]).to eq("invalid_token") | ||
expect(json_response[:error_description]).to eq("Malformed authorization header") | ||
end | ||
end | ||
|
||
context "successful retrieve all existing #{underscore_model_name}" do | ||
it "with authorized token request" do | ||
get "/api/v3/#{namespace}/#{underscore_model_name}", headers: header_token_authorization | ||
expect(response).to have_http_status(:ok) | ||
expect(json_response[:count]).to be | ||
expect(json_response[:current_page]).to be | ||
expect(json_response[:data_type]).to be | ||
expect(json_response[:items]).to be | ||
expect(json_response[:total_pages]).to be | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
This comment has been minimized.
Sorry, something went wrong. |
check in your editor, how to add an empty line at the end of the file