Skip to content

Commit

Permalink
final controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tibvdm committed Mar 20, 2024
1 parent c4f90d5 commit c9a8fb3
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
47 changes: 46 additions & 1 deletion test/controllers/api/taxa2tree_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
require 'test_helper'

class Api::Taxa2treeControllerTest < ActionController::TestCase
# TODO
teardown :assert_success

test 'should get taxa2tree' do
@expected = '{
"id":1,"name":"Organism","rank":"no rank","data":{"count":1,"self_count":0},"children":[
{"id":13,"name":"kingdom2","rank":"kingdom","data":{"count":1,"self_count":0},"children":[
{"id":14,"name":"phylum1","rank":"phylum","data":{"count":1,"self_count":1},"children":[]}
]}
]
}'

get :taxa2tree, params: { input: %w[14], format: 'json' }
end

test 'should get taxa2tree with names' do
@expected = '{
"id":1,"name":"Organism","rank":"no rank","data":{"count":1,"self_count":0},"children":[
{"id":13,"name":"kingdom2","rank":"kingdom","data":{"count":1,"self_count":0},"children":[
{"id":14,"name":"phylum1","rank":"phylum","data":{"count":1,"self_count":1},"children":[]}
]}
]
}'

get :taxa2tree, params: { input: %w[14], names: 'true', format: 'json' }
puts @response.body
end

# test 'should get taxa2tree with extra' do
# @expected = '{
# "id":1,"name":"Organism","rank":"no rank","data":{"count":1,"self_count":0},"children":[
# {"id":13,"name":"kingdom2","rank":"kingdom","data":{"count":1,"self_count":0},"children":[
# {"id":14,"name":"phylum1","rank":"phylum","data":{"count":1,"self_count":1},"children":[]}
# ]}
# ]
# }'

# get :taxa2tree, params: { input: %w[14], extra: 'true', format: 'json' }
# end

private

def assert_success
assert_response :success
assert_equal '*', @response.headers['Access-Control-Allow-Origin']
assert_json
end
end
14 changes: 9 additions & 5 deletions test/controllers/mpa/pept2filtered_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
class Mpa::Pept2filteredControllerTest < ActionController::TestCase
teardown :assert_success

# TODO: find a working (non-empty) example
# test 'should get pept2filtered' do
# @expected = '{}'
test 'should get pept2filtered' do
@expected = '{
"peptides":[
{"sequence":"AALER","taxa":[1,2],"fa":{"go_terms":["goid"],"ec_numbers":["EC:1.2.3.4"],"interpro_entries":["IPR:000126"]}},
{"sequence":"AALLER","taxa":[2,1],"fa":{"go_terms":[],"ec_numbers":[],"interpro_entries":[]}}
]
}'

# get :pept2filtered, params: { peptides: %w[AAIER AAILER], taxa: %w[1 2 13 15], format: 'json' }
# end
get :pept2filtered, params: { peptides: %w[AAIER AALER AAILER AALLER], taxa: %w[1 2 13 14 15], format: 'json' }
end

private

Expand Down
18 changes: 18 additions & 0 deletions test/controllers/private_api/proteins_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ class PrivateApi::ProteinsControllerTest < ActionController::TestCase
get :proteins, params: { peptide: "AAAAAAAAA" }
end

test 'should get proteins too short sequence' do
@expected = '{
"name":"Sequence too short",
"message":"The peptide sequence you provided is too short. It should contain at least 5 valid amino acids."
}'

get :proteins, params: { peptide: "AAA" }
end

test 'should get proteins without peptides' do
@expected = '{
"name":"Invalid peptide provided",
"message":"No peptide sequence was provided. Please provide a valid peptide sequence."
}'

get :proteins, params: {}
end

private

def assert_success
Expand Down

0 comments on commit c9a8fb3

Please sign in to comment.