Skip to content

Commit 7374691

Browse files
authored
fix: undeleted messages (#74)
1 parent 465f800 commit 7374691

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

src/Sub/Queue/Jobs/SnsEventDispatcherJob.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public function fire()
2121
'message delivery is disabled for your SQS subscription.', $this->job);
2222
}
2323

24+
$this->release();
25+
2426
return;
2527
}
2628

@@ -30,6 +32,8 @@ public function fire()
3032
'subject' => $this->snsSubject(),
3133
]);
3234
}
35+
36+
$this->delete();
3337
}
3438

3539
/**

tests/Sub/Queue/Jobs/SnsEventDispatcherJobTest.php

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function it_will_handle_empty_messages_with_a_subject()
113113
}
114114

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

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

125-
$this->getJob()->fire();
125+
$job = $this->getJob();
126+
$job->shouldNotReceive('delete');
127+
$job->shouldReceive('release')->once();
128+
129+
$job->fire();
126130

127131
Event::assertNothingDispatched();
128132
}
129133

130134
/** @test */
131-
public function it_will_not_handle_messages_where_the_event_name_to_trigger_cannot_be_resolved()
135+
public function it_will_not_handle_messages_where_the_event_name_to_trigger_cannot_be_resolved_and_delete_the_message_from_the_queue()
132136
{
133137
$this->mockedJobData = $this->mockedRichNotificationMessage([
134138
'TopicArn' => '',
135139
'Subject' => '',
136140
])['Messages'][0];
137141

138-
$this->getJob()->fire();
142+
$job = $this->getJob();
143+
$job->shouldReceive('delete')->once();
144+
$job->shouldNotReceive('release');
145+
146+
$job->fire();
139147

140148
Event::assertNothingDispatched();
141149
}
142150

151+
/** @test */
152+
public function it_will_delete_the_message_from_the_queue_when_it_managed_to_dispatch_an_event()
153+
{
154+
$this->mockedJobData = $this->mockedRichNotificationMessage([
155+
'TopicArn' => 'TopicArn:123456',
156+
])['Messages'][0];
157+
158+
$job = $this->getJob();
159+
$job->shouldReceive('delete')->once();
160+
161+
$job->fire();
162+
163+
Event::assertDispatched('TopicArn:123456');
164+
}
165+
166+
/** @return SnsEventDispatcherJob|\Mockery\LegacyMockInterface */
143167
protected function getJob()
144168
{
145-
return new SnsEventDispatcherJob(
169+
$mock = m::mock(SnsEventDispatcherJob::class, [
146170
$this->app,
147171
m::mock(SqsClient::class),
148172
$this->mockedJobData,
149173
'connection-name',
150-
'https://sqs.someregion.amazonaws.com/1234567891011/pubsub-events'
151-
);
174+
'https://sqs.someregion.amazonaws.com/1234567891011/pubsub-events',
175+
])->makePartial();
176+
177+
$mock->shouldReceive('delete', 'release')->byDefault();
178+
179+
return $mock;
152180
}
153181
}

0 commit comments

Comments
 (0)