Skip to content

Commit

Permalink
Merge pull request #1043 from griffithlab/test-improvements
Browse files Browse the repository at this point in the history
Minor test improvements
  • Loading branch information
acoffman authored Apr 23, 2024
2 parents a213c87 + e205df5 commit a5c4722
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
working-directory: ./server
bundler-cache: true
ruby-version: '3.0'
ruby-version: '3.3'

- name: Setup node
uses: actions/setup-node@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
uses: ruby/setup-ruby@v1
with:
working-directory: ./server
ruby-version: '3.0'
ruby-version: '3.3'
bundler-cache: true

- name: Deploy to production
Expand Down
2 changes: 1 addition & 1 deletion server/app/graphql/loaders/association_count_loader.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Loaders
class AssociationCountLoader < GraphQL::Batch::Loader
def initialize(model, association: association)
def initialize(model, association: )
@model = model
@association = association
end
Expand Down
7 changes: 3 additions & 4 deletions server/app/graphql/resolvers/top_level_therapies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ class Resolvers::TopLevelTherapies < GraphQL::Schema::Resolver
description 'List and filter Therapies from the NCI Thesaurus.'

scope do
Therapy.select('therapies.id, therapies.name, therapies.ncit_id, count(distinct(assertions.id)) as assertion_count, count(distinct(evidence_items.id)) as evidence_count')
.left_outer_joins(:assertions)
.left_outer_joins(:evidence_items)
Therapy.select('therapies.id, therapies.name, max(therapies.ncit_id) as ncit_id, count(distinct(assertions.id)) as assertion_count, count(distinct(evidence_items.id)) as evidence_count')
.left_outer_joins(:assertions, :evidence_items)
.where("evidence_items.status != 'rejected' OR assertions.status != 'rejected'")
.where(deprecated: false)
.group('therapies.id, therapies.name, therapies.ncit_id')
.group('therapies.id, therapies.name')
.having('COUNT(evidence_items.id) > 0 OR COUNT(assertions.id) > 0')
.order('evidence_count DESC', :id)
end
Expand Down
11 changes: 5 additions & 6 deletions server/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
config.cache_classes = false
config.action_view.cache_template_loading = true

# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
# Eager load when running in CI to detect any load issues
config.eager_load = ENV["CI"].present?

# Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true
Expand All @@ -27,8 +25,7 @@
config.action_controller.perform_caching = false
config.cache_store = :null_store

# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
config.action_dispatch.show_exceptions = true

# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
Expand All @@ -49,6 +46,8 @@
# Raise exceptions for disallowed deprecations.
config.active_support.disallowed_deprecation = :raise

config.active_job.queue_adapter = :test

# Tell Active Support which deprecation messages to disallow.
config.active_support.disallowed_deprecation_warnings = []

Expand Down
Empty file removed server/test/controllers/.keep
Empty file.
48 changes: 48 additions & 0 deletions server/test/controllers/links_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require "test_helper"

class LinksControllerTest < ActionDispatch::IntegrationTest
test "it should 404 rather than redirect when the entity isn't found" do
get "/links/features/999999"
assert_response :not_found
end

test 'it should 400 bad request when its an invalid link type' do
get '/links/footures/9999'
assert_response :bad_request
end

test 'gene, feature, factor permalinks work' do
feature = features.first
feature_path = "/features/#{feature.id}"
check_redirect "/links/features/#{feature.id}", feature_path
check_redirect "/links/id/FID#{feature.id}", feature_path

gene = feature_genes.first
gene_path = "/features/#{gene.feature.id}"
check_redirect "/links/genes/#{gene.id}", gene_path
check_redirect "/links/id/GID#{gene.id}", gene_path
check_redirect "/links/entrez_id/#{gene.entrez_id}", gene_path
check_redirect "/links/entrez_name/#{gene.name}", gene_path
end

test 'variant links work' do
variant = variants(:v600e)
variant_path = "/variants/#{variant.id}"

check_redirect "/links/id/VID#{variant.id}", variant_path
check_redirect "/links/allele_registry/#{variant.allele_registry_id}", variant_path
check_redirect "/links/variants/#{variant.id}", variant_path
end

test 'redirect legacy frontend gene route to corresponding feature' do
gene = feature_genes.first
check_redirect "/genes/#{gene.id}", "/features/#{gene.feature.id}"
end

def check_redirect(input_path, output_path)
get input_path
assert_response :redirect
redirect_url = URI.parse(@response['Location']).path
assert_equal output_path, redirect_url
end
end
3 changes: 3 additions & 0 deletions server/test/fixtures/feature_factors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
msi:
ncit_id: NCIT123

7 changes: 7 additions & 0 deletions server/test/fixtures/features.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
braf:
name: BRAF
full_name: B-Raf proto-oncogene, serine/threonine kinase
feature_instance: braf (Features::Gene)

vhl:
name: VHL
full_name: von Hippel-Lindau tumor suppressor
feature_instance: vhl (Features::Gene)

msi:
name: MSI
full_name: Microsatellite Instability
description: The description for the MSI factor
feature_instance: msi (Features::Factor)
1 change: 1 addition & 0 deletions server/test/fixtures/variants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ v600e:
gene_id: 1
type: 'Variants::GeneVariant'
single_variant_molecular_profile: mp1
allele_registry_id: CAFOO

v600k:
name: V600K
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ def setup
mp_id = response["data"]["createMolecularProfile"]["molecularProfile"]['id']
mp = MolecularProfile.find(mp_id)
assert_equal(mp.display_name, "NOT BRAF V600K AND BRAF V600E AND ( VHL W88* OR VHL V87E (c.260T>A) )")
assert_equal(mp.variants, [@variant, v2, v3, v4])
assert_equal(mp.variants.to_a, [@variant, v2, v3, v4])
end
end
1 change: 1 addition & 0 deletions server/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ActiveSupport::TestCase
fixtures :all

set_fixture_class feature_genes: Features::Gene
set_fixture_class feature_factors: Features::Factor

# Add more helper methods to be used by all tests here...
end

0 comments on commit a5c4722

Please sign in to comment.