1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/tests/Integration/PostmarkWebhookTest.php

134 lines
4.1 KiB
PHP
Raw Normal View History

2022-01-16 04:11:48 +01:00
<?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
2022-01-16 04:11:48 +01:00
*/
2022-01-16 04:11:48 +01:00
namespace Tests\Integration;
use App\Jobs\PostMark\ProcessPostmarkWebhook;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\MockAccountData;
use Tests\TestCase;
/**
2024-09-16 13:13:55 +02:00
*
2022-01-16 04:11:48 +01:00
*/
class PostmarkWebhookTest extends TestCase
{
use MockAccountData;
use DatabaseTransactions;
2024-08-22 08:57:52 +02:00
protected function setUp(): void
2022-01-16 04:11:48 +01:00
{
parent::setUp();
2023-01-11 09:29:27 +01:00
if (! config('services.postmark.token')) {
2022-01-16 04:11:48 +01:00
$this->markTestSkipped('Postmark Secret Set');
}
2022-01-16 04:11:48 +01:00
$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',
2022-01-16 04:11:48 +01:00
'Tag' => $this->company->company_key,
'DeliveredAt' => '2021-02-21T16:34:52Z',
'Details' => 'Test delivery webhook details',
2022-01-16 04:11:48 +01:00
];
$response = $this->post('/api/v1/postmark_webhook', $data);
$response->assertStatus(403);
$response = $this->withHeaders([
2023-01-11 09:29:27 +01:00
'X-API-SECURITY' => config('services.postmark.token'),
2022-01-16 04:11:48 +01:00
])->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',
2022-01-16 04:11:48 +01:00
'Tag' => $this->company->company_key,
'DeliveredAt' => '2021-02-21T16:34:52Z',
'Details' => 'Test delivery webhook details',
2022-01-16 04:11:48 +01:00
]);
$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',
2022-01-16 04:11:48 +01:00
'Tag' => $this->company->company_key,
'DeliveredAt' => '2021-02-21T16:34:52Z',
'Details' => 'Test delivery webhook details',
2022-01-16 04:11:48 +01:00
];
$response = $this->post('/api/v1/postmark_webhook', $data);
$response->assertStatus(403);
$response = $this->withHeaders([
2023-01-11 09:29:27 +01:00
'X-API-SECURITY' => config('services.postmark.token'),
2022-01-16 04:11:48 +01:00
])->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',
2022-01-16 04:11:48 +01:00
'Tag' => $this->company->company_key,
'DeliveredAt' => '2021-02-21T16:34:52Z',
'Details' => 'Test delivery webhook details',
2022-01-16 04:11:48 +01:00
]);
$this->assertEquals('spam', $invitation->fresh()->email_status);
}
}