-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
app/controllers/api/v1/authorization_requests_controller.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,24 @@ | ||
class API::V1::AuthorizationRequestsController < API::V1Controller | ||
def index | ||
authorization_requests = AuthorizationRequest | ||
.where(type: valid_authorization_request_types) | ||
.offset(params[:offset]) | ||
.limit(params.fetch(:limit, 10)) | ||
|
||
if authorization_requests.any? | ||
render json: authorization_requests, | ||
each_serializer: API::V1::AuthorizationRequestSerializer, | ||
status: :ok | ||
else | ||
render_error(404, title: 'Non trouvé', detail: 'Aucune demande n\'a été trouvé') | ||
end | ||
end | ||
|
||
private | ||
|
||
def valid_authorization_request_types | ||
current_user.developer_roles.map do |role| | ||
"AuthorizationRequest::#{role.split(':')[0].classify}" | ||
end | ||
end | ||
end |
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 @@ | ||
class API::V1::AuthorizationRequestSerializer < WebhookAuthorizationRequestSerializer; end |
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
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
24 changes: 24 additions & 0 deletions
24
spec/requests/api/v1/authorization_requests_controller_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,24 @@ | ||
RSpec.describe 'API: Authorization requests', type: :request do | ||
let(:user) { create(:user, :developer) } | ||
let(:application) { create(:oauth_application, owner: user) } | ||
let(:access_token) { create(:access_token, application:, resource_owner_id: user.id) } | ||
|
||
describe 'index' do | ||
subject(:get_index) do | ||
get '/api/v1/demandes', headers: { 'Authorization' => "Bearer #{access_token.token}" } | ||
end | ||
|
||
context 'when there is at least one authorization request associated to one of the user developer role' do | ||
let!(:valid_authorization_request) { create(:authorization_request, :api_entreprise) } | ||
let!(:invalid_authorization_request) { create(:authorization_request, :api_particulier) } | ||
|
||
it 'reponds OK with data' do | ||
get_index | ||
|
||
expect(response.status).to eq(200) | ||
expect(response.parsed_body.count).to eq(1) | ||
expect(response.parsed_body[0]['id']).to eq(valid_authorization_request.id) | ||
end | ||
end | ||
end | ||
end |