Remove user_team related tests [SCI-8815] (#5860)

This commit is contained in:
Soufiane 2023-07-25 14:35:17 +02:00 committed by GitHub
parent 3c655ab974
commit 4858f41b3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 0 additions and 187 deletions

View file

@ -131,9 +131,6 @@ class Users::RegistrationsController < Devise::RegistrationsController
@team.created_by = resource # set created_by for oraganization
@team.save
# Add this user to the team as owner
UserTeam.create(user: resource, team: @team, role: :admin)
# set current team to new user
resource.current_team_id = @team.id
resource.save
@ -171,9 +168,6 @@ class Users::RegistrationsController < Devise::RegistrationsController
@team.created_by = @user # set created_by for team
@team.save!
# Add this user to the team as owner
UserTeam.create(user: @user, team: @team, role: :admin)
# set current team to new user
@user.current_team_id = @team.id
@user.save!

View file

@ -6,7 +6,6 @@ Given(/^the following users are registered:$/) do |table|
team_role = hash.delete 'role'
user = FactoryBot.create(:user, hash)
team = FactoryBot.create(:team, name: team_name, users: [user])
UserTeam.where(user: user, team: team).first.update role: team_role
User.find_by(email: hash.fetch('email')).confirm
end
end
@ -87,7 +86,6 @@ end
Given(/^Templates project exists for the "([^"]*)" team$/) do |team_name|
team = Team.find_by(name: team_name)
user = team.user_teams.where(role: :admin).take.user
TemplatesService.new.schedule_creation_for_user(user)
end
Given(/^I'm on the projects page of "([^"]*)" team$/) do |team_name|
@ -99,9 +97,6 @@ end
Given(/^"([^"]*)" is in "([^"]*)" team as a "([^"]*)"$/) do |user_email, team_name, role|
team = Team.find_by(name: team_name)
user = User.find_by(email: user_email)
FactoryBot.create(:user_team, user: user,
team: team, role:
UserTeam.roles.fetch(role))
end
Then(/^I attach a "([^"]*)" file to "([^"]*)" field$/) do |file, field_id|

View file

@ -40,7 +40,6 @@ Given('the following users are registered with teams:') do |table|
team = Team.find_by(name: row[:team])
team ||= FactoryBot.create(:team, name: row[:team])
user = FactoryBot.create(:user, row.slice('name', 'email'))
FactoryBot.create(:user_team, user: user, team: team, role: row[:role])
end
end

View file

@ -1,88 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe Users::Settings::UserTeamsController, type: :controller do
login_user
let(:user) { subject.current_user }
let(:team) { create :team, created_by: user }
let!(:user_team) { create :user_team, :admin, user: user, team: team }
let(:another_user) { create :user }
let!(:another_user_team) do
create :user_team, :normal_user, user: another_user, team: team
end
describe 'DELETE destroy' do
let(:params) do
{
id: another_user_team.id
}
end
let(:action) { delete :destroy, params: params, format: :json }
context 'when inviting existing user not in the team' do
it 'calls create activity for inviting user' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :remove_user_from_team)))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
it 'remove user_team record from DB' do
expect { action }
.to(change { UserTeam.count })
end
end
context 'when user leaving team by himself' do
it 'calls create activity for user leaving' do
params_leave = { id: another_user_team.id, leave: true }
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :user_leave_team)))
delete :destroy, params: params_leave, format: :json
end
it 'adds activity in DB' do
params_leave = { id: another_user_team.id, leave: true }
expect { delete :destroy, params: params_leave, format: :json }
.to(change { Activity.count })
end
end
end
describe 'PUT update' do
let(:params) do
{
id: another_user_team.id,
user_team: {
role: 'admin'
}
}
end
let(:action) { put :update, params: params, format: :json }
context 'when updating user role in the team' do
it 'calls create activity for updating role' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type:
:change_users_role_on_team)))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
end
end

View file

@ -1,17 +0,0 @@
# frozen_string_literal: true
FactoryBot.define do
factory :user_team do
user
team
trait :admin do
role { 'admin' }
end
trait :guest do
role { 'guest' }
end
trait :normal_user do # default enum by DB
role { 'normal_user' }
end
end
end

View file

@ -14,10 +14,8 @@ module UserAssignments
before(:each) do
available_roles = [owner_role, viewer_role, technician_role]
create :user_team, :admin, user: user_two, team: team
create :user_assignment, user: user_two, assignable: project, user_role: viewer_role, assigned_by: user_one
create :user_team, :admin, user: user_three, team: team
create :user_assignment, user: user_three, assignable: project, user_role: technician_role, assigned_by: user_one
end

View file

@ -16,13 +16,6 @@ module UserAssignments
let!(:my_module_one) { create :my_module, experiment: experiment_one, created_by: experiment_one.created_by }
let!(:my_module_two) { create :my_module, experiment: experiment_two, created_by: experiment_two.created_by }
before do
[user_one, user_two].each do |user|
create :user_team, :admin, user: user, team: team
end
end
describe 'perform' do
it 'propagates the user assignments to project child object' do
expect {

View file

@ -26,7 +26,6 @@ describe Team, type: :model do
describe 'Relations' do
it { should belong_to(:created_by).class_name('User').optional }
it { should belong_to(:last_modified_by).class_name('User').optional }
it { should have_many :user_teams }
it { should have_many :users }
it { should have_many :projects }
it { should have_many :protocols }

View file

@ -46,7 +46,6 @@ describe User, type: :model do
end
describe 'Relations' do
it { should have_many :user_teams }
it { should have_many :teams }
it { should have_many :user_projects }
it { should have_many :projects }
@ -85,7 +84,6 @@ describe User, type: :model do
it { should have_many :tokens }
it { should have_many :modified_tags }
it { should have_many :assigned_user_my_modules }
it { should have_many :assigned_user_teams }
it { should have_many :assigned_user_projects }
it { should have_many :added_protocols }
it { should have_many :archived_protocols }
@ -149,21 +147,6 @@ describe User, type: :model do
end
end
describe 'teams_data should return a list of teams' do
# needs persistence because is testing a sql query
let(:team) { create :team }
let(:user_one) do
create :user, email: 'user1@asdf.com', current_team_id: team.id
end
let(:user_two) { create :user, email: 'user2@asdf.com' }
it 'should return correct number of team members' do
create :user_team, team: team, user: user_one
create :user_team, team: team, user: user_two
expect(user_one.datatables_teams.first.members).to eq 2
end
end
describe 'user settings' do
it { is_expected.to respond_to(:time_zone) }
it { is_expected.to respond_to(:assignments_notification) }

View file

@ -1,36 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe UserTeam, type: :model do
let(:user_team) { build :user_team }
it 'is valid' do
expect(user_team).to be_valid
end
it 'should be of class UserTeam' do
expect(subject.class).to eq UserTeam
end
describe 'Database table' do
it { should have_db_column :role }
it { should have_db_column :user_id }
it { should have_db_column :team_id }
it { should have_db_column :created_at }
it { should have_db_column :updated_at }
it { should have_db_column :assigned_by_id }
end
describe 'Relations' do
it { should belong_to :user }
it { should belong_to :team }
it { should belong_to(:assigned_by).class_name('User').optional }
end
describe 'Validations' do
it { should validate_presence_of :role }
it { should validate_presence_of :user }
it { should validate_presence_of :team }
end
end

View file

@ -8,7 +8,6 @@ RSpec.describe Views::Datatables::DatatablesTeam, type: :model do
it { should have_db_column :name }
it { should have_db_column :members }
it { should have_db_column :role }
it { should have_db_column :user_team_id }
it { should have_db_column :user_id }
it { should have_db_column :can_be_left }
end

View file

@ -6,7 +6,6 @@ RSpec.describe "Api::Service::ProjectsJsonExportController", type: :request do
before :all do
@user = create(:user)
@team = create(:team, created_by: @user)
create(:user_team, user: @user, team: @team, role: 1)
@accessible_project = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team)
@accessible_experiment = create(:experiment, created_by: @user,

View file

@ -6,7 +6,6 @@ RSpec.describe "Api::Service::ProtocolsController", type: :request do
before :all do
@user = create(:user)
@team = create(:team, created_by: @user)
create(:user_team, user: @user, team: @team, role: 2)
@project = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team)
@experiment = create(:experiment, created_by: @user, last_modified_by: @user, project: @project, created_by: @user)

View file

@ -6,7 +6,6 @@ RSpec.describe "Api::Service::StepsController", type: :request do
before :all do
@user = create(:user)
@team = create(:team, created_by: @user)
create(:user_team, user: @user, team: @team, role: 2)
@project = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team)
@experiment = create(:experiment, created_by: @user, last_modified_by: @user, project: @project, created_by: @user)

View file

@ -11,7 +11,6 @@ RSpec.describe 'Api::V1::StepTextsController', type: :request do
@task = @experiment.my_modules.first
@protocol = create(:protocol, my_module: @task)
@step = create(:step, protocol: @protocol)
create(:user_team, user: @user, team: @team)
@valid_headers = {
'Authorization': 'Bearer ' + generate_token(@user.id),

View file

@ -7,7 +7,6 @@ RSpec.describe 'Api::V1::TaskAssignmentsController', type: :request do
@user = create(:user)
@user_second = create(:user)
@team = create(:team, created_by: @user)
create(:user_team, user: @user, team: @team, role: 1)
@owner_role = UserRole.find_by(name: I18n.t('user_roles.predefined.owner'))
@project = create(:project, name: Faker::Name.unique.name,
created_by: @user, team: @team)

View file

@ -4,7 +4,6 @@ describe ProjectsJsonExportService do
before :all do
@user = create(:user)
@team = create(:team, created_by: @user)
create(:user_team, user: @user, team: @team, role: 1)
@accessible_project_1 = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team)
@accessible_project_2 = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team)