Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Groups/samples_count #783

Merged
merged 41 commits into from
Oct 29, 2024
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
244af6e
Add Groups samples_count tests
malchua Sep 25, 2024
7d8b79c
Update group tests with proper assertions
malchua Sep 25, 2024
3c3e4cf
Add test for project deletions and transfers
malchua Sep 25, 2024
6b81aab
Add tests for sample deletions and transfers
malchua Sep 25, 2024
6d2f43a
Add samples_count column to Namespaces table
malchua Sep 25, 2024
da3cca1
Fix query in group_test.rb
malchua Sep 26, 2024
6f4ac83
Add samples_count column to namespaces table
malchua Sep 26, 2024
c002c61
Add samples_count to Groups row component
malchua Sep 26, 2024
9bee8d4
Create test for group samples_count after sample creation
malchua Sep 27, 2024
308993d
Update group samples_count after sample creation
malchua Sep 27, 2024
a048859
Fix samples destroy service test
malchua Sep 27, 2024
d39018b
Update groups' samples_count after sample deletions
malchua Sep 27, 2024
6d54723
Fix sample transfer service test
malchua Sep 27, 2024
b663280
Update samples_count for groups when samples are transferred
malchua Sep 27, 2024
d2799f6
Fix samples clone service test
malchua Sep 27, 2024
2b0926b
Update samples_count when samples are cloned
malchua Sep 27, 2024
e6e670c
Fix project transfer service tests
malchua Sep 30, 2024
ab84cfd
Update samples_count after a project transfer
malchua Sep 30, 2024
00c3303
Fix group tests
malchua Oct 1, 2024
87b833c
Update samples_count after project deletion
malchua Oct 1, 2024
f1b986d
Update samples_count after group transfer
malchua Oct 1, 2024
6929e41
Update samples_count after group deletion
malchua Oct 1, 2024
6945cdb
Fix errors in groups tests
malchua Oct 2, 2024
1b684aa
Address rubocop warnings
malchua Oct 3, 2024
980e774
Fix project destroy_service to update samples_count properly
malchua Oct 3, 2024
2e00f5d
Add UI testing for group deletions
malchua Oct 8, 2024
ab31762
Add more ui tests
malchua Oct 16, 2024
f5eb6fc
Fix bug with displaying project samples_count
malchua Oct 17, 2024
41696fa
Create migration to reset group samples counters
malchua Oct 17, 2024
90c23be
Update projects fixture to allow for samples counter reset migration
malchua Oct 17, 2024
f8f0ccd
Update schema by running reset samples counter migration file
malchua Oct 17, 2024
1ea3a65
Add UI tests for Groups: Subgroups and projects tab
malchua Oct 17, 2024
d66a76e
Clean up dashboard/groups_test.rb file
malchua Oct 17, 2024
458d56e
Add samples_counts to the groups fixture
malchua Oct 18, 2024
911ad80
Add test to ensure test projects' samples_counts are accurate
malchua Oct 18, 2024
bcb1723
Update test to ensure test groups' samples_counts are accurate
malchua Oct 18, 2024
6ef9571
Revert certain tests now that samples_count in the groups fixture has…
malchua Oct 18, 2024
5d09521
Simplify deleted_samples_count calculation
malchua Oct 18, 2024
c8421d2
Refactor service tests to reuse common variables
malchua Oct 18, 2024
59a7065
Add edge cases for updating samples_count after tranferring projects
malchua Oct 21, 2024
59587ac
Add edge cases for updating samples_count after tranferring samples
malchua Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -58,6 +58,14 @@

<div class="flex flex-row-reverse gap-x-3 text-slate-500">
<% if @namespace.type == "Group" %>
<%= viral_tooltip(title: t(:'.stats.samples')) do %>
<span
id="<%= "#{dom_id(@namespace)}-samples-count" %>"
class="flex items-center text-sm samples-count"
>
<%= viral_icon(name: :beaker, color: :subdued, classes: "h-5 w-5") %><%= @namespace.samples_count %>
</span>
<% end %>
<%= viral_tooltip(title: t(:'.stats.projects')) do %>
<span class="flex items-center text-sm">
<%= viral_icon(name: :rectangle_stack, color: :subdued, classes: "h-5 w-5") %>
@@ -73,7 +81,7 @@
<% if @namespace.type == "Project" %>
<%= viral_tooltip(title: t(:'.stats.samples')) do %>
<span class="flex items-center text-sm">
<%= viral_icon(name: :beaker, color: :subdued, classes: "h-5 w-5") %><%= @sample_count %>
<%= viral_icon(name: :beaker, color: :subdued, classes: "h-5 w-5") %><%= @namespace.project.samples.size %>
</span>
<% end %>
<% end %>
5 changes: 1 addition & 4 deletions app/components/namespace_tree/row/row_contents_component.rb
Original file line number Diff line number Diff line change
@@ -4,16 +4,13 @@ module NamespaceTree
module Row
# Component for the contents of NamespaceTree row
class RowContentsComponent < Viral::Component
# rubocop: disable Metrics/ParameterLists
def initialize(namespace:, path: nil, path_args: {}, collapsed: false, sample_count: 0, icon_size: :small)
def initialize(namespace:, path: nil, path_args: {}, collapsed: false, icon_size: :small)
@namespace = namespace
@path = path
@path_args = path_args
@collapsed = collapsed
@sample_count = sample_count
@icon_size = icon_size
end
# rubocop: enable Metrics/ParameterLists
end
end
end
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
namespace: @namespace,
path: @path,
path_args: @path_args,
sample_count: @sample_count,
icon_size: @icon_size,
) %>
</div>
42 changes: 41 additions & 1 deletion app/models/group.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Namespace for Groups
class Group < Namespace
class Group < Namespace # rubocop:disable Metrics/ClassLength
include History

has_many :group_members, foreign_key: :namespace_id, inverse_of: :group,
@@ -107,4 +107,44 @@ def retrieve_group_activity
)
)
end

def add_to_samples_count(namespaces, addition_amount)
namespaces.each do |namespace|
namespace.samples_count += addition_amount
namespace.save
end
end

def subtract_from_samples_count(namespaces, subtraction_amount)
namespaces.each do |namespace|
namespace.samples_count -= subtraction_amount
namespace.save
end
end

def update_samples_count_by_addition_services(added_samples_count = 1)
namespaces_to_update = self_and_ancestors.where(type: Group.sti_name)
add_to_samples_count(namespaces_to_update, added_samples_count)
end

def update_samples_count_by_destroy_service(deleted_samples_count)
namespaces_to_update = self_and_ancestors.where(type: Group.sti_name)
subtract_from_samples_count(namespaces_to_update, deleted_samples_count)
end

def update_samples_count_by_transfer_service(destination, transferred_samples_count, destination_type = 'Project')
namespaces_to_update = self_and_ancestors.where(type: Group.sti_name)
subtract_from_samples_count(namespaces_to_update, transferred_samples_count)

case destination_type
when 'Project'
namespaces_to_update = destination.parent.self_and_ancestors.where(type: Group.sti_name)
when 'Group'
namespaces_to_update = destination.self_and_ancestors.where(type: Group.sti_name)
else
return
end

add_to_samples_count(namespaces_to_update, transferred_samples_count)
end
end
7 changes: 7 additions & 0 deletions app/services/groups/destroy_service.rb
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ class DestroyService < BaseService
def initialize(group, user = nil, params = {})
super(user, params.except(:group, :group_id))
@group = group
@deleted_samples_count = @group.samples_count
end

def execute
@@ -26,9 +27,15 @@ def execute
removed_group_puid: @group.puid,
action: 'group_subgroup_destroy'
}

update_samples_count
end

group.update_metadata_summary_by_namespace_deletion
end

def update_samples_count
@group.update_samples_count_by_destroy_service(@deleted_samples_count)
end
end
end
13 changes: 13 additions & 0 deletions app/services/groups/transfer_service.rb
Original file line number Diff line number Diff line change
@@ -31,6 +31,8 @@ def execute(new_namespace) # rubocop:disable Metrics/AbcSize, Metrics/MethodLeng

UpdateMembershipsJob.perform_later(new_namespace_member_ids)

update_samples_count(old_namespace, new_namespace)

new_namespace.update_metadata_summary_by_namespace_transfer(@group, old_namespace)

true
@@ -103,5 +105,16 @@ def create_activities(old_namespace, new_namespace) # rubocop:disable Metrics/Me
}
end
end

def update_samples_count(old_namespace, new_namespace)
transferred_samples_count = Project.joins(:namespace).where(namespace: { parent_id: @group.self_and_descendants })
.select(:samples_count).pluck(:samples_count).sum
if old_namespace
old_namespace.update_samples_count_by_transfer_service(new_namespace, transferred_samples_count,
new_namespace.type)
elsif new_namespace.type == 'Group'
new_namespace.update_samples_count_by_addition_services(transferred_samples_count)
end
end
end
end
10 changes: 9 additions & 1 deletion app/services/projects/destroy_service.rb
Original file line number Diff line number Diff line change
@@ -3,15 +3,19 @@
module Projects
# Service used to Delete Projects
class DestroyService < BaseProjectService
def execute
def execute # rubocop:disable Metrics/AbcSize
authorize! project, to: :destroy?

deleted_samples_count = @project.samples.size

project.namespace.destroy!

create_activities if project.namespace.deleted?

return unless project.namespace.deleted? && project.namespace.type != Namespaces::UserNamespace.sti_name

update_samples_count(deleted_samples_count) if @project.parent.type == 'Group'

project.namespace.update_metadata_summary_by_namespace_deletion
end

@@ -28,5 +32,9 @@ def create_activities
action: 'group_project_destroy'
}
end

def update_samples_count(deleted_samples_count)
@project.parent.update_samples_count_by_destroy_service(deleted_samples_count)
end
end
end
14 changes: 13 additions & 1 deletion app/services/projects/transfer_service.rb
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ class TransferService < BaseProjectService
TransferError = Class.new(StandardError)
attr_reader :new_namespace, :old_namespace

def execute(new_namespace) # rubocop:disable Metrics/AbcSize
def execute(new_namespace) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
@new_namespace = new_namespace
@old_namespace = @project.parent

@@ -27,6 +27,8 @@ def execute(new_namespace) # rubocop:disable Metrics/AbcSize

@new_namespace.update_metadata_summary_by_namespace_transfer(@project.namespace, @old_namespace)

update_samples_count

true
rescue Projects::TransferService::TransferError => e
project.errors.add(:new_namespace, e.message)
@@ -84,5 +86,15 @@ def create_activities(project) # rubocop:disable Metrics/MethodLength
action: 'project_namespace_transfer'
}
end

def update_samples_count
transferred_samples_count = @project.samples.size
if @old_namespace.type == 'Group'
@old_namespace.update_samples_count_by_transfer_service(@new_namespace, transferred_samples_count,
@new_namespace.type)
elsif @new_namespace.type == 'Group'
@new_namespace.update_samples_count_by_addition_services(transferred_samples_count)
end
end
end
end
12 changes: 10 additions & 2 deletions app/services/samples/clone_service.rb
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ def validate(new_project_id, sample_ids)
raise CloneError, I18n.t('services.samples.clone.same_project')
end

def clone_samples(sample_ids)
def clone_samples(sample_ids) # rubocop:disable Metrics/AbcSize
cloned_sample_ids = {}
cloned_sample_puids = {}

@@ -42,7 +42,11 @@ def clone_samples(sample_ids)
cloned_sample_puids[sample.puid] = cloned_sample.puid unless cloned_sample.nil?
end

create_activities(cloned_sample_ids, cloned_sample_puids) if cloned_sample_ids.count.positive?
if cloned_sample_ids.count.positive?
update_samples_count(cloned_sample_ids.count) if @new_project.parent.type == 'Group'

create_activities(cloned_sample_ids, cloned_sample_puids)
end

cloned_sample_ids
end
@@ -69,6 +73,10 @@ def clone_attachments(sample, clone)
Attachments::CreateService.new(current_user, clone, { files:, include_activity: false }).execute
end

def update_samples_count(cloned_samples_count)
@new_project.parent.update_samples_count_by_addition_services(cloned_samples_count)
end

def create_activities(cloned_sample_ids, cloned_sample_puids) # rubocop:disable Metrics/MethodLength
@project.namespace.create_activity key: 'namespaces_project_namespace.samples.clone',
owner: current_user,
6 changes: 6 additions & 0 deletions app/services/samples/create_service.rb
Original file line number Diff line number Diff line change
@@ -25,7 +25,13 @@ def execute
}
end

update_samples_count if @project.parent.type == 'Group'

sample
end

def update_samples_count
@project.parent.update_samples_count_by_addition_services
end
end
end
8 changes: 8 additions & 0 deletions app/services/samples/destroy_service.rb
Original file line number Diff line number Diff line change
@@ -33,6 +33,8 @@ def destroy_single
}
end

update_samples_count if @project.parent.type == 'Group'

update_metadata_summary(sample)
end

@@ -48,6 +50,8 @@ def destroy_multiple # rubocop:disable Metrics/MethodLength
samples_deleted_puids << sample.puid
end

update_samples_count(samples_to_delete_count) if @project.parent.type == 'Group'

@project.namespace.create_activity key: 'namespaces_project_namespace.samples.destroy_multiple',
owner: current_user,
parameters:
@@ -63,5 +67,9 @@ def destroy_multiple # rubocop:disable Metrics/MethodLength
def update_metadata_summary(sample)
sample.project.namespace.update_metadata_summary_by_sample_deletion(sample) if sample.deleted?
end

def update_samples_count(deleted_samples_count = 1)
@project.parent.update_samples_count_by_destroy_service(deleted_samples_count)
end
end
end
9 changes: 9 additions & 0 deletions app/services/samples/transfer_service.rb
Original file line number Diff line number Diff line change
@@ -77,6 +77,7 @@ def transfer(new_project_id, sample_ids) # rubocop:disable Metrics/MethodLength,

@project.namespace.update_metadata_summary_by_sample_transfer(transferred_samples_ids,
new_project_id)
update_samples_count(transferred_samples_ids.count)
end

transferred_samples_ids
@@ -103,5 +104,13 @@ def create_activities(transferred_samples_ids, transferred_samples_puids) # rubo
action: 'sample_transfer'
}
end

def update_samples_count(transferred_samples_count)
if @project.parent.type == 'Group'
@project.parent.update_samples_count_by_transfer_service(@new_project, transferred_samples_count)
elsif @new_project.parent.type == 'Group'
@new_project.parent.update_samples_count_by_addition_services(transferred_samples_count)
end
end
end
end
8 changes: 8 additions & 0 deletions db/migrate/20240925230422_add_samples_count_to_namespaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

# migration to add samples count to namespaces table
class AddSamplesCountToNamespaces < ActiveRecord::Migration[7.2]
def change
add_column :namespaces, :samples_count, :integer, default: 0
end
end
ChrisHuynh333 marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 13 additions & 0 deletions db/migrate/20241004162923_reset_all_group_samples_counters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

# migration to reset the samples_count to the total number of samples found in all
# subgroups and projects, for each group
class ResetAllGroupSamplesCounters < ActiveRecord::Migration[7.2]
def up
Group.all.each do |group|
group.samples_count = Project.joins(:namespace).where(namespace: { parent_id: group.self_and_descendants })
.select(:samples_count).pluck(:samples_count).sum
group.save!
end
end
end
37 changes: 19 additions & 18 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions test/fixtures/groups.yml
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ group_one:
metadata_summary: { "metadatafield1": 633, "metadatafield2": 106 }
puid: INXT_GRP_AAAAAAAAAA
attachments_updated_at: <%= 2.hours.ago %>
samples_count: 25

subgroup1:
<<: *DEFAULTS
@@ -21,6 +22,7 @@ subgroup1:
description: Subgroup 1 description
parent_id: <%= ActiveRecord::FixtureSet.identify(:group_one, :uuid) %>
puid: INXT_GRP_AAAAAAAAAB
samples_count: 2

<% (Namespace::MAX_ANCESTORS-1).times do |n| %>
subgroup<%= (n+2) %>:
@@ -30,6 +32,7 @@ subgroup<%= (n+2) %>:
description: <%= "Subgroup #{n+2} description" %>
parent_id: <%= ActiveRecord::FixtureSet.identify("subgroup#{n+1}", :uuid) %>
puid: <%= "INXT_GRP_AAAAAA#{((n/26).round+66).chr}AA#{((n%26)+65).chr}" %>
samples_count: 0
<% end %>

group_two:
@@ -38,13 +41,15 @@ group_two:
path: group-2
description: Group 2 description
puid: INXT_GRP_AAAAAAAAAC
samples_count: 0

group_three:
<<: *DEFAULTS
name: Group 3
path: group-3
description: Group 3 description
puid: INXT_GRP_AAAAAAAAAD
samples_count: 1

subgroup_one_group_three:
<<: *DEFAULTS
@@ -53,6 +58,7 @@ subgroup_one_group_three:
description: Subgroup 1 Group 3
parent_id: <%= ActiveRecord::FixtureSet.identify(:group_three, :uuid) %>
puid: INXT_GRP_AAAAAAAAAE
samples_count: 1

david_doe_group_four:
<<: *DEFAULTS
@@ -61,13 +67,15 @@ david_doe_group_four:
description: David's first group
puid: INXT_GRP_AAAAAAAAAF
metadata_summary: { "unique_metadata_field": 1 }
samples_count: 1

group_five:
<<: *DEFAULTS
name: Group 5
path: group-5
description: Group 5 description
puid: INXT_GRP_AAAAAAAAAG
samples_count: 0

subgroup_one_group_five:
<<: *DEFAULTS
@@ -76,13 +84,15 @@ subgroup_one_group_five:
description: Subgroup 1 Group 5
parent_id: <%= ActiveRecord::FixtureSet.identify(:group_five, :uuid) %>
puid: INXT_GRP_AAAAAAAAAH
samples_count: 0

group_six:
<<: *DEFAULTS
name: Group 6
path: group-6
description: Group 6 description
puid: INXT_GRP_AAAAAAAAAI
samples_count: 0

subgroup_one_group_six:
<<: *DEFAULTS
@@ -91,20 +101,23 @@ subgroup_one_group_six:
description: Subgroup 1 description
parent_id: <%= ActiveRecord::FixtureSet.identify(:group_six, :uuid) %>
puid: INXT_GRP_AAAAAAAAAJ
samples_count: 0

group_seven:
<<: *DEFAULTS
name: Group 7
path: group-7
description: Group 7 description
puid: INXT_GRP_AAAAAAAAAK
samples_count: 0

group_eight:
<<: *DEFAULTS
name: Group 8
path: group-8
description: Group 8 description
puid: INXT_GRP_AAAAAAAAAL
samples_count: 0

<% [*("a".."z")].each_with_index do |letter, index| %>
group_<%= letter %>:
@@ -115,6 +128,7 @@ group_<%= letter %>:
created_at: <%= (index + 1).days.ago %>
updated_at: <%= (index + 1).days.ago %>
puid: <%= "INXT_GRP_AAAAAAABA#{letter.capitalize}" %>
samples_count: 0
<% end %>

namespace_group_link_group_one:
@@ -123,27 +137,31 @@ namespace_group_link_group_one:
path: group-one
description: Group One description
puid: INXT_GRP_AAAAAAAAAM
samples_count: 0

namespace_group_link_group_two:
<<: *DEFAULTS
name: Group Two
path: group-two
description: Group Two description
puid: INXT_GRP_AAAAAAAAAN
samples_count: 0

namespace_group_link_group_three:
<<: *DEFAULTS
name: Group Three
path: group-three
description: Group Three description
puid: INXT_GRP_AAAAAAAAAO
samples_count: 0

group_nine:
<<: *DEFAULTS
name: Group 9
path: group-9
description: Group 9 description
puid: INXT_GRP_AAAAAAAAAP
samples_count: 0

subgroup_one_group_nine:
<<: *DEFAULTS
@@ -152,6 +170,7 @@ subgroup_one_group_nine:
description: Subgroup 1 Group 9 description
parent_id: <%= ActiveRecord::FixtureSet.identify(:group_nine, :uuid) %>
puid: INXT_GRP_AAAAAAAAAQ
samples_count: 0

group_ten:
<<: *DEFAULTS
@@ -160,41 +179,47 @@ group_ten:
description: Group 10 description
parent_id: <%= ActiveRecord::FixtureSet.identify(:subgroup_one_group_nine, :uuid) %>
puid: INXT_GRP_AAAAAAAAAR
samples_count: 0

group_alpha:
<<: *DEFAULTS
name: Group Alpha
path: group-alpha
description: Group Alpha description
puid: INXT_GRP_AAAAAAAAAS
samples_count: 2

group_bravo:
<<: *DEFAULTS
name: Group Bravo
path: group-bravo
description: Group bravo description
puid: INXT_GRP_AAAAAAAAAT
samples_count: 1

group_charlie:
<<: *DEFAULTS
name: Group Charlie
path: group-charlie
description: Group Charlie description
puid: INXT_GRP_AAAAAAAAAU
samples_count: 1

group_alpha_subgroup1:
<<: *DEFAULTS
name: Subgroup 1
path: group-alpha/subgroup-1
description: Subgroup 1 description
puid: INXT_GRP_AAAAAAAAAV
samples_count: 1

group_eleven:
<<: *DEFAULTS
name: Group 11
path: group-11
description: Group 11 description
puid: INXT_GRP_AAAAAAAAAW
samples_count: 0

group_twelve:
<<: *DEFAULTS
@@ -204,6 +229,7 @@ group_twelve:
owner_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
metadata_summary: { "metadatafield1": 3, "metadatafield2": 3 }
puid: INXT_GRP_AAAAAAAAAX
samples_count: 4

subgroup_twelve_a:
<<: *DEFAULTS
@@ -214,6 +240,7 @@ subgroup_twelve_a:
parent_id: <%= ActiveRecord::FixtureSet.identify(:group_twelve, :uuid) %>
metadata_summary: { "metadatafield1": 2, "metadatafield2": 2 }
puid: INXT_GRP_AAAAAAAAAY
samples_count: 3

subgroup_twelve_b:
<<: *DEFAULTS
@@ -224,6 +251,7 @@ subgroup_twelve_b:
parent_id: <%= ActiveRecord::FixtureSet.identify(:group_twelve, :uuid) %>
metadata_summary: { "metadatafield1": 1, "metadatafield2": 1 }
puid: INXT_GRP_AAAAAAAAAZ
samples_count: 1

subgroup_twelve_a_a:
<<: *DEFAULTS
@@ -234,13 +262,15 @@ subgroup_twelve_a_a:
parent_id: <%= ActiveRecord::FixtureSet.identify(:subgroup_twelve_a, :uuid) %>
metadata_summary: { "metadatafield1": 1, "metadatafield2": 1 }
puid: INXT_GRP_AAAAAAAAA2
samples_count: 2

group_delta:
<<: *DEFAULTS
name: Group Delta
path: group-delta
description: Group Delta description
puid: INXT_GRP_AAAAAAAAA3
samples_count: 0

group_delta_subgroupA:
<<: *DEFAULTS
@@ -249,13 +279,15 @@ group_delta_subgroupA:
description: Subgroup A description
parent_id: <%= ActiveRecord::FixtureSet.identify(:group_delta, :uuid) %>
puid: INXT_GRP_AAAAAAAAA4
samples_count: 0

group_echo:
<<: *DEFAULTS
name: Group Echo
path: group-echo
description: Group Echo description
puid: INXT_GRP_AAAAAAAAA5
samples_count: 0

group_echo_subgroupB:
<<: *DEFAULTS
@@ -264,13 +296,15 @@ group_echo_subgroupB:
description: Subgroup B description
parent_id: <%= ActiveRecord::FixtureSet.identify(:group_echo, :uuid) %>
puid: INXT_GRP_AAAAAAAAA6
samples_count: 0

group_foxtrot:
<<: *DEFAULTS
name: Group Foxtrot
path: group-foxtrot
description: Group Foxtrot description
puid: INXT_GRP_AAAAAAAAA7
samples_count: 0

group_foxtrot_subgroupA:
<<: *DEFAULTS
@@ -279,13 +313,15 @@ group_foxtrot_subgroupA:
description: Subgroup A description
parent_id: <%= ActiveRecord::FixtureSet.identify(:group_foxtrot, :uuid) %>
puid: INXT_GRP_AAAAAAAABA
samples_count: 0

group_golf:
<<: *DEFAULTS
name: Group Golf
path: group-golf
description: Group Golf description
puid: INXT_GRP_AAAAAAAABB
samples_count: 0

group_hotel:
<<: *DEFAULTS
@@ -294,27 +330,31 @@ group_hotel:
description: Group Hotel description
owner_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
puid: INXT_GRP_AAAAAAAABC
samples_count: 1

group_thirteen:
<<: *DEFAULTS
name: Group 13
path: group-13
description: Group 13 description
puid: INXT_GRP_AAAAAAAABD
samples_count: 0

group_fourteen:
<<: *DEFAULTS
name: Group 14
path: group-14
description: Group 14 description
puid: INXT_GRP_AAAAAAAABE
samples_count: 1

group_fifteen:
<<: *DEFAULTS
name: Group 15
path: group-15
description: Group 15 description
puid: INXT_GRP_AAAAAAAABF
samples_count: 3

group_sixteen:
<<: *DEFAULTS
@@ -323,6 +363,7 @@ group_sixteen:
description: Group 16 description
owner_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
puid: INXT_GRP_AAAAAAAABG
samples_count: 3

group_seventeen:
<<: *DEFAULTS
@@ -331,6 +372,7 @@ group_seventeen:
description: Group 17 description
owner_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
puid: INXT_GRP_AAAAAAAABI
samples_count: 200

user30_group_one:
<<: *DEFAULTS
@@ -339,6 +381,7 @@ user30_group_one:
description: Group 1 description
owner_id: <%= ActiveRecord::FixtureSet.identify(:user30, :uuid) %>
puid: INXT_GRP_AAAAAAAABH
samples_count: 0

janitor_doe_group:
<<: *DEFAULTS
@@ -347,6 +390,7 @@ janitor_doe_group:
description: Group 1 description
owner_id: <%= ActiveRecord::FixtureSet.identify(:janitor_doe, :uuid) %>
puid: INXT_GRP_ABAAAAAAAA
samples_count: 0

empty_group:
<<: *DEFAULTS
@@ -355,6 +399,7 @@ empty_group:
description: Group without any Samples
owner_id: <%= ActiveRecord::FixtureSet.identify(:empty_doe, :uuid) %>
puid: INXT_GRP_AAAAAAAABHI
samples_count: 0

group_jeff:
<<: *DEFAULTS
@@ -363,3 +408,4 @@ group_jeff:
description: Group Jeff description
owner_id: <%= ActiveRecord::FixtureSet.identify(:jeff_doe, :uuid) %>
puid: INXT_GRP_AAAAAAJEFF
samples_count: 0
58 changes: 58 additions & 0 deletions test/fixtures/projects.yml
Original file line number Diff line number Diff line change
@@ -3,231 +3,289 @@
project1:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project1_namespace, :uuid) %>
samples_count: 3

project2:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project2_namespace, :uuid) %>
samples_count: 20

john_doe_project2:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:john_doe_project2_namespace, :uuid) %>
samples_count: 1

john_doe_project3:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:john_doe_project3_namespace, :uuid) %>
samples_count: 0

john_doe_project4:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:john_doe_project4_namespace, :uuid) %>
samples_count: 0

project4:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project4_namespace, :uuid) %>
samples_count: 1

project5:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project5_namespace, :uuid) %>
samples_count: 0

project6:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project6_namespace, :uuid) %>
samples_count: 0

project7:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project7_namespace, :uuid) %>
samples_count: 0

project8:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project8_namespace, :uuid) %>
samples_count: 0

project9:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project9_namespace, :uuid) %>
samples_count: 0

project10:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project10_namespace, :uuid) %>
samples_count: 0

project11:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project11_namespace, :uuid) %>
samples_count: 0

project12:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project12_namespace, :uuid) %>
samples_count: 0

project13:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project13_namespace, :uuid) %>
samples_count: 0

project14:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project14_namespace, :uuid) %>
samples_count: 0

project15:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project15_namespace, :uuid) %>
samples_count: 0

project16:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project16_namespace, :uuid) %>
samples_count: 0

project17:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project17_namespace, :uuid) %>
samples_count: 0

project18:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project18_namespace, :uuid) %>
samples_count: 0

project19:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project19_namespace, :uuid) %>
samples_count: 0

project20:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project20_namespace, :uuid) %>
samples_count: 0

project21:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project21_namespace, :uuid) %>
samples_count: 0

project22:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project22_namespace, :uuid) %>
samples_count: 0

project23:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project23_namespace, :uuid) %>
samples_count: 0

project24:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project24_namespace, :uuid) %>
samples_count: 0

project25:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project25_namespace, :uuid) %>
samples_count: 2

project26:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project26_namespace, :uuid) %>
samples_count: 3

project32:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project32_namespace, :uuid) %>
samples_count: 0

projectA:
creator_id: <%= ActiveRecord::FixtureSet.identify(:jeff_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectA_namespace, :uuid) %>
samples_count: 3

namespace_group_link_group_one_project1:
creator_id: <%= ActiveRecord::FixtureSet.identify(:user24, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:namespace_group_link_group_one_project1_namespace, :uuid) %>
samples_count: 0

namespace_group_link_group_three_project1:
creator_id: <%= ActiveRecord::FixtureSet.identify(:user24, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:namespace_group_link_group_three_project1_namespace, :uuid) %>
samples_count: 0

project28:
creator_id: <%= ActiveRecord::FixtureSet.identify(:david_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project28_namespace, :uuid) %>
samples_count: 1

project29:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project29_namespace, :uuid) %>
samples_count: 1

project30:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project30_namespace, :uuid) %>
samples_count: 1

project31:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project31_namespace, :uuid) %>
samples_count: 2

projectAlpha:
creator_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectAlpha_namespace, :uuid) %>
samples_count: 1

projectBravo:
creator_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectBravo_namespace, :uuid) %>
samples_count: 1

projectCharlie:
creator_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectCharlie_namespace, :uuid) %>
samples_count: 1

projectAlpha1:
creator_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectAlpha1_namespace, :uuid) %>
samples_count: 1

projectDelta:
creator_id: <%= ActiveRecord::FixtureSet.identify(:private_joan, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectDelta_namespace, :uuid) %>
samples_count: 0

projectEcho:
creator_id: <%= ActiveRecord::FixtureSet.identify(:private_joan, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectEcho_namespace, :uuid) %>
samples_count: 0

projectDeltaSubgroupA:
creator_id: <%= ActiveRecord::FixtureSet.identify(:private_joan, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectDeltaSubgroupA_namespace, :uuid) %>
samples_count: 0

projectEchoSubgroupB:
creator_id: <%= ActiveRecord::FixtureSet.identify(:private_joan, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectEchoSubgroupB_namespace, :uuid) %>
samples_count: 0

projectFoxtrotSubgroupA:
creator_id: <%= ActiveRecord::FixtureSet.identify(:private_micha, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectFoxtrotSubgroupA_namespace, :uuid) %>
samples_count: 0

project27:
creator_id: <%= ActiveRecord::FixtureSet.identify(:user27, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:user27_project1_namespace, :uuid) %>
samples_count: 0

projectHotel:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectHotel_namespace, :uuid) %>
samples_count: 1

projectJeff:
creator_id: <%= ActiveRecord::FixtureSet.identify(:jeff_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project_jeff_namespace, :uuid) %>
samples_count: 1

project33:
creator_id: <%= ActiveRecord::FixtureSet.identify(:jane_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project33_namespace, :uuid) %>
samples_count: 0

project34:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project34_namespace, :uuid) %>
samples_count: 1

project35:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project35_namespace, :uuid) %>
samples_count: 3

project36:
creator_id: <%= ActiveRecord::FixtureSet.identify(:jeff_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project_jeff_namespace, :uuid) %>
samples_count: 2

project37:
creator_id: <%= ActiveRecord::FixtureSet.identify(:user21, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project37_namespace, :uuid) %>
samples_count: 3

project38:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project38_namespace, :uuid) %>
samples_count: 200

user29_project1:
creator_id: <%= ActiveRecord::FixtureSet.identify(:user29, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:user29_project1_namespace, :uuid) %>
samples_count: 1

project_janitor_end_to_end:
creator_id: <%= ActiveRecord::FixtureSet.identify(:janitor_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project_janitor_namespace, :uuid) %>
samples_count: 1

project_janitor_DELETE:
creator_id: <%= ActiveRecord::FixtureSet.identify(:janitor_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project_janitor_namespace, :uuid) %>
samples_count: 4

empty_project:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:empty_project_namespace, :uuid) %>
samples_count: 0
35 changes: 35 additions & 0 deletions test/models/group_test.rb
Original file line number Diff line number Diff line change
@@ -4,9 +4,12 @@

class GroupTest < ActiveSupport::TestCase
def setup
@user = users(:john_doe)
@group = groups(:group_one)
@subgroup_one = groups(:subgroup1)
@group_three = groups(:group_three)
@group_three_subgroup1 = groups(:subgroup_one_group_three)
@sample23 = samples(:sample23)
end

test 'valid group' do
@@ -206,4 +209,36 @@ def setup
test '#metadata_summary incorporates fields from shared projects' do
assert_equal %w[metadatafield1 metadatafield2], groups(:group_alpha).metadata_fields
end

test 'update samples_count by sample transfer' do
project = projects(:project22)
assert_difference -> { @group_three.reload.samples_count } => -1,
-> { @group_three_subgroup1.reload.samples_count } => -1 do
@group_three_subgroup1.update_samples_count_by_transfer_service(project, 1)
end
end

test 'update samples_count by sample deletion' do
assert_difference -> { @group_three.reload.samples_count } => -1,
-> { @group_three_subgroup1.reload.samples_count } => -1 do
@group_three_subgroup1.update_samples_count_by_destroy_service(1)
end
end

test 'update samples_count by sample addition' do
assert_difference -> { @group_three.reload.samples_count } => 1,
-> { @group_three_subgroup1.reload.samples_count } => 1 do
@group_three_subgroup1.update_samples_count_by_addition_services(1)
end
end

test 'samples_count for each group fixture should be correct' do
# If you've added samples to fixtures, update the sample_count to the corresponding project/groups
Group.find_each do |group|
current_samples_count = group.samples_count
expected_samples_count = Project.joins(:namespace).where(namespace: { parent_id: group.self_and_descendants })
.select(:samples_count).pluck(:samples_count).sum
assert_equal current_samples_count, expected_samples_count
end
end
end
10 changes: 10 additions & 0 deletions test/models/project_test.rb
Original file line number Diff line number Diff line change
@@ -57,4 +57,14 @@ def setup

assert project_namespace.reload.deleted?
end

test 'samples_count for each project fixture should be correct' do
# If you've added samples to fixtures, update the sample_count to the corresponding project/groups
Project.find_each do |project|
current_samples_count = project.samples.size
Project.reset_counters(project.id, :samples)
expected_samples_count = project.reload.samples.size
assert_equal current_samples_count, expected_samples_count
end
end
end
29 changes: 24 additions & 5 deletions test/services/groups/destroy_service_test.rb
Original file line number Diff line number Diff line change
@@ -7,6 +7,11 @@ class DestroyServiceTest < ActiveSupport::TestCase
def setup
@user = users(:john_doe)
@group = groups(:group_two)

@group12 = groups(:group_twelve)
@subgroup12a = groups(:subgroup_twelve_a)
@subgroup12b = groups(:subgroup_twelve_b)
@subgroup12aa = groups(:subgroup_twelve_a_a)
end

test 'delete group with correct permissions' do
@@ -42,11 +47,6 @@ def setup
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
@group12 = groups(:group_twelve)
@subgroup12a = groups(:subgroup_twelve_a)
@subgroup12b = groups(:subgroup_twelve_b)
@subgroup12aa = groups(:subgroup_twelve_a_a)

assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12aa.metadata_summary)
assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, @subgroup12a.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12b.metadata_summary)
@@ -60,5 +60,24 @@ def setup
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12a.reload.metadata_summary)
assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, @group12.reload.metadata_summary)
end

test 'samples count updated after group deletion' do
# Reference group/projects descendants tree:
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
assert_equal(2, @subgroup12aa.samples_count)
assert_equal(3, @subgroup12a.samples_count)
assert_equal(1, @subgroup12b.samples_count)
assert_equal(4, @group12.samples_count)

assert_no_changes -> { @subgroup12b.reload.samples_count } do
Groups::DestroyService.new(@subgroup12aa, @user).execute
end

assert(@subgroup12aa.reload.deleted?)
assert_equal(1, @subgroup12a.reload.samples_count)
assert_equal(2, @group12.reload.samples_count)
end
end
end
41 changes: 36 additions & 5 deletions test/services/groups/transfer_service_test.rb
Original file line number Diff line number Diff line change
@@ -8,6 +8,11 @@ def setup
@john_doe = users(:john_doe)
@jane_doe = users(:jane_doe)
@group = groups(:group_one)

@group12 = groups(:group_twelve)
@subgroup12a = groups(:subgroup_twelve_a)
@subgroup12b = groups(:subgroup_twelve_b)
@subgroup12aa = groups(:subgroup_twelve_a_a)
end

test 'transfer group with permission' do
@@ -85,11 +90,6 @@ def setup
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
@group12 = groups(:group_twelve)
@subgroup12a = groups(:subgroup_twelve_a)
@subgroup12b = groups(:subgroup_twelve_b)
@subgroup12aa = groups(:subgroup_twelve_a_a)

assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12aa.metadata_summary)
assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, @subgroup12a.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12b.metadata_summary)
@@ -115,5 +115,36 @@ def setup

assert_equal({ 'metadatafield1' => 3, 'metadatafield2' => 3 }, @subgroup12a.reload.metadata_summary)
end

test 'samples count updates after group transfer' do
# Reference group/projects descendants tree:
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
assert_equal(2, @subgroup12aa.samples_count)
assert_equal(3, @subgroup12a.samples_count)
assert_equal(1, @subgroup12b.samples_count)
assert_equal(4, @group12.samples_count)

assert_no_changes -> { @group12.reload.samples_count } do
assert_no_changes -> { @subgroup12aa.reload.samples_count } do
Groups::TransferService.new(@subgroup12aa, @john_doe).execute(@subgroup12b)
end
end

assert_equal(2, @subgroup12aa.samples_count)
assert_equal(1, @subgroup12a.reload.samples_count)
assert_equal(3, @subgroup12b.reload.samples_count)

assert_no_changes -> { @group12.reload.samples_count } do
assert_no_changes -> { @subgroup12aa.reload.samples_count } do
assert_no_changes -> { @subgroup12b.reload.samples_count } do
Groups::TransferService.new(@subgroup12b, @john_doe).execute(@subgroup12a)
end
end
end

assert_equal(4, @subgroup12a.reload.samples_count)
end
end
end
32 changes: 26 additions & 6 deletions test/services/projects/destroy_service_test.rb
Original file line number Diff line number Diff line change
@@ -7,6 +7,11 @@ class DestroyServiceTest < ActiveSupport::TestCase
def setup
@user = users(:john_doe)
@project = projects(:john_doe_project2)
@group12 = groups(:group_twelve)
@subgroup12a = groups(:subgroup_twelve_a)
@subgroup12b = groups(:subgroup_twelve_b)
@subgroup12aa = groups(:subgroup_twelve_a_a)
@project31 = projects(:project31)
end

test 'delete project with with correct permissions' do
@@ -45,12 +50,6 @@ def setup
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
@group12 = groups(:group_twelve)
@subgroup12a = groups(:subgroup_twelve_a)
@subgroup12b = groups(:subgroup_twelve_b)
@subgroup12aa = groups(:subgroup_twelve_a_a)
@project31 = projects(:project31)

assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @project31.namespace.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12aa.metadata_summary)
assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, @subgroup12a.metadata_summary)
@@ -67,5 +66,26 @@ def setup
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12b.reload.metadata_summary)
assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, @group12.reload.metadata_summary)
end

test 'samples count updated after project deletion' do
# Reference group/projects descendants tree:
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
assert_equal(2, @subgroup12aa.samples_count)
assert_equal(3, @subgroup12a.samples_count)
assert_equal(1, @subgroup12b.samples_count)
assert_equal(4, @group12.samples_count)

assert_no_changes -> { @subgroup12b.reload.samples_count } do
Projects::DestroyService.new(@project31, @user).execute
end

assert(@project31.namespace.reload.deleted?)
assert_equal(0, @subgroup12aa.reload.samples_count)
assert_equal(1, @subgroup12a.reload.samples_count)
assert_equal(1, @subgroup12b.reload.samples_count)
assert_equal(2, @group12.reload.samples_count)
end
end
end
80 changes: 74 additions & 6 deletions test/services/projects/transfer_service_test.rb
Original file line number Diff line number Diff line change
@@ -8,6 +8,12 @@ def setup
@john_doe = users(:john_doe)
@jane_doe = users(:jane_doe)
@project = projects(:project1)

@project31 = projects(:project31)
@group12 = groups(:group_twelve)
@subgroup12a = groups(:subgroup_twelve_a)
@subgroup12b = groups(:subgroup_twelve_b)
@subgroup12aa = groups(:subgroup_twelve_a_a)
end

test 'transfer project with permission' do
@@ -149,12 +155,6 @@ def setup
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
@project31 = projects(:project31)
@group12 = groups(:group_twelve)
@subgroup12a = groups(:subgroup_twelve_a)
@subgroup12b = groups(:subgroup_twelve_b)
@subgroup12aa = groups(:subgroup_twelve_a_a)

assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @project31.namespace.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12aa.metadata_summary)
assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, @subgroup12a.metadata_summary)
@@ -182,5 +182,73 @@ def setup
new_namespace.reload
assert_equal({}, new_namespace.metadata_summary)
end

test 'samples count updates after project transfer' do
# Reference group/projects descendants tree:
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
assert_equal(2, @subgroup12aa.samples_count)
assert_equal(3, @subgroup12a.samples_count)
assert_equal(1, @subgroup12b.samples_count)
assert_equal(4, @group12.samples_count)

assert_no_changes -> { @group12.reload.samples_count } do
assert_no_changes -> { @project31.reload.samples.size } do
Projects::TransferService.new(@project31, @john_doe).execute(@subgroup12b)
end
end

assert_equal(0, @subgroup12aa.reload.samples_count)
assert_equal(1, @subgroup12a.reload.samples_count)
assert_equal(3, @subgroup12b.reload.samples_count)
end

test 'samples count updates after a project transfer from a user namespace' do
# Reference group/projects descendants tree:
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
john_doe_project = projects(:john_doe_project2)

assert_equal(2, @subgroup12aa.samples_count)
assert_equal(3, @subgroup12a.samples_count)
assert_equal(1, @subgroup12b.samples_count)
assert_equal(4, @group12.samples_count)

assert_no_changes -> { @subgroup12a.reload.samples_count } do
assert_no_changes -> { @subgroup12aa.reload.samples_count } do
assert_no_changes -> { john_doe_project.reload.samples.size } do
Projects::TransferService.new(john_doe_project, @john_doe).execute(@subgroup12b)
end
end
end

assert_equal(5, @group12.reload.samples_count)
assert_equal(2, @subgroup12b.reload.samples_count)
end

test 'samples count updates after a project transfer to a user namespace' do
# Reference group/projects descendants tree:
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
john_doe_namespace = namespaces_user_namespaces(:john_doe_namespace)

assert_equal(2, @subgroup12aa.samples_count)
assert_equal(3, @subgroup12a.samples_count)
assert_equal(1, @subgroup12b.samples_count)
assert_equal(4, @group12.samples_count)

assert_no_changes -> { @subgroup12b.reload.samples_count } do
assert_no_changes -> { @project31.reload.samples.size } do
Projects::TransferService.new(@project31, @john_doe).execute(john_doe_namespace)
end
end

assert_equal(2, @group12.reload.samples_count)
assert_equal(1, @subgroup12a.reload.samples_count)
assert_equal(0, @subgroup12aa.reload.samples_count)
end
end
end
42 changes: 42 additions & 0 deletions test/services/samples/clone_service_test.rb
Original file line number Diff line number Diff line change
@@ -182,5 +182,47 @@ def setup
sample_name: @sample2.name, sample_puid: @sample2.puid)
)
end

test 'samples count updates after cloning sample' do
# Reference group/projects descendants tree:
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
group12 = groups(:group_twelve)
subgroup12a = groups(:subgroup_twelve_a)
subgroup12b = groups(:subgroup_twelve_b)
subgroup12aa = groups(:subgroup_twelve_a_a)
project30 = projects(:project30)
project31 = projects(:project31)
sample33 = samples(:sample33)

assert_equal(2, subgroup12aa.samples_count)
assert_equal(3, subgroup12a.samples_count)
assert_equal(1, subgroup12b.samples_count)
assert_equal(4, group12.samples_count)

clone_samples_params = { new_project_id: project31.id, sample_ids: [sample33.id] }
cloned_sample_ids = Samples::CloneService.new(project30, @john_doe).execute(clone_samples_params[:new_project_id],
clone_samples_params[:sample_ids])
cloned_sample_ids.each do |sample_id, clone_id|
sample = Sample.find_by(id: sample_id)
clone = Sample.find_by(id: clone_id)
assert_equal project30.id, sample.project_id
assert_equal project31.id, clone.project_id
assert_not_equal sample.puid, clone.puid
assert_equal sample.name, clone.name
assert_equal sample.description, clone.description
assert_equal sample.metadata, clone.metadata
assert_equal sample.metadata_provenance, clone.metadata_provenance
sample_blobs = sample.attachments.map { |attachment| attachment.file.blob }
clone_blobs = clone.attachments.map { |attachment| attachment.file.blob }
assert_equal sample_blobs.sort, clone_blobs.sort
end

assert_equal(3, subgroup12aa.reload.samples_count)
assert_equal(4, subgroup12a.reload.samples_count)
assert_equal(1, subgroup12b.reload.samples_count)
assert_equal(5, group12.reload.samples_count)
end
end
end
26 changes: 26 additions & 0 deletions test/services/samples/create_service_test.rb
Original file line number Diff line number Diff line change
@@ -97,5 +97,31 @@ def setup
assert_equal 'new-project2-sample', sample.at(version: 1).name
assert_equal 'first sample for project2', sample.at(version: 1).description
end

test 'samples count updated after sample creation' do
# Reference group/projects descendants tree:
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
group12 = groups(:group_twelve)
subgroup12a = groups(:subgroup_twelve_a)
subgroup12b = groups(:subgroup_twelve_b)
subgroup12aa = groups(:subgroup_twelve_a_a)
project31 = projects(:project31)
valid_params = { name: 'sample36', description: 'new sample for project31' }

assert_equal(2, subgroup12aa.samples_count)
assert_equal(3, subgroup12a.samples_count)
assert_equal(1, subgroup12b.samples_count)
assert_equal(4, group12.samples_count)

assert_no_changes -> { subgroup12b.reload.samples_count } do
Samples::CreateService.new(@user, project31, valid_params).execute
end

assert_equal(3, subgroup12aa.reload.samples_count)
assert_equal(4, subgroup12a.reload.samples_count)
assert_equal(5, group12.reload.samples_count)
end
end
end
118 changes: 77 additions & 41 deletions test/services/samples/destroy_service_test.rb
Original file line number Diff line number Diff line change
@@ -10,6 +10,13 @@ def setup
@sample2 = samples(:sample2)
@sample30 = samples(:sample30)
@project = projects(:project1)

@group12 = groups(:group_twelve)
@subgroup12a = groups(:subgroup_twelve_a)
@subgroup12b = groups(:subgroup_twelve_b)
@subgroup12aa = groups(:subgroup_twelve_a_a)
@project31 = projects(:project31)
@sample34 = samples(:sample34)
end

test 'destroy sample with correct permissions' do
@@ -44,28 +51,21 @@ def setup
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
group12 = groups(:group_twelve)
subgroup12a = groups(:subgroup_twelve_a)
subgroup12b = groups(:subgroup_twelve_b)
subgroup12aa = groups(:subgroup_twelve_a_a)
project31 = projects(:project31)
sample34 = samples(:sample34)

assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, project31.namespace.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, subgroup12aa.metadata_summary)
assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, subgroup12a.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, subgroup12b.metadata_summary)
assert_equal({ 'metadatafield1' => 3, 'metadatafield2' => 3 }, group12.metadata_summary)

assert_no_changes -> { subgroup12b.reload.metadata_summary } do
Samples::DestroyService.new(project31, @user, { sample: sample34 }).execute
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @project31.namespace.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12aa.metadata_summary)
assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, @subgroup12a.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12b.metadata_summary)
assert_equal({ 'metadatafield1' => 3, 'metadatafield2' => 3 }, @group12.metadata_summary)

assert_no_changes -> { @subgroup12b.reload.metadata_summary } do
Samples::DestroyService.new(@project31, @user, { sample: @sample34 }).execute
end

assert_equal({}, project31.namespace.reload.metadata_summary)
assert_equal({}, subgroup12aa.reload.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, subgroup12a.reload.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, subgroup12b.reload.metadata_summary)
assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, group12.reload.metadata_summary)
assert_equal({}, @project31.namespace.reload.metadata_summary)
assert_equal({}, @subgroup12aa.reload.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12a.reload.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12b.reload.metadata_summary)
assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, @group12.reload.metadata_summary)
end

test 'multiple destroy with multiple samples and correct permissions' do
@@ -93,38 +93,74 @@ def setup
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
group12 = groups(:group_twelve)
subgroup12a = groups(:subgroup_twelve_a)
subgroup12b = groups(:subgroup_twelve_b)
subgroup12aa = groups(:subgroup_twelve_a_a)
project30 = projects(:project30)
project31 = projects(:project31)
sample33 = samples(:sample33)
sample34 = samples(:sample34)

assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, project31.namespace.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, subgroup12aa.metadata_summary)
assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, subgroup12a.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, subgroup12b.metadata_summary)
assert_equal({ 'metadatafield1' => 3, 'metadatafield2' => 3 }, group12.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @project31.namespace.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12aa.metadata_summary)
assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, @subgroup12a.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12b.metadata_summary)
assert_equal({ 'metadatafield1' => 3, 'metadatafield2' => 3 }, @group12.metadata_summary)

Samples::TransferService.new(project30, @user).execute(project31.id, [sample33.id])
Samples::TransferService.new(project30, @user).execute(@project31.id, [sample33.id])

assert_equal(
{ 'metadatafield1' => 2, 'metadatafield2' => 2 }, project31.reload.namespace.metadata_summary
{ 'metadatafield1' => 2, 'metadatafield2' => 2 }, @project31.reload.namespace.metadata_summary
)

assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, subgroup12aa.reload.metadata_summary)
assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, @subgroup12aa.reload.metadata_summary)

assert_no_changes -> { @subgroup12b.reload.metadata_summary } do
Samples::DestroyService.new(@project31, @user, { sample_ids: [sample33.id, @sample34.id] }).execute
end

assert_equal({}, @project31.namespace.reload.metadata_summary)
assert_equal({}, @subgroup12aa.reload.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12a.reload.metadata_summary)
assert_equal({}, @subgroup12b.reload.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @group12.reload.metadata_summary)
end

test 'samples count updated after single sample deletion' do
# Reference group/projects descendants tree:
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
assert_equal(2, @subgroup12aa.samples_count)
assert_equal(3, @subgroup12a.samples_count)
assert_equal(1, @subgroup12b.samples_count)
assert_equal(4, @group12.samples_count)

assert_no_changes -> { @subgroup12b.reload.metadata_summary } do
Samples::DestroyService.new(@project31, @user, { sample: @sample34 }).execute
end

assert_equal(1, @subgroup12aa.reload.samples_count)
assert_equal(2, @subgroup12a.reload.samples_count)
assert_equal(1, @subgroup12b.reload.samples_count)
assert_equal(3, @group12.reload.samples_count)
end

test 'samples count updated after multiple sample deletion' do
# Reference group/projects descendants tree:
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
sample35 = samples(:sample35)

assert_equal(2, @subgroup12aa.samples_count)
assert_equal(3, @subgroup12a.samples_count)
assert_equal(1, @subgroup12b.samples_count)
assert_equal(4, @group12.samples_count)

assert_no_changes -> { subgroup12b.reload.metadata_summary } do
Samples::DestroyService.new(project31, @user, { sample_ids: [sample33.id, sample34.id] }).execute
assert_no_changes -> { @subgroup12b.reload.samples_count } do
Samples::DestroyService.new(@project31, @user, { sample_ids: [@sample34.id, sample35.id] }).execute
end

assert_equal({}, project31.namespace.reload.metadata_summary)
assert_equal({}, subgroup12aa.reload.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, subgroup12a.reload.metadata_summary)
assert_equal({}, subgroup12b.reload.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, group12.reload.metadata_summary)
assert_equal(0, @subgroup12aa.reload.samples_count)
assert_equal(1, @subgroup12a.reload.samples_count)
assert_equal(1, @subgroup12b.reload.samples_count)
assert_equal(2, @group12.reload.samples_count)
end
end
end
128 changes: 110 additions & 18 deletions test/services/samples/transfer_service_test.rb
Original file line number Diff line number Diff line change
@@ -4,14 +4,31 @@

module Samples
class TransferServiceTest < ActiveSupport::TestCase
def setup
def setup # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
@john_doe = users(:john_doe)
@jane_doe = users(:jane_doe)
@joan_doe = users(:joan_doe)
@current_project = projects(:project1)
@new_project = projects(:project2)
@sample1 = samples(:sample1)
@sample2 = samples(:sample2)

@sample33 = samples(:sample33)
@sample34 = samples(:sample34)
@sample35 = samples(:sample35)
@project29 = projects(:project29)
@project30 = projects(:project30)
@project31 = projects(:project31)
@group12 = groups(:group_twelve)
@subgroup12a = groups(:subgroup_twelve_a)
@subgroup12b = groups(:subgroup_twelve_b)
@subgroup12aa = groups(:subgroup_twelve_a_a)
@sample_transfer_params1 = { new_project_id: @project30.id,
sample_ids: [@sample34.id, @sample35.id] }
@sample_transfer_params2 = { new_project_id: @project29.id,
sample_ids: [@sample33.id, @sample34.id, @sample35.id] }

@john_doe_project2 = projects(:john_doe_project2)
end

test 'transfer project samples with permission' do
@@ -109,20 +126,6 @@ def setup
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
@sample33 = samples(:sample33)
@sample34 = samples(:sample34)
@sample35 = samples(:sample35)
@project29 = projects(:project29)
@project30 = projects(:project30)
@project31 = projects(:project31)
@group12 = groups(:group_twelve)
@subgroup12a = groups(:subgroup_twelve_a)
@subgroup12b = groups(:subgroup_twelve_b)
@subgroup12aa = groups(:subgroup_twelve_a_a)

@sample_transfer_params1 = { new_project_id: @project30.id,
sample_ids: [@sample34.id, @sample35.id] }

assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @project31.namespace.metadata_summary)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12aa.metadata_summary)
assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, @subgroup12a.metadata_summary)
@@ -140,9 +143,6 @@ def setup
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12a.reload.metadata_summary)
assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, @subgroup12b.reload.metadata_summary)

@sample_transfer_params2 = { new_project_id: @project29.id,
sample_ids: [@sample33.id, @sample34.id, @sample35.id] }

assert_no_changes -> { @group12.reload.metadata_summary } do
Samples::TransferService.new(@project30, @john_doe).execute(@sample_transfer_params2[:new_project_id],
@sample_transfer_params2[:sample_ids])
@@ -154,5 +154,97 @@ def setup
assert_equal({}, @subgroup12aa.reload.metadata_summary)
assert_equal({ 'metadatafield1' => 3, 'metadatafield2' => 3 }, @subgroup12a.reload.metadata_summary)
end

test 'samples count updates after sample transfer' do
# Reference group/projects descendants tree:
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
assert_equal(2, @subgroup12aa.samples_count)
assert_equal(3, @subgroup12a.samples_count)
assert_equal(1, @subgroup12b.samples_count)
assert_equal(4, @group12.samples_count)

assert_no_changes -> { @group12.reload.samples_count } do
Samples::TransferService.new(@project31, @john_doe).execute(@sample_transfer_params1[:new_project_id],
@sample_transfer_params1[:sample_ids])
end

assert_equal(0, @subgroup12aa.reload.samples_count)
assert_equal(1, @subgroup12a.reload.samples_count)
assert_equal(3, @subgroup12b.reload.samples_count)

assert_no_changes -> { @group12.reload.samples_count } do
Samples::TransferService.new(@project30, @john_doe).execute(@sample_transfer_params2[:new_project_id],
@sample_transfer_params2[:sample_ids])
end

assert_equal(0, @subgroup12aa.reload.samples_count)
assert_equal(4, @subgroup12a.reload.samples_count)
assert_equal(0, @subgroup12b.reload.samples_count)
end

test 'samples count updates after a sample transfer from a user namespace' do
# Reference group/projects descendants tree:
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
sample24 = samples(:sample24)

assert_equal(2, @subgroup12aa.samples_count)
assert_equal(3, @subgroup12a.samples_count)
assert_equal(1, @subgroup12b.samples_count)
assert_equal(4, @group12.samples_count)

assert_difference -> { @subgroup12aa.reload.samples_count } => 1,
-> { @subgroup12a.reload.samples_count } => 1,
-> { @group12.reload.samples_count } => 1,
-> { @john_doe_project2.reload.samples.size } => -1 do
Samples::TransferService.new(@john_doe_project2, @john_doe).execute(@project31.id, [sample24.id])
end

assert_equal(1, @subgroup12b.reload.samples_count)
end

test 'samples count updates after a sample transfer to a user namespace' do
# Reference group/projects descendants tree:
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
assert_equal(2, @subgroup12aa.samples_count)
assert_equal(3, @subgroup12a.samples_count)
assert_equal(1, @subgroup12b.samples_count)
assert_equal(4, @group12.samples_count)

assert_difference -> { @subgroup12aa.reload.samples_count } => -2,
-> { @subgroup12a.reload.samples_count } => -2,
-> { @group12.reload.samples_count } => -2,
-> { @john_doe_project2.reload.samples.size } => 2 do
Samples::TransferService.new(@project31, @john_doe).execute(@john_doe_project2.id, [@sample34.id, @sample35.id])
end

assert_equal(1, @subgroup12b.reload.samples_count)
end

test 'samples count updates after a sample transfer between projects in the same user namespace' do
# Reference group/projects descendants tree:
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
john_doe_project3 = projects(:john_doe_project3)
sample24 = samples(:sample24)

assert_equal(2, @subgroup12aa.samples_count)
assert_equal(3, @subgroup12a.samples_count)
assert_equal(1, @subgroup12b.samples_count)
assert_equal(4, @group12.samples_count)

assert_difference -> { @john_doe_project2.reload.samples.size } => -1,
-> { john_doe_project3.reload.samples.size } => 1 do
Samples::TransferService.new(@john_doe_project2, @john_doe).execute(john_doe_project3.id, [sample24.id])
end

assert_equal(1, @subgroup12b.reload.samples_count)
end
end
end
395 changes: 395 additions & 0 deletions test/system/dashboard/groups_test.rb

Large diffs are not rendered by default.

419 changes: 419 additions & 0 deletions test/system/groups_test.rb

Large diffs are not rendered by default.