Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor tests to reduce code duplication

  • Loading branch information...
commit f9b1fbffa0bb7fb5846bd7089712edbfc5a08a5c 1 parent bcdfc3e
Ray Miller authored
Showing with 49 additions and 37 deletions.
  1. +49 −37 t/60-allele-request.t
View
86 t/60-allele-request.t
@@ -3,57 +3,69 @@
use strict;
use warnings FATAL => 'all';
-#use LIMS2::Test;
+use LIMS2::Test;
use Test::Most;
+use Const::Fast;
use LIMS2::AlleleRequestFactory;
-# XXX Naughty hack, we should really use LIMS2::Test
-{
- require LIMS2::Model;
-
- my $model;
-
- sub model {
- return $model ||= LIMS2::Model->new( { user => 'tasks' } );
+const my @TEST_DATA => (
+ {
+ allele_request => {
+ gene_id => 'MGI:1914632',
+ targeting_type => 'double_targeted',
+ first_allele_mutation_type => 'ko first',
+ first_allele_cassette_function => 'ko first',
+ second_allele_mutation_type => 'ko first',
+ second_allele_cassette_function => 'reporter only'
+ },
+ first_allele_designs => [ 34188 ],
+ first_allele_design_wells => [ '56_G04' ],
+ second_allele_designs => [ 34188 ],
+ second_allele_design_wells => [ '56_G04' ],
+ first_allele_vectors => [ 'MOHFAS0001_A_H02' ],
+ second_allele_vectors => [ 'MOHSAS0001_A_H02' ],
+ first_electorporations => [ 'FEP0006_A01' ],
+ second_electroporations => [ 'SEP0006_C01' ]
}
-}
+);
-ok my $arf = LIMS2::AlleleRequestFactory->new( model => model(), species => 'Mouse' ),
+ok my $factory = LIMS2::AlleleRequestFactory->new( model => model(), species => 'Mouse' ),
'create allele request factory';
-isa_ok $arf, 'LIMS2::AlleleRequestFactory';
+isa_ok $factory, 'LIMS2::AlleleRequestFactory';
-throws_ok { $arf->allele_request() }
+throws_ok { $factory->allele_request() }
qr/\Qallele_request() requires targeting_type\E/, 'allele_request requires targeting_type';
-ok my $ar = $arf->allele_request(
- gene_id => 'MGI:1343161',
- targeting_type => 'double_targeted',
- first_allele_mutation_type => 'ko first',
- first_allele_cassette_function => 'ko first',
- second_allele_mutation_type => 'ko first',
- second_allele_cassette_function => 'reporter only'
-), 'constructor succeeds';
-
-my $first_allele_designs;
-lives_ok { $first_allele_designs = $ar->first_allele_designs } 'first_allele_designs succeeds';
-cmp_bag [ map { $_->id } @{$first_allele_designs} ], [ 76 ], 'first_allele_designs returns expected result';
-
-my $second_allele_designs;
-lives_ok { $second_allele_designs = $ar->second_allele_designs } 'second_allele_designs succeeds';
-cmp_bag [ map { $_->id } @{$second_allele_designs} ], [ 76 ], 'second_allele_designs returns expected result';
+for my $test_data ( @TEST_DATA ) {
+ run_allele_request_test( $factory, $test_data );
+}
-my $first_allele_design_wells;
-lives_ok { $first_allele_design_wells = $ar->first_allele_design_wells } 'first_allele_design_wells succeeds';
-cmp_bag [ map { $_->as_string } @{$first_allele_design_wells} ], [ '4_C04', '34_C04' ], 'first_allele_design_wells returns the expected result';
+done_testing;
-my $second_allele_design_wells;
-lives_ok { $second_allele_design_wells = $ar->second_allele_design_wells } 'second_allele_design_wells succeeds';
-cmp_bag [ map { $_->as_string } @{$second_allele_design_wells} ], [ '4_C04', '34_C04' ], 'second_allele_design_wells returns the expected result';
+sub run_allele_request_test {
+ my ( $factory, $test_data ) = @_;
-
+ ok my $ar = $factory->allele_request( $test_data->{allele_request} ),
+ 'allele_request succeeds';
+ for my $method (
+ qw( first_allele_designs second_allele_designs
+ first_allele_design_wells second_allele_design_wells
+ first_allele_vectors second_allele_vectors
+ first_electroporations second_electroporations
+ ) ) {
+ check_lives_and_cmp_bag( $ar, $test_data, $method );
+ }
+}
+sub check_lives_and_cmp_bag {
+ my ( $ar, $test_data, $method ) = @_;
+ return unless exists $test_data->{$method};
-done_testing();
+ my $result;
+ lives_ok { $result = $ar->$method() } "$method succeeds";
+ cmp_bag [ map { $_->as_string } @{$result} ], $test_data->{$method},
+ "$method returns the expected result";
+}
Please sign in to comment.
Something went wrong with that request. Please try again.