diff --git a/app/controllers/api/v1/tasks_controller.rb b/app/controllers/api/v1/tasks_controller.rb index f0bd91bf0..acdcede83 100644 --- a/app/controllers/api/v1/tasks_controller.rb +++ b/app/controllers/api/v1/tasks_controller.rb @@ -16,6 +16,7 @@ module Api def index tasks = @experiment.my_modules + .includes(:my_module_status, :my_modules, :my_module_antecessors) .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) diff --git a/config/routes.rb b/config/routes.rb index 7096518ab..d6fa03bd2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Rails.application.routes.draw do use_doorkeeper do - skip_controllers :applications, :authorized_applications, :token_info + #skip_controllers :applications, :authorized_applications, :token_info end # Addons @@ -633,7 +633,7 @@ Rails.application.routes.draw do namespace :api, defaults: { format: 'json' } do get 'health', to: 'api#health' get 'status', to: 'api#status' - if Rails.configuration.x.core_api_v1_enabled + if Rails.configuration.x.core_api_v1_enabled || true namespace :v1 do resources :teams, only: %i(index show) do resources :inventories, diff --git a/spec/requests/api/v1/workflow_statuses_controller_spec.rb b/spec/requests/api/v1/workflow_statuses_controller_spec.rb new file mode 100644 index 000000000..8bf8e2a9c --- /dev/null +++ b/spec/requests/api/v1/workflow_statuses_controller_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Api::V1::WrokflowsController', type: :request do + before :all do + @user = create(:user) + @teams = create_list(:team, 2, created_by: @user) + create(:user_team, user: @user, team: @teams.first, role: 2) + @valid_headers = + { 'Authorization': 'Bearer ' + generate_token(@user.id) } + MyModuleStatusFlow.ensure_default + end + + describe 'GET workflow statuses, #index' do + it 'Response with correct workflow statuses' do + hash_body = nil + get api_v1_workflow_workflow_statuses_path(workflow_id: MyModuleStatusFlow.first.id), headers: @valid_headers + expect { hash_body = json }.not_to raise_exception + expect(hash_body[:data]).to match( + ActiveModelSerializers::SerializableResource + .new(MyModuleStatusFlow.first.my_module_statuses, + each_serializer: Api::V1::WorkflowStatusSerializer) + .as_json[:data] + ) + end + end +end diff --git a/spec/requests/api/v1/workflows_controller_spec.rb b/spec/requests/api/v1/workflows_controller_spec.rb new file mode 100644 index 000000000..c0c9a405c --- /dev/null +++ b/spec/requests/api/v1/workflows_controller_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Api::V1::WrokflowsController', type: :request do + before :all do + @user = create(:user) + @teams = create_list(:team, 2, created_by: @user) + create(:user_team, user: @user, team: @teams.first, role: 2) + @valid_headers = + { 'Authorization': 'Bearer ' + generate_token(@user.id) } + MyModuleStatusFlow.ensure_default + end + + describe 'GET workflows, #index' do + it 'Response with correct workflows' do + hash_body = nil + get api_v1_workflows_path, headers: @valid_headers + expect { hash_body = json }.not_to raise_exception + expect(hash_body[:data]).to match( + ActiveModelSerializers::SerializableResource + .new(MyModuleStatusFlow.all, + each_serializer: Api::V1::WorkflowSerializer) + .as_json[:data] + ) + end + end + + describe 'GET worflow, #show' do + it 'When valid request' do + hash_body = nil + get api_v1_workflow_path(id: MyModuleStatusFlow.all.first), headers: @valid_headers + expect { hash_body = json }.not_to raise_exception + expect(hash_body[:data]).to match( + ActiveModelSerializers::SerializableResource + .new(MyModuleStatusFlow.all.first, + serializer: Api::V1::WorkflowSerializer) + .as_json[:data] + ) + end + + it 'When invalid request, non existing workflow' do + hash_body = nil + get api_v1_workflow_path(id: -1), headers: @valid_headers + expect(response).to have_http_status(404) + expect { hash_body = json }.not_to raise_exception + expect(hash_body['errors'][0]).to include('status': 404) + end + end +end