Adapt AddressBook tests for new AddressBook code.
This commit is contained in:
parent
1878898d9f
commit
b537bfae6b
1 changed files with 17 additions and 14 deletions
|
|
@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
plan tests => 24;
|
plan tests => 26;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# put your tests here
|
# put your tests here
|
||||||
|
|
@ -103,7 +103,18 @@ cmp_deeply(
|
||||||
);
|
);
|
||||||
|
|
||||||
$session->user({userId => 1});
|
$session->user({userId => 1});
|
||||||
|
eval { $book = WebGUI::Shop::AddressBook->create($session); };
|
||||||
|
$e = Exception::Class->caught();
|
||||||
|
isa_ok($e, 'WebGUI::Error::InvalidParam', 'create takes exception to making an address book for Visitor');
|
||||||
|
cmp_deeply(
|
||||||
|
$e,
|
||||||
|
methods(
|
||||||
|
error => 'Visitor cannot have an address book.',
|
||||||
|
),
|
||||||
|
'... correct error message',
|
||||||
|
);
|
||||||
|
|
||||||
|
$session->user({userId => 3});
|
||||||
$book = WebGUI::Shop::AddressBook->create($session);
|
$book = WebGUI::Shop::AddressBook->create($session);
|
||||||
isa_ok($book, 'WebGUI::Shop::AddressBook', 'create returns the right kind of object');
|
isa_ok($book, 'WebGUI::Shop::AddressBook', 'create returns the right kind of object');
|
||||||
|
|
||||||
|
|
@ -113,7 +124,7 @@ is($session->getId, $book->session->getId, 'session method returns OUR session o
|
||||||
|
|
||||||
ok($session->id->valid($book->getId), 'create makes a valid GUID style addressBookId');
|
ok($session->id->valid($book->getId), 'create makes a valid GUID style addressBookId');
|
||||||
|
|
||||||
is($book->get('userId'), 1, 'create uses $session->user to get the userid for this book');
|
is($book->get('userId'), 3, 'create uses $session->user to get the userid for this book');
|
||||||
|
|
||||||
my $bookCount = $session->db->quickScalar('select count(*) from addressBook');
|
my $bookCount = $session->db->quickScalar('select count(*) from addressBook');
|
||||||
is($bookCount, 1, 'only 1 address book was created');
|
is($bookCount, 1, 'only 1 address book was created');
|
||||||
|
|
@ -166,7 +177,6 @@ cmp_deeply(
|
||||||
$book->get(),
|
$book->get(),
|
||||||
{
|
{
|
||||||
userId => ignore(),
|
userId => ignore(),
|
||||||
sessionId => ignore(),
|
|
||||||
addressBookId => ignore(),
|
addressBookId => ignore(),
|
||||||
defaultAddressId => ignore(),
|
defaultAddressId => ignore(),
|
||||||
},
|
},
|
||||||
|
|
@ -203,7 +213,7 @@ undef $book;
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
#
|
#
|
||||||
# newBySession
|
# newByUserId
|
||||||
#
|
#
|
||||||
#######################################################################
|
#######################################################################
|
||||||
|
|
||||||
|
|
@ -213,22 +223,15 @@ my $mergeUser = WebGUI::User->create($otherSession);
|
||||||
WebGUI::Test->usersToDelete($mergeUser);
|
WebGUI::Test->usersToDelete($mergeUser);
|
||||||
$otherSession->user({user => $mergeUser});
|
$otherSession->user({user => $mergeUser});
|
||||||
my $adminBook = WebGUI::Shop::AddressBook->create($otherSession);
|
my $adminBook = WebGUI::Shop::AddressBook->create($otherSession);
|
||||||
|
WebGUI::Test->addToCleanup($adminBook);
|
||||||
my $goodAddress = $adminBook->addAddress({label => 'first'});
|
my $goodAddress = $adminBook->addAddress({label => 'first'});
|
||||||
|
|
||||||
my $session2 = WebGUI::Test->newSession;
|
my $session2 = WebGUI::Test->newSession;
|
||||||
$session2->user({user => $mergeUser});
|
$session2->user({user => $mergeUser});
|
||||||
my $bookAdmin = WebGUI::Shop::AddressBook->newBySession($session2);
|
my $bookAdmin = WebGUI::Shop::AddressBook->newByUserId($session2);
|
||||||
|
|
||||||
cmp_bag(
|
cmp_bag(
|
||||||
[ map { $_->getId } @{ $bookAdmin->getAddresses } ],
|
[ map { $_->getId } @{ $bookAdmin->getAddresses } ],
|
||||||
[ $goodAddress->getId, ],
|
[ $goodAddress->getId, ],
|
||||||
'newBySession merges address books by userId'
|
'newByUserId works'
|
||||||
);
|
);
|
||||||
|
|
||||||
$adminBook->delete;
|
|
||||||
$bookAdmin->delete;
|
|
||||||
|
|
||||||
END {
|
|
||||||
$session->db->write('delete from addressBook');
|
|
||||||
$session->db->write('delete from address');
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue