mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 21:34:35 -04:00
Tests for entity history
This commit is contained in:
parent
2f1968c899
commit
21f1469499
@ -30,9 +30,11 @@ class EmailHistoryController extends BaseController
|
|||||||
$data = SystemLog::where('client_id', $client->id)
|
$data = SystemLog::where('client_id', $client->id)
|
||||||
->where('category_id', SystemLog::CATEGORY_MAIL)
|
->where('category_id', SystemLog::CATEGORY_MAIL)
|
||||||
->orderBy('id', 'DESC')
|
->orderBy('id', 'DESC')
|
||||||
|
->cursor()
|
||||||
->map(function ($system_log) {
|
->map(function ($system_log) {
|
||||||
if($system_log->log['history'] ?? false) {
|
if($system_log->log['history'] ?? false) {
|
||||||
return json_decode($system_log->log['history'], true);
|
return $system_log->log['history'];
|
||||||
|
// return json_decode($system_log->log['history'], true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -54,9 +56,11 @@ class EmailHistoryController extends BaseController
|
|||||||
->where('category_id', SystemLog::CATEGORY_MAIL)
|
->where('category_id', SystemLog::CATEGORY_MAIL)
|
||||||
->whereJsonContains('log->history->entity_id', $this->encodePrimaryKey($request->entity_id))
|
->whereJsonContains('log->history->entity_id', $this->encodePrimaryKey($request->entity_id))
|
||||||
->orderBy('id', 'DESC')
|
->orderBy('id', 'DESC')
|
||||||
|
->cursor()
|
||||||
->map(function ($system_log) {
|
->map(function ($system_log) {
|
||||||
if($system_log->log['history'] ?? false) {
|
if($system_log->log['history'] ?? false) {
|
||||||
return json_decode($system_log->log['history'], true);
|
return $system_log->log['history'];
|
||||||
|
// return json_decode($system_log->log['history'], true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -11,14 +11,15 @@
|
|||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use Tests\TestCase;
|
||||||
|
use App\Models\SystemLog;
|
||||||
|
use Tests\MockAccountData;
|
||||||
use App\Jobs\Entity\EmailEntity;
|
use App\Jobs\Entity\EmailEntity;
|
||||||
use App\Utils\Traits\GeneratesCounter;
|
use App\Utils\Traits\GeneratesCounter;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
use Tests\MockAccountData;
|
|
||||||
use Tests\TestCase;
|
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
@ -46,6 +47,96 @@ class InvoiceEmailTest extends TestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testClientEmailHistory()
|
||||||
|
{
|
||||||
|
$system_log = new SystemLog();
|
||||||
|
$system_log->company_id = $this->company->id;
|
||||||
|
$system_log->client_id = $this->client->id;
|
||||||
|
$system_log->category_id = SystemLog::CATEGORY_MAIL;
|
||||||
|
$system_log->event_id = SystemLog::EVENT_MAIL_SEND;
|
||||||
|
$system_log->type_id = SystemLog::TYPE_WEBHOOK_RESPONSE;
|
||||||
|
$system_log->log = [
|
||||||
|
'history' => [
|
||||||
|
'entity_id' => $this->invoice->hashed_id,
|
||||||
|
'entity_type' => 'invoice',
|
||||||
|
'subject' => 'Invoice #1',
|
||||||
|
'events' => [
|
||||||
|
[
|
||||||
|
'recipient' => 'bob@gmail.com',
|
||||||
|
'status' => 'Delivered',
|
||||||
|
'delivery_message' => 'A message that was deliveryed',
|
||||||
|
'server' => 'email.mx.com',
|
||||||
|
'server_ip' => '127.0.0.1',
|
||||||
|
'date' => \Carbon\Carbon::parse('2023-10-10')->format('Y-m-d H:m:s') ?? '',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$system_log->save();
|
||||||
|
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/emails/clientHistory/'.$this->client->hashed_id);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$this->assertEquals('invoice', $arr[0]['entity_type']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEntityEmailHistory()
|
||||||
|
{
|
||||||
|
$system_log = new SystemLog();
|
||||||
|
$system_log->company_id = $this->company->id;
|
||||||
|
$system_log->client_id = $this->client->id;
|
||||||
|
$system_log->category_id = SystemLog::CATEGORY_MAIL;
|
||||||
|
$system_log->event_id = SystemLog::EVENT_MAIL_SEND;
|
||||||
|
$system_log->type_id = SystemLog::TYPE_WEBHOOK_RESPONSE;
|
||||||
|
$system_log->log = [
|
||||||
|
'history' => [
|
||||||
|
'entity_id' => $this->invoice->hashed_id,
|
||||||
|
'entity_type' => 'invoice',
|
||||||
|
'subject' => 'Invoice #1',
|
||||||
|
'events' => [
|
||||||
|
[
|
||||||
|
'recipient' => 'bob@gmail.com',
|
||||||
|
'status' => 'Delivered',
|
||||||
|
'delivery_message' => 'A message that was deliveryed',
|
||||||
|
'server' => 'email.mx.com',
|
||||||
|
'server_ip' => '127.0.0.1',
|
||||||
|
'date' => \Carbon\Carbon::parse('2023-10-10')->format('Y-m-d H:m:s') ?? '',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$system_log->save();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'entity' => 'invoice',
|
||||||
|
'entity_id' => $this->invoice->hashed_id,
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/emails/entityHistory/', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$this->assertEquals('invoice', $arr[0]['entity_type']);
|
||||||
|
$this->assertEquals($this->invoice->hashed_id, $arr[0]['entity_id']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testTemplateValidation()
|
public function testTemplateValidation()
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user