user store tests
[scpubgit/App-EzPz.git] / t / users.t
diff --git a/t/users.t b/t/users.t
new file mode 100644 (file)
index 0000000..18cba49
--- /dev/null
+++ b/t/users.t
@@ -0,0 +1,61 @@
+use strictures 1;
+use Test::More;
+use App::EzPz::UserStore;
+use File::Temp qw(tempfile);
+
+my $us = App::EzPz::UserStore->new(htpasswd_file => (tempfile)[1]);
+
+my $mst = $us->add({ username => 'mst', password => 'boromir' });
+
+is($mst->username, 'mst', 'username ok');
+ok($mst->check_password('boromir'), 'right pw ok on user');
+ok(!$mst->check_password('gimli'), 'wrong pw not ok on user');
+
+ok($us->check_password('mst', 'boromir'), 'right pw ok on user store');
+ok(!$us->check_password('mst', 'gimli'), 'wrong pw not ok on user store');
+
+ok(!$us->check_password('genehack', 'boromir'), 'nonexistent user fails ok');
+
+my $mst_clone = $us->add({ username => 'an_mst_clone', password => 'dnatank' });
+
+is(
+  join(',', sort map $_->username, $us->all),
+  'an_mst_clone,mst',
+  'user list ok with 2 users'
+);
+
+$us->remove($mst_clone);
+
+is(
+  join(',', sort map $_->username, $us->all),
+  'mst',
+  'user list ok after delete'
+);
+
+is(
+  join(',', $mst->list_names), '',
+  'No lists yet'
+);
+
+$mst->add_list_name($_) for qw(list1 list2 list3);
+
+is(
+  join(',', $mst->list_names), 'list1,list2,list3',
+  'Three lists after add',
+);
+
+$mst->remove_list_name('list2');
+
+is(
+  join(',', $mst->list_names), 'list1,list3',
+  'Two lists after move',
+);
+
+$mst->add_list_name('list2');
+
+is(
+  join(',', $mst->list_names), 'list1,list3,list2',
+  'Re-add appends',
+);
+
+done_testing;