1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/tests/Integration/PostmarkWebhookTest.php
Nikola Cirkovic c75b1d303f
Cirkovic/ina 16 fixes (#50)
* Dispatch | PdfCreatorTest | Removed deprecated method

* Dispatch | Remove deprecated dispatchNow() method and use dispatchSync or call handle() on class where return is mandatory.
2022-06-24 21:15:14 +10:00

135 lines
4.1 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace Tests\Integration;
use App\Jobs\PostMark\ProcessPostmarkWebhook;
use App\Models\Invoice;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
*/
class PostmarkWebhookTest extends TestCase
{
use MockAccountData;
use DatabaseTransactions;
protected function setUp() :void
{
parent::setUp();
if (! config('postmark.secret')) {
$this->markTestSkipped('Postmark Secret Set');
}
$this->makeTestData();
}
public function testDeliveryReport()
{
$invitation = $this->invoice->invitations->first();
$invitation->message_id = '00000000-0000-0000-0000-000000000000';
$invitation->save();
$data = [
'RecordType' => 'Delivery',
'ServerID' => '23',
'MessageStream' => 'outbound',
'MessageID' => '00000000-0000-0000-0000-000000000000',
'Recipient' => 'john@example.com',
'Tag' => $this->company->company_key,
'DeliveredAt' => '2021-02-21T16:34:52Z',
'Details' => 'Test delivery webhook details',
];
$response = $this->post('/api/v1/postmark_webhook', $data);
$response->assertStatus(403);
$response = $this->withHeaders([
'X-API-SECURITY' => config('postmark.secret'),
])->post('/api/v1/postmark_webhook', $data);
$response->assertStatus(200);
}
public function testDeliveryJob()
{
$invitation = $this->invoice->invitations->first();
$invitation->message_id = '00000000-0000-0000-0000-000000000000';
$invitation->save();
ProcessPostmarkWebhook::dispatchSync([
'RecordType' => 'Delivery',
'ServerID' => '23',
'MessageStream' => 'outbound',
'MessageID' => '00000000-0000-0000-0000-000000000000',
'Recipient' => 'john@example.com',
'Tag' => $this->company->company_key,
'DeliveredAt' => '2021-02-21T16:34:52Z',
'Details' => 'Test delivery webhook details',
]);
$this->assertEquals('delivered', $invitation->fresh()->email_status);
}
public function testSpamReport()
{
$invitation = $this->invoice->invitations->first();
$invitation->message_id = '00000000-0000-0000-0000-000000000001';
$invitation->save();
$data = [
'RecordType' => 'SpamComplaint',
'ServerID' => '23',
'MessageStream' => 'outbound',
'MessageID' => '00000000-0000-0000-0000-000000000001',
'Recipient' => 'john@example.com',
'Tag' => $this->company->company_key,
'DeliveredAt' => '2021-02-21T16:34:52Z',
'Details' => 'Test delivery webhook details',
];
$response = $this->post('/api/v1/postmark_webhook', $data);
$response->assertStatus(403);
$response = $this->withHeaders([
'X-API-SECURITY' => config('postmark.secret'),
])->post('/api/v1/postmark_webhook', $data);
$response->assertStatus(200);
}
public function testSpamJob()
{
$invitation = $this->invoice->invitations->first();
$invitation->message_id = '00000000-0000-0000-0000-000000000001';
$invitation->save();
ProcessPostmarkWebhook::dispatchSync([
'RecordType' => 'SpamComplaint',
'ServerID' => '23',
'MessageStream' => 'outbound',
'MessageID' => '00000000-0000-0000-0000-000000000001',
'From' => 'john@example.com',
'Tag' => $this->company->company_key,
'DeliveredAt' => '2021-02-21T16:34:52Z',
'Details' => 'Test delivery webhook details',
]);
$this->assertEquals('spam', $invitation->fresh()->email_status);
}
}