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

Tests: Simplify Samples services samples_count validations #874

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 7 additions & 26 deletions test/services/samples/clone_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,33 +204,14 @@ def setup
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
assert_difference -> { project30.reload.samples.size } => 0,
-> { project31.reload.samples.size } => 1,
-> { subgroup12aa.reload.samples_count } => 1,
-> { subgroup12a.reload.samples_count } => 1,
-> { subgroup12b.reload.samples_count } => 0,
-> { group12.reload.samples_count } => 1 do
Samples::CloneService.new(project30, @john_doe).execute(project31.id, [sample33.id])
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
15 changes: 5 additions & 10 deletions test/services/samples/create_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,13 @@ def setup
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
assert_difference -> { project31.reload.samples.size } => 1,
-> { subgroup12aa.reload.samples_count } => 1,
-> { subgroup12a.reload.samples_count } => 1,
-> { subgroup12b.reload.samples_count } => 0,
-> { group12.reload.samples_count } => 1 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
34 changes: 12 additions & 22 deletions test/services/samples/destroy_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,14 @@ def setup
# 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
assert_difference -> { @subgroup12b.reload.samples_count } => 0,
-> { @project31.reload.samples.size } => -1,
-> { @subgroup12aa.reload.samples_count } => -1,
-> { @subgroup12a.reload.samples_count } => -1,
-> { @subgroup12b.reload.samples_count } => 0,
-> { @group12.reload.samples_count } => -1 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
Expand All @@ -148,19 +143,14 @@ def setup
# ---- < 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.samples_count } do
assert_difference -> { @subgroup12b.reload.samples_count } => 0,
-> { @project31.reload.samples.size } => -2,
-> { @subgroup12aa.reload.samples_count } => -2,
-> { @subgroup12a.reload.samples_count } => -2,
-> { @subgroup12b.reload.samples_count } => 0,
-> { @group12.reload.samples_count } => -2 do
Samples::DestroyService.new(@project31, @user, { sample_ids: [@sample34.id, sample35.id] }).execute
end

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
27 changes: 2 additions & 25 deletions test/services/samples/transfer_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,60 +191,37 @@ def setup # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
# ---- < 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,
-> { @subgroup12b.reload.samples_count } => 0,
-> { @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,
-> { @subgroup12b.reload.samples_count } => 0,
-> { @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
Loading