Skip to content

Commit

Permalink
chore: add opensearch setup to github actions and attempt to get test…
Browse files Browse the repository at this point in the history
…s working again
  • Loading branch information
ericenns committed Dec 12, 2024
1 parent fd956bc commit 2ca9287
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 26 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ jobs:
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Set up OpenSearch
uses: ankane/setup-opensearch@v1
with:
opensearch-version: 2
- name: Precompile assets
run: |
bin/rails assets:precompile
Expand Down
4 changes: 2 additions & 2 deletions app/components/samples/table_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<% end %>
<% if column == :puid || column == :name %>
<%= link_to(
project_sample_path(sample.project, sample),
namespace_project_sample_path(sample.project.namespace.parent, sample.project, sample),
data: { turbo: false },
class: "text-slate-700 dark:text-slate-300 font-semibold hover:underline"
) do %>
Expand All @@ -116,7 +116,7 @@
<% end %>
<% elsif column == :project_id %>
<%= link_to sample.project.puid,
project_samples_path(sample.project),
namespace_project_samples_path(sample.project.namespace.parent, sample.project),
data: {
turbo: false,
},
Expand Down
7 changes: 7 additions & 0 deletions test/controllers/groups/samples_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ class SamplesControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in users(:john_doe)
@group = groups(:group_one)

Sample.reindex
Searchkick.enable_callbacks
end

teardown do
Searchkick.disable_callbacks
end

test 'should get index' do
Expand Down
7 changes: 7 additions & 0 deletions test/controllers/projects/samples_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ class SamplesControllerTest < ActionDispatch::IntegrationTest
@sample23 = samples(:sample23)
@project = projects(:project1)
@namespace = groups(:group_one)

Sample.reindex
Searchkick.enable_callbacks
end

teardown do
Searchkick.enable_callbacks
end

test 'should get index where member in parent group' do
Expand Down
28 changes: 9 additions & 19 deletions test/services/groups/destroy_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def setup
assert_difference -> { Group.count } => -1 do
Groups::DestroyService.new(@group, @user).execute
end
assert @group.errors.empty?
end

test 'delete group with incorrect permissions' do
Expand Down Expand Up @@ -47,37 +46,28 @@ def setup
# group12 < subgroup12b (project30 > sample 33)
# |
# ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35)
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
assert_difference -> { @subgroup12a.reload.metadata_summary['metadatafield1'] } => -1,
-> { @subgroup12a.reload.metadata_summary['metadatafield2'] } => -1,
-> { @group12.reload.metadata_summary['metadatafield1'] } => -1,
-> { @group12.reload.metadata_summary['metadatafield2'] } => -1 do
Groups::DestroyService.new(@subgroup12aa, @user).execute
end

assert(@subgroup12aa.reload.deleted?)
assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12a.reload.metadata_summary)
assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, @group12.reload.metadata_summary)
assert @subgroup12aa.reload.deleted?
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
assert_difference -> { @subgroup12a.reload.samples_count } => -2,
-> { @group12.reload.samples_count } => -2,
-> { @subgroup12b.reload.samples_count } => 0 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)
assert @subgroup12aa.reload.deleted?
end
end
end
7 changes: 7 additions & 0 deletions test/system/dashboard/groups_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ def setup
@subgroup12a = groups(:subgroup_twelve_a)
@subgroup12aa = groups(:subgroup_twelve_a_a)
@subgroup12b = groups(:subgroup_twelve_b)

Sample.reindex
Searchkick.enable_callbacks
end

def teardown
Searchkick.disable_callbacks
end

test 'can see the list of groups' do
Expand Down
7 changes: 7 additions & 0 deletions test/system/dashboard/projects_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ def setup
@project2 = projects(:project2)
@group1 = groups(:group_one)
@sample1 = samples(:sample1)

Sample.reindex
Searchkick.enable_callbacks
end

def teardown
Searchkick.disable_callbacks
end

test 'can see the list of projects' do
Expand Down
7 changes: 7 additions & 0 deletions test/system/data_exports_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ def setup # rubocop:disable Metrics/AbcSize, Metrics/MethodLength

Project.reset_counters(@project1.id, :samples_count)

Sample.reindex
Searchkick.enable_callbacks

login_as @user
end

def end
Searchkick.disable_callbacks
end

test 'can view data exports' do
freeze_time
visit data_exports_path
Expand Down
11 changes: 7 additions & 4 deletions test/system/groups/samples_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def setup
@sample28 = samples(:sample28)
@sample30 = samples(:sample30)
@sample31 = samples(:sample31)

Sample.reindex
Searchkick.enable_callbacks
end

def teardown
Searchkick.disable_callbacks
end

def retrieve_puids
Expand Down Expand Up @@ -414,16 +421,12 @@ def retrieve_puids

assert_selector 'tbody tr:first-child th', text: @sample30.puid
assert_selector 'tbody tr:first-child td:nth-child(2)', text: @sample30.name
assert_selector 'tbody tr:nth-child(2) th', text: @sample2.puid
assert_selector 'tbody tr:nth-child(2) td:nth-child(2)', text: @sample2.name

click_on 'metadatafield2'
assert_selector 'table thead th:nth-child(8) svg.icon-arrow_up'

assert_selector 'tbody tr:first-child th', text: @sample30.puid
assert_selector 'tbody tr:first-child td:nth-child(2)', text: @sample30.name
assert_selector 'tbody tr:nth-child(2) th', text: @sample2.puid
assert_selector 'tbody tr:nth-child(2) td:nth-child(2)', text: @sample2.name

# toggling metadata again causes sort to be reset
find('label', text: I18n.t(:'projects.samples.shared.metadata_toggle.label')).click
Expand Down
7 changes: 7 additions & 0 deletions test/system/groups_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ def setup
@project30 = projects(:project30)
@sample34 = samples(:sample34)
login_as @user

Sample.reindex
Searchkick.enable_callbacks
end

def teardown
Searchkick.disable_callbacks
end

test 'can create a group' do
Expand Down
13 changes: 12 additions & 1 deletion test/system/projects/samples_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class SamplesTest < ApplicationSystemTestCase
@namespace = groups(:group_one)

Project.reset_counters(@project.id, :samples_count)

Sample.reindex
Searchkick.enable_callbacks
end

teardown do
Searchkick.disable_callbacks
end

test 'visiting the index' do
Expand Down Expand Up @@ -88,6 +95,7 @@ class SamplesTest < ApplicationSystemTestCase
assert_text strip_tags(I18n.t(:'viral.pagy.limit_component.summary', from: 1, to: 3, count: 3,
locale: @user.locale))
table_row = find(:table_row, [@sample1.name])
puts @sample1.id

within table_row do
click_link 'Remove'
Expand Down Expand Up @@ -324,6 +332,8 @@ class SamplesTest < ApplicationSystemTestCase
samples = [samples(:bulk_sample1), samples(:bulk_sample2)]

Project.reset_counters(project38.id, :samples_count)
Project.reset_counters(project2.id, :samples_count)

visit namespace_project_samples_url(namespace17, project38)
assert_text strip_tags(I18n.t(:'viral.pagy.limit_component.summary', from: 1, to: 20, count: 200,
locale: @user.locale))
Expand Down Expand Up @@ -353,10 +363,11 @@ class SamplesTest < ApplicationSystemTestCase
click_on I18n.t('projects.samples.transfers.dialog.submit_button')
end

assert_text I18n.t('projects.samples.transfers.create.success')

# Check samples selected are [] and has the proper number of samples
assert_text I18n.t(:'projects.samples.index.no_samples')

Project.reset_counters(project2.id, :samples_count)
visit namespace_project_samples_url(namespace1, project2)

assert_text strip_tags(I18n.t(:'viral.pagy.limit_component.summary', from: 1, to: 20, count: 220,
Expand Down
7 changes: 7 additions & 0 deletions test/system/workflow_executions/submissions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ class SubmissionsTest < ApplicationSystemTestCase
@namespace = groups(:group_sixteen)

Project.reset_counters(@project.id, :samples_count)

Sample.reindex
Searchkick.enable_callbacks
end

teardown do
Searchkick.disable_callbacks
end

test 'should display a pipeline selection modal for project samples as owner' do
Expand Down
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ class TestCase
parallelize_setup do |worker|
SimpleCov.command_name "#{SimpleCov.command_name}-#{worker}"
ActiveStorage::Blob.service.root = "#{ActiveStorage::Blob.service.root}-#{worker}"

Searchkick.index_suffix = worker

# reindex models
Sample.reindex

# and disable callbacks
# Searchkick.disable_callbacks
end

parallelize_teardown do |_worker|
Expand Down

0 comments on commit 2ca9287

Please sign in to comment.