@@ -14,15 +14,13 @@ BEGIN {
1414use lib " $main::ww3_dir /lib" ;
1515use lib " $main::ww3_dir /t/lib" ;
1616
17- use Test::More;
18- use Test::Exception;
17+ use Test2::V0;
1918use YAML::XS qw/ LoadFile/ ;
20- use DateTime::Format::Strptime;
21- use Mojo::JSON qw/ true false/ ;
19+ use Mojo::JSON qw/ true/ ;
2220
2321use DB::Schema;
2422
25- use TestUtils qw/ loadCSV removeIDs loadSchema / ;
23+ use TestUtils qw/ loadCSV removeIDs/ ;
2624
2725# Load the database
2826my $config_file = " $main::ww3_dir /conf/webwork3-test.yml" ;
@@ -34,7 +32,6 @@ my $schema = DB::Schema->connect(
3432 $config -> {database_password },
3533 { quote_names => 1 }
3634);
37- my $strp = DateTime::Format::Strptime-> new(pattern => ' %F' , on_error => ' croak' );
3835
3936my $course_rs = $schema -> resultset(' Course' );
4037
@@ -56,56 +53,56 @@ my @courses_from_db = $course_rs->getCourses;
5653for my $course (@courses_from_db ) { removeIDs($course ); }
5754@courses_from_db = sortByCourseName(\@courses_from_db );
5855
59- is_deeply (\@courses_from_db , \@courses , ' getCourses: get all courses' );
56+ is (\@courses_from_db , \@courses , ' getCourses: get all courses' );
6057
61- # # Get a single course by name
58+ # Get a single course by name
6259my $course = $course_rs -> getCourse(info => { course_name => ' Calculus' });
6360
6461my $calc_id = $course -> {course_id };
6562delete $course -> {course_id };
6663my @calc_courses = grep { $_ -> {course_name } eq ' Calculus' } @courses ;
67- is_deeply ($course , $calc_courses [0], ' getCourse: get a single course by name' );
64+ is ($course , $calc_courses [0], ' getCourse: get a single course by name' );
6865
6966# Get a single course by course_id
7067$course = $course_rs -> getCourse(info => { course_id => $calc_id });
7168delete $course -> {course_id };
72- is_deeply ($course , $calc_courses [0], ' getCourse: get a single course by id' );
69+ is ($course , $calc_courses [0], ' getCourse: get a single course by id' );
7370
7471# Try to get a single course by sending proper info:
75- throws_ok {
76- $course_rs -> getCourse(info => { course_id => $calc_id , course_name => ' Calculus' });
77- }
78- ' DB::Exception::ParametersNeeded' , ' getCourse: sends too much info' ;
72+ is(
73+ dies { $course_rs -> getCourse(info => { course_id => $calc_id , course_name => ' Calculus' }); },
74+ check_isa(' DB::Exception::ParametersNeeded' ),
75+ ' getCourse: sends too much info'
76+ );
7977
80- throws_ok {
81- $course_rs -> getCourse(info => { name => ' Calculus' });
82- }
83- ' DB::Exception::ParametersNeeded' , ' getCourse: sends wrong info' ;
78+ is(
79+ dies { $course_rs -> getCourse(info => { name => ' Calculus' }); },
80+ check_isa(' DB::Exception::ParametersNeeded' ),
81+ ' getCourse: sends wrong info'
82+ );
8483
8584# Try to get a single course that doesn't exist
86- throws_ok {
87- $course_rs -> getCourse(info => { course_name => ' non_existent_course' });
88- }
89- ' DB::Exception::CourseNotFound' , ' getCourse: get a non-existent course' ;
85+ is(
86+ dies { $course_rs -> getCourse(info => { course_name => ' non_existent_course' }); },
87+ check_isa(' DB::Exception::CourseNotFound' ),
88+ ' getCourse: get a non-existent course'
89+ );
9090
9191# Add a course
92- my $new_course_params = {
93- course_name => ' Geometry' ,
94- visible => true,
95- course_dates => {}
96- };
92+ my $new_course_params = { course_name => ' Geometry' , visible => true, course_dates => {} };
9793
9894my $new_course = $course_rs -> addCourse(params => $new_course_params );
9995my $added_course_id = $new_course -> {course_id };
10096removeIDs($new_course );
10197
102- is_deeply( $new_course_params , $new_course , ' addCourse: add a new course' );
98+ is( $new_course , $new_course_params , ' addCourse: add a new course' );
10399
104100# Add a course that already exists
105- throws_ok {
106- $course_rs -> addCourse(params => { course_name => ' Geometry' , visible => 1 });
107- }
108- ' DB::Exception::CourseAlreadyExists' , ' addCourse: course already exists' ;
101+ is(
102+ dies { $course_rs -> addCourse(params => { course_name => ' Geometry' , visible => true }); },
103+ check_isa(' DB::Exception::CourseAlreadyExists' ),
104+ ' addCourse: course already exists'
105+ );
109106
110107# Update the course name
111108my $updated_course = $course_rs -> updateCourse(
@@ -116,36 +113,40 @@ my $updated_course = $course_rs->updateCourse(
116113$new_course_params -> {course_name } = ' Geometry II' ;
117114delete $updated_course -> {course_id };
118115
119- is_deeply( $new_course_params , $updated_course , ' updateCourse: update a course by name' );
116+ is( $updated_course , $new_course_params , ' updateCourse: update a course by name' );
120117
121118# Try to update an non-existent course
122- throws_ok {
123- $course_rs -> updateCourse(info => { course_name => ' non_existent_course' });
124- }
125- ' DB::Exception::CourseNotFound' , ' updateCourse: update a non-existent course_name' ;
119+ is(
120+ dies { $course_rs -> updateCourse(info => { course_name => ' non_existent_course' }); },
121+ check_isa(' DB::Exception::CourseNotFound' ),
122+ ' updateCourse: update a non-existent course_name'
123+ );
126124
127- throws_ok {
128- $course_rs -> updateCourse(info => { course_id => -9 }, params => $new_course_params );
129- }
130- ' DB::Exception::CourseNotFound' , ' updateCourse: update a non-existent course_id' ;
125+ is(
126+ dies { $course_rs -> updateCourse(info => { course_id => -9 }, params => $new_course_params ); },
127+ check_isa(' DB::Exception::CourseNotFound' ),
128+ ' updateCourse: update a non-existent course_id'
129+ );
131130
132131# Delete a course
133132my $deleted_course = $course_rs -> deleteCourse(info => { course_name => ' Geometry II' });
134133removeIDs($deleted_course );
135134
136- is_deeply( $new_course_params , $deleted_course , ' deleteCourse: delete a course' );
135+ is( $deleted_course , $new_course_params , ' deleteCourse: delete a course' );
137136
138137# Try to delete a non-existent course by name
139- throws_ok {
140- $course_rs -> deleteCourse(info => { course_name => ' undefined_name' })
141- }
142- ' DB::Exception::CourseNotFound' , ' deleteCourse: delete a non-existent course_name' ;
138+ is(
139+ dies { $course_rs -> deleteCourse(info => { course_name => ' undefined_name' }) },
140+ check_isa(' DB::Exception::CourseNotFound' ),
141+ ' deleteCourse: delete a non-existent course_name'
142+ );
143143
144144# Try to delete a non-existent course by id
145- throws_ok {
146- $course_rs -> deleteCourse(info => { course_id => -9 })
147- }
148- ' DB::Exception::CourseNotFound' , ' deleteCourse: delete a non-existent course_id' ;
145+ is(
146+ dies { $course_rs -> deleteCourse(info => { course_id => -9 }) },
147+ check_isa(' DB::Exception::CourseNotFound' ),
148+ ' deleteCourse: delete a non-existent course_id'
149+ );
149150
150151sub sortByCourseName {
151152 my $course_rs = shift ;
@@ -158,7 +159,6 @@ sub sortByCourseName {
158159for my $course (@courses_from_db ) { removeIDs($course ); }
159160@courses_from_db = sortByCourseName(\@courses_from_db );
160161
161- is_deeply (\@courses_from_db , \@courses , ' check: courses db table is returned to its original state.' );
162+ is (\@courses_from_db , \@courses , ' check: courses db table is returned to its original state.' );
162163
163164done_testing();
164-
0 commit comments