Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sethsandaru committed Mar 13, 2024
1 parent 4c1ac4a commit fbfa04d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Entities/InboxMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static function make(object $rawDbRecord): InboxMessage
{
$inboxMsg = new InboxMessage();
$inboxMsg->id = intval($rawDbRecord->id);
$inboxMsg->externalId = $rawDbRecord->externalId;
$inboxMsg->externalId = $rawDbRecord->external_id;
$inboxMsg->rawPayload = $rawDbRecord->payload ?: '{}';

return $inboxMsg;
Expand Down
26 changes: 26 additions & 0 deletions tests/Integration/Commands/InboxWorkCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ public function testCommandPullsTheOrderedMsgAndProcessThem()
// 4. validate
$this->assertSame(0, $code);
$this->assertStringContainsString('Processed 3 inbox messages', $result);

$this->assertStringContainsString('Handling message with externalId: "evt_1NWX0RBGIr5C5v4TpncL2sCf"', $result);
$this->assertStringContainsString('Handled message with externalId: "evt_1NWX0RBGIr5C5v4TpncL2sCf"', $result);

$this->assertStringContainsString('Handling message with externalId: "evt_1NWUFiBGIr5C5v4TptQhGyW3"', $result);
$this->assertStringContainsString('Handled message with externalId: "evt_1NWUFiBGIr5C5v4TptQhGyW3"', $result);

$this->assertStringContainsString('Handling message with externalId: "evt_1Nh2fp2eZvKYlo2CzbNockEM"', $result);
$this->assertStringContainsString('Handled message with externalId: "evt_1Nh2fp2eZvKYlo2CzbNockEM"', $result);

$this->assertStringContainsString('[Info] No message found. Stopping...', $result);

Event::assertDispatched(
Expand Down Expand Up @@ -135,6 +145,22 @@ public function testCommandThrowsErrorWhenFailedToProcessAMessage()
'topic' => 'with_err_msg',
]);
}

public function testCommandStopsAfterAnAmountOfTime()
{
$beginAt = time();

$code = Artisan::call('inbox:work test --max-processing-time=10');
$result = Artisan::output();

$finishedAt = time();

$this->assertSame(0, $code);

$this->assertStringContainsString('[Info] Reached max processing time. Closing the process.', $result);

$this->assertGreaterThanOrEqual(10, $finishedAt - $beginAt);
}
}

class InvoicePaymentSucceedEvent
Expand Down

0 comments on commit fbfa04d

Please sign in to comment.