diff options
Diffstat (limited to 't/script/createsuperuser.t')
-rw-r--r-- | t/script/createsuperuser.t | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/t/script/createsuperuser.t b/t/script/createsuperuser.t new file mode 100644 index 000000000..1d4826111 --- /dev/null +++ b/t/script/createsuperuser.t @@ -0,0 +1,23 @@ +use Test::More; +use Test::Output; + +use_ok 'FixMyStreet::Script::CreateSuperuser'; + +stderr_like { FixMyStreet::Script::CreateSuperuser::createsuperuser(); } + qr/Specify a single email address/, 'Email error shown'; +stderr_is { FixMyStreet::Script::CreateSuperuser::createsuperuser('test@example.org'); } + "Specify a password for this new user.\n", 'Password error shown'; +stdout_is { FixMyStreet::Script::CreateSuperuser::createsuperuser('test@example.org', 'password'); } + "test\@example.org is now a superuser.\n", 'Correct message shown'; + +my $user = FixMyStreet::DB->resultset("User")->find({ email => 'test@example.org' }); +ok $user, 'user created'; +is $user->is_superuser, 1, 'is a superuser'; + +$user->update({ is_superuser => 0 }); +stdout_is { FixMyStreet::Script::CreateSuperuser::createsuperuser('test@example.org'); } + "test\@example.org is now a superuser.\n", 'Correct message shown'; +$user->discard_changes; +is $user->is_superuser, 1, 'is a superuser again'; + +done_testing; |