Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Sub/Queue/Jobs/SnsEventDispatcherJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public function fire()
'message delivery is disabled for your SQS subscription.', $this->job);
}

$this->release();

return;
}

Expand All @@ -30,6 +32,8 @@ public function fire()
'subject' => $this->snsSubject(),
]);
}

$this->delete();
}

/**
Expand Down
42 changes: 35 additions & 7 deletions tests/Sub/Queue/Jobs/SnsEventDispatcherJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function it_will_handle_empty_messages_with_a_subject()
}

/** @test */
public function it_will_not_handle_raw_notification_messages()
public function it_will_not_handle_raw_notification_messages_and_release_the_message_onto_the_queue()
{
Log::shouldReceive('error')->once()->with(
m::pattern('/^SqsSnsQueue: Invalid SNS payload/'),
Expand All @@ -122,32 +122,60 @@ public function it_will_not_handle_raw_notification_messages()

$this->mockedJobData = $this->mockedRawNotificationMessage()['Messages'][0];

$this->getJob()->fire();
$job = $this->getJob();
$job->shouldNotReceive('delete');
$job->shouldReceive('release')->once();

$job->fire();

Event::assertNothingDispatched();
}

/** @test */
public function it_will_not_handle_messages_where_the_event_name_to_trigger_cannot_be_resolved()
public function it_will_not_handle_messages_where_the_event_name_to_trigger_cannot_be_resolved_and_delete_the_message_from_the_queue()
{
$this->mockedJobData = $this->mockedRichNotificationMessage([
'TopicArn' => '',
'Subject' => '',
])['Messages'][0];

$this->getJob()->fire();
$job = $this->getJob();
$job->shouldReceive('delete')->once();
$job->shouldNotReceive('release');

$job->fire();

Event::assertNothingDispatched();
}

/** @test */
public function it_will_delete_the_message_from_the_queue_when_it_managed_to_dispatch_an_event()
{
$this->mockedJobData = $this->mockedRichNotificationMessage([
'TopicArn' => 'TopicArn:123456',
])['Messages'][0];

$job = $this->getJob();
$job->shouldReceive('delete')->once();

$job->fire();

Event::assertDispatched('TopicArn:123456');
}

/** @return SnsEventDispatcherJob|\Mockery\LegacyMockInterface */
protected function getJob()
{
return new SnsEventDispatcherJob(
$mock = m::mock(SnsEventDispatcherJob::class, [
$this->app,
m::mock(SqsClient::class),
$this->mockedJobData,
'connection-name',
'https://sqs.someregion.amazonaws.com/1234567891011/pubsub-events'
);
'https://sqs.someregion.amazonaws.com/1234567891011/pubsub-events',
])->makePartial();

$mock->shouldReceive('delete', 'release')->byDefault();

return $mock;
}
}