fix failing scenarios

This commit is contained in:
zmagoD 2021-05-29 18:40:26 +02:00
parent f1c3bf7cf6
commit ffaf141abf
15 changed files with 52 additions and 43 deletions

View file

@ -660,7 +660,7 @@ Rails.application.routes.draw do
namespace :api, defaults: { format: 'json' } do
get 'health', to: 'api#health'
get 'status', to: 'api#status'
if true #Rails.configuration.x.core_api_v1_enabled
if Rails.configuration.x.core_api_v1_enabled
namespace :v1 do
resources :teams, only: %i(index show) do
resources :inventories, only: %i(index create show update destroy) do

View file

@ -12,8 +12,13 @@ describe MyModuleTagsController, type: :controller do
let!(:user_project) do
create :user_project, user: user, project: project
end
let(:normal_user_role) { create :normal_user_role }
let!(:user_assignment) { create :user_assignment, assignable: project, user: user, user_role: normal_user_role, assigned_by: user }
let!(:user_assignment) do
create :user_assignment,
assignable: project,
user: user,
user_role: create(:owner_role),
assigned_by: user
end
let(:experiment) { create :experiment, project: project }
let(:my_module) { create :my_module, experiment: experiment }

View file

@ -9,11 +9,15 @@ describe MyModulesController, type: :controller do
let(:team) { create :team, created_by: user }
let!(:user_team) { create :user_team, :admin, user: user, team: team }
let(:project) { create :project, team: team, created_by: user }
let!(:user_project) do
create :user_project, user: user, project: project
let!(:user_project) { create :user_project, user: user, project: project }
let(:owner_role) { create :owner_role }
let!(:user_assignment) do
create :user_assignment,
assignable: project,
user: user,
user_role: owner_role,
assigned_by: user
end
let(:normal_user_role) { create :normal_user_role }
let!(:user_assignment) { create :user_assignment, assignable: project, user: user, user_role: normal_user_role, assigned_by: user }
let!(:repository) { create :repository, created_by: user, team: team }
let!(:repository_row) do
create :repository_row, created_by: user, repository: repository
@ -159,6 +163,7 @@ describe MyModulesController, type: :controller do
it 'renders 403' do
# Remove user from project
UserProject.where(user: user, project: project).destroy_all
UserAssignment.where(user: user, assignable: project).destroy_all
action
expect(response).to have_http_status 403
@ -194,7 +199,7 @@ describe MyModulesController, type: :controller do
create :user_assignment,
assignable: experiment.project,
user: user,
user_role: create(:owner_role),
user_role: owner_role,
assigned_by: user
end

View file

@ -9,8 +9,13 @@ describe ProtocolsController, type: :controller do
let(:team) { create :team, created_by: user }
let!(:user_team) { create :user_team, :admin, user: user, team: team }
let(:project) { create :project, team: team, created_by: user }
let!(:user_project) do
create :user_project, user: user, project: project
let!(:user_project) { create :user_project, user: user, project: project }
let!(:user_assignment) do
create :user_assignment,
assignable: project,
user: user,
user_role: create(:owner_role),
assigned_by: user
end
let(:experiment) { create :experiment, project: project }
let(:my_module) { create :my_module, experiment: experiment }

View file

@ -12,12 +12,11 @@ describe StepsController, type: :controller do
let!(:user_project) do
create :user_project, user: user, project: project
end
let(:normal_user_role) { create :normal_user_role }
let!(:user_assignment) do
create :user_assignment,
assignable: project,
user: user,
user_role: normal_user_role,
user_role: create(:owner_role),
assigned_by: user
end
let(:experiment) { create :experiment, project: project }

View file

@ -12,12 +12,11 @@ describe TagsController, type: :controller do
let!(:user_project) do
create :user_project, user: user, project: project
end
let(:normal_user_role) { create :normal_user_role }
let!(:user_assignment) do
create :user_assignment,
assignable: project,
user: user,
user_role: normal_user_role,
user_role: create(:owner_role),
assigned_by: user
end
let(:experiment) { create :experiment, project: project }

View file

@ -5,17 +5,5 @@ FactoryBot.define do
user
project
assigned_by { user }
trait :owner do
role { UserProject.roles[:owner] }
end
trait :normal_user do
role { UserProject.roles[:normal_user] }
end
trait :technician do
role { UserProject.roles[:technician] }
end
trait :viewer do
role { UserProject.roles[:viewer] }
end
end
end

View file

@ -10,14 +10,13 @@ describe 'ResultPermissions' do
let(:result) { create :result, user: user, my_module: my_module }
let(:my_module) { create :my_module, experiment: experiment }
let(:experiment) { create :experiment, user: user }
let(:normal_user_role) { create :normal_user_role }
before do
create :user_project, user: user, project: experiment.project
create :user_assignment,
assignable: experiment.project,
user: user,
user_role: normal_user_role,
user_role: create(:owner_role),
assigned_by: user
end

View file

@ -13,11 +13,11 @@ RSpec.describe 'Api::V1::AssetsController', type: :request do
@step = create(:step, protocol: @protocol)
create(:user_team, user: @user, team: @team)
create(:user_project, :normal_user, user: @user, project: @project)
create(:user_project, user: @user, project: @project)
create :user_assignment,
assignable: @project,
user: @user,
user_role: create(:normal_user_role),
user_role: create(:owner_role),
assigned_by: @user
@valid_headers =

View file

@ -13,11 +13,11 @@ RSpec.describe 'Api::V1::ChecklistsController', type: :request do
@step = create(:step, protocol: @protocol)
@checklist = create(:checklist, step: @step)
create(:user_team, user: @user, team: @team)
create(:user_project, :normal_user, user: @user, project: @project)
create(:user_project, user: @user, project: @project)
create :user_assignment,
assignable: @project,
user: @user,
user_role: create(:normal_user_role),
user_role: create(:owner_role),
assigned_by: @user
@valid_headers = {

View file

@ -12,11 +12,11 @@ RSpec.describe 'Api::V1::ChecklistsController', type: :request do
@protocol = create(:protocol, my_module: @task)
@step = create(:step, protocol: @protocol)
create(:user_team, user: @user, team: @team)
create(:user_project, :normal_user, user: @user, project: @project)
create(:user_project, user: @user, project: @project)
create :user_assignment,
assignable: @project,
user: @user,
user_role: create(:normal_user_role),
user_role: create(:owner_role),
assigned_by: @user
@valid_headers = {

View file

@ -14,7 +14,7 @@ RSpec.describe 'Api::V1::StepsController', type: :request do
create :user_assignment,
assignable: @project,
user: @user,
user_role: create(:normal_user_role),
user_role: create(:owner_role),
assigned_by: @user
@valid_headers =

View file

@ -12,11 +12,11 @@ RSpec.describe 'Api::V1::TablesController', type: :request do
@protocol = create(:protocol, my_module: @task)
@step = create(:step, protocol: @protocol)
create(:user_team, user: @user, team: @team)
create(:user_project, :normal_user, user: @user, project: @project)
create(:user_project, user: @user, project: @project)
create :user_assignment,
assignable: @project,
user: @user,
user_role: create(:normal_user_role),
user_role: create(:owner_role),
assigned_by: @user
@valid_headers = {

View file

@ -9,7 +9,7 @@ RSpec.describe 'Api::V1::TasksController', type: :request do
@user = create(:user)
@teams = create_list(:team, 2, created_by: @user)
create(:user_team, user: @user, team: @teams.first, role: 2)
@owner_role = create(:owner_role)
@valid_project = create(:project, name: Faker::Name.unique.name,
created_by: @user, team: @teams.first)
@ -144,11 +144,11 @@ RSpec.describe 'Api::V1::TasksController', type: :request do
describe 'POST tasks, #create' do
before :all do
create :user_project, :normal_user, user: @user, project: @valid_project
create :user_project, user: @user, project: @valid_project
create :user_assignment,
assignable: @valid_project,
user: @user,
user_role: create(:normal_user_role),
user_role: @owner_role,
assigned_by: @user
@valid_headers['Content-Type'] = 'application/json'
end
@ -228,8 +228,9 @@ RSpec.describe 'Api::V1::TasksController', type: :request do
end
it 'renders 403 for use with view permissions' do
up = UserProject.where(user: @user, project: @valid_project).first
up.update_attribute(:role, :viewer)
user_assignment = UserAssignment.where(user: @user, assignable: @valid_project)
.first
user_assignment.update!(user_role: create(:viewer_role))
post(api_v1_team_project_experiment_tasks_path(
team_id: @teams.first.id,

View file

@ -8,8 +8,16 @@ describe SmartAnnotations::TagToText do
let!(:user_team) { create :user_team, user: user, team: team, role: 2 }
let!(:project) { create :project, name: 'my project', team: team }
let!(:user_project) do
create :user_project, project: project, user: user, role: 0
create :user_project, project: project, user: user
end
let!(:user_assignment) do
create :user_assignment,
assignable: project,
user: user,
user_role: create(:owner_role),
assigned_by: user
end
let(:text) do
"My annotation of [#my project~prj~#{project.id.base62_encode}]"
end