Skip to content

Commit e16eac1

Browse files
committed
TEST: updated tests to include checking permissions
1 parent 846cd64 commit e16eac1

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

t/db/002_course_settings.t

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,12 @@ for my $setting (@$global_settings) {
182182
local $YAML::XS::Boolean = "JSON::PP";
183183
my $global_settings_from_file = LoadFile("$main::ww3_dir/conf/course_settings.yml");
184184

185-
is_deeply($global_settings, $global_settings_from_file, 'default settings: db values are the same as the file values.');
185+
# sort each of these for comparison
186+
my @global_settings = sort { $a->{setting_name} cmp $b->{setting_name} } @$global_settings;
187+
my @global_settings_from_file = sort { $a->{setting_name} cmp $b->{setting_name} } @$global_settings_from_file;
188+
189+
is_deeply(\@global_settings, \@global_settings_from_file,
190+
'default settings: db values are the same as the file values.');
186191

187192
# Make sure all of the default settings are valid
188193
for my $setting (@$global_settings) {

t/mojolicious/015_course_settings.t

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use lib "$main::ww3_dir/t/lib";
2020
use Clone qw/clone/;
2121
use YAML::XS qw/LoadFile/;
2222
use List::MoreUtils qw/firstval/;
23+
use Mojo::JSON qw/true false/;
2324

2425
use TestUtils qw/loadCSV removeIDs/;
2526

@@ -33,10 +34,10 @@ my $config = clone(LoadFile($config_file));
3334

3435
my $t = Test::Mojo->new(WeBWorK3 => $config);
3536

36-
# Authenticate with the admin user.
37-
$t->post_ok('/webwork3/api/login' => json => { username => 'admin', password => 'admin' })->status_is(200)
38-
->content_type_is('application/json;charset=UTF-8')->json_is('/logged_in' => 1)->json_is('/user/user_id' => 1)
39-
->json_is('/user/is_admin' => 1);
37+
# Authenticate with an instructor.
38+
$t->post_ok('/webwork3/api/login' => json => { username => 'lisa', password => 'lisa' })->status_is(200)
39+
->content_type_is('application/json;charset=UTF-8')->json_is('/logged_in' => 1)
40+
->json_is('/user/username' => 'lisa')->json_is('/user/is_admin' => false);
4041

4142
# Load the global settings from the file
4243
my $global_settings_from_file = LoadFile("$main::ww3_dir/conf/course_settings.yml");
@@ -113,4 +114,29 @@ $t->post_ok('/webwork3/api/global-settings/check-timezone' => json => { timezone
113114
$t->post_ok('/webwork3/api/global-settings/check-timezone' => json => { timezone => 'Amrica/Chicago' })->status_is(200)
114115
->json_is('/valid_timezone' => false);
115116

117+
# Check to make sure that a student has appropriate access (ralph is a student in Arithmetic-course_id: 4)
118+
119+
$t->post_ok('/webwork3/api/logout')->status_is(200);
120+
$t->post_ok('/webwork3/api/login' => json => { username => 'ralph', password => 'ralph' })->status_is(200);
121+
122+
# A student should have access to the global settings;
123+
$t->get_ok('/webwork3/api/global-settings')->content_type_is('application/json;charset=UTF-8')->status_is(200);
124+
$t->get_ok('/webwork3/api/global-settings/1')->content_type_is('application/json;charset=UTF-8')->status_is(200);
125+
126+
# A student should also have access to the course setting overrides for a course they are enrolled in.
127+
$t->get_ok('/webwork3/api/courses/4/settings')->content_type_is('application/json;charset=UTF-8')->status_is(200);
128+
129+
# But not from a course they are not enrolled in
130+
$t->get_ok('/webwork3/api/courses/5/settings')->content_type_is('application/json;charset=UTF-8')->status_is(403);
131+
132+
# A student shouldn't be able to update a course setting
133+
$t->put_ok(
134+
"/webwork3/api/courses/4/settings/$reduced_scoring->{setting_id}" => json => {
135+
value => 0.5
136+
}
137+
)->status_is(403);
138+
139+
# Nor delete a course setting
140+
$t->delete_ok("/webwork3/api/courses/4/settings/$reduced_scoring->{setting_id}")->status_is(403);
141+
116142
done_testing;

0 commit comments

Comments
 (0)