Skip to content

Commit

Permalink
Adding tests for get request to index models
Browse files Browse the repository at this point in the history
  • Loading branch information
dexterhenry committed Aug 7, 2021
1 parent 340976a commit cf0fb9e
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions spec/requests/app/controllers/api/v3/models_index_api_spec.rb
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.

Copy link
@sanchojaf

sanchojaf Aug 8, 2021

Member

check in your editor, how to add an empty line at the end of the file

0 comments on commit cf0fb9e

Please sign in to comment.