mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-31 12:09:17 +08:00
Add tests for new workflow endpoints
This commit is contained in:
parent
68f31ce7ec
commit
4c7312faf9
4 changed files with 81 additions and 2 deletions
|
@ -16,6 +16,7 @@ module Api
|
||||||
|
|
||||||
def index
|
def index
|
||||||
tasks = @experiment.my_modules
|
tasks = @experiment.my_modules
|
||||||
|
.includes(:my_module_status, :my_modules, :my_module_antecessors)
|
||||||
.page(params.dig(:page, :number))
|
.page(params.dig(:page, :number))
|
||||||
.per(params.dig(:page, :size))
|
.per(params.dig(:page, :size))
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
use_doorkeeper do
|
use_doorkeeper do
|
||||||
skip_controllers :applications, :authorized_applications, :token_info
|
#skip_controllers :applications, :authorized_applications, :token_info
|
||||||
end
|
end
|
||||||
|
|
||||||
# Addons
|
# Addons
|
||||||
|
@ -633,7 +633,7 @@ Rails.application.routes.draw do
|
||||||
namespace :api, defaults: { format: 'json' } do
|
namespace :api, defaults: { format: 'json' } do
|
||||||
get 'health', to: 'api#health'
|
get 'health', to: 'api#health'
|
||||||
get 'status', to: 'api#status'
|
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
|
namespace :v1 do
|
||||||
resources :teams, only: %i(index show) do
|
resources :teams, only: %i(index show) do
|
||||||
resources :inventories,
|
resources :inventories,
|
||||||
|
|
28
spec/requests/api/v1/workflow_statuses_controller_spec.rb
Normal file
28
spec/requests/api/v1/workflow_statuses_controller_spec.rb
Normal file
|
@ -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
|
50
spec/requests/api/v1/workflows_controller_spec.rb
Normal file
50
spec/requests/api/v1/workflows_controller_spec.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue