Fix exception handling by the NotifyAboutLowStock workflow activity. Fixes bug #11343.
This commit is contained in:
parent
be7cd328cf
commit
47276ce4ad
3 changed files with 80 additions and 13 deletions
|
|
@ -20,9 +20,10 @@ use WebGUI::Inbox;
|
|||
|
||||
use Data::Dumper;
|
||||
use Test::More;
|
||||
use Test::Exception;
|
||||
use URI;
|
||||
|
||||
plan tests => 15; # increment this value for each test you create
|
||||
plan tests => 20; # increment this value for each test you create
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
$session->user({userId => 3});
|
||||
|
|
@ -35,7 +36,7 @@ my $posters = $import->addChild({
|
|||
className => 'WebGUI::Asset::Sku::Product',
|
||||
url => 'cell_posters',
|
||||
title => "Red's Posters",
|
||||
}, undef, undef, { skipAutoCommitWorkflows => 1, });
|
||||
}, undef, time()-15, { skipAutoCommitWorkflows => 1, });
|
||||
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
$versionTag->commit();
|
||||
|
|
@ -67,7 +68,7 @@ my $marilynVarId = $posters->setCollateral('variantsJSON', 'variantId', 'new',
|
|||
varSku => 'subway-skirt',
|
||||
price => 50,
|
||||
weight => 1,
|
||||
quantity => 5,
|
||||
quantity => 10,
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -83,8 +84,8 @@ addToCleanup($workflow);
|
|||
my $threshold = $workflow->addActivity('WebGUI::Workflow::Activity::NotifyAboutLowStock');
|
||||
$threshold->set('className' , 'WebGUI::Activity::NotifyAboutLowStock');
|
||||
$threshold->set('toGroup' , 3);
|
||||
$threshold->set('subject' , 'Threshold=10');
|
||||
$threshold->set('warningLimit' , 10);
|
||||
$threshold->set('subject' , 'Threshold=15');
|
||||
$threshold->set('warningLimit' , 15);
|
||||
|
||||
my $instance1 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
|
|
@ -109,7 +110,7 @@ is(scalar @{$messages}, 1, 'Received one message');
|
|||
my $message = $messages->[0];
|
||||
|
||||
my $body = $message->get('message');
|
||||
is($message->get('subject'), 'Threshold=10', 'Message has the right subject');
|
||||
is($message->get('subject'), 'Threshold=15', 'Message has the right subject');
|
||||
my @urls = split /\n/, $body;
|
||||
is (scalar @urls, 1, 'Only one variant is below the threshold');
|
||||
my $url = pop @urls;
|
||||
|
|
@ -140,14 +141,72 @@ is(scalar @{$inbox->getMessagesForUser($admin)}, 0, 'No messages sent since thre
|
|||
|
||||
$message = $inbox->getMessagesForUser($admin)->[0];
|
||||
|
||||
note "Test that the workflow does not die when encountering bad assets";
|
||||
|
||||
my $otherPosters = $posters->duplicate;
|
||||
my $movie_posters = $import->addChild({
|
||||
className => 'WebGUI::Asset::Sku::Product',
|
||||
url => 'movie_posters',
|
||||
title => "Movie Posters",
|
||||
}, undef, undef, { skipAutoCommitWorkflows => 1, });
|
||||
|
||||
my $movieVarId = $movie_posters->setCollateral('variantsJSON', 'variantId', 'new',
|
||||
{
|
||||
shortdesc => 'Shawshank Redemption',
|
||||
varSku => 'shawshank-1',
|
||||
price => 10,
|
||||
weight => 1,
|
||||
quantity => 5,
|
||||
},
|
||||
);
|
||||
my $otherTag = WebGUI::VersionTag->getWorking($session);
|
||||
addToCleanup($otherTag);
|
||||
$otherTag->commit;
|
||||
|
||||
$threshold->set('warningLimit' , 10);
|
||||
my $instance3 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
|
||||
$retVal = $instance3->run();
|
||||
$retVal = $instance3->run();
|
||||
is($retVal, 'done', 'Workflow is done');
|
||||
|
||||
$messages = $inbox->getMessagesForUser($admin);
|
||||
is(scalar @{$messages}, 1, 'Received one message');
|
||||
wipeMessages($inbox, $admin);
|
||||
|
||||
my $instance4 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
#break the asset
|
||||
$session->db->write('delete from asset where assetId=?', [$otherPosters->getId]);
|
||||
is(WebGUI::Asset->new($session, $otherPosters->getId), undef, 'middle asset broken');
|
||||
|
||||
$retVal = $instance4->run();
|
||||
$retVal = $instance4->run();
|
||||
is($retVal, 'done', 'Workflow is done');
|
||||
|
||||
$messages = $inbox->getMessagesForUser($admin);
|
||||
is(scalar @{$messages}, 1, 'Still received one message');
|
||||
wipeMessages($inbox, $admin);
|
||||
|
||||
END {
|
||||
$workflow->delete;
|
||||
$posters->purge;
|
||||
my $i = 0;
|
||||
wipeMessages($inbox, $admin);
|
||||
$messages = $inbox->getMessagesForUser($admin);
|
||||
is(scalar @{$messages}, 0, 'Inbox cleaned up');
|
||||
$session->db->write("delete from mailQueue where message like '%Threshold=10%'");
|
||||
$session->db->write("delete from mailQueue where message like '%Threshold=15%'");
|
||||
$session->db->write("delete from asset where assetId=?",[$otherPosters->getId]);
|
||||
$session->db->write("delete from assetData where assetId=?",[$otherPosters->getId]);
|
||||
$session->db->write("delete from sku where assetId=?",[$otherPosters->getId]);
|
||||
$session->db->write("delete from Product where assetId=?",[$otherPosters->getId]);
|
||||
$session->db->write("delete from assetIndex where assetId=?",[$otherPosters->getId]);
|
||||
}
|
||||
|
||||
sub wipeMessages {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue