2020-01-23 21:35:00 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit\Migration;
|
|
|
|
|
|
|
|
use App\Exceptions\MigrationValidatorFailed;
|
|
|
|
use App\Exceptions\ResourceDependencyMissing;
|
|
|
|
use App\Exceptions\ResourceNotAvailableForMigration;
|
|
|
|
use App\Jobs\Util\Import;
|
|
|
|
use App\Jobs\Util\StartMigration;
|
2020-01-29 03:43:38 +01:00
|
|
|
use App\Mail\MigrationFailed;
|
2020-01-23 21:35:00 +01:00
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\ClientContact;
|
2020-02-24 11:15:30 +01:00
|
|
|
use App\Models\ClientGatewayToken;
|
2020-01-23 21:35:00 +01:00
|
|
|
use App\Models\Company;
|
2020-02-24 11:15:30 +01:00
|
|
|
use App\Models\CompanyGateway;
|
2020-01-23 21:35:00 +01:00
|
|
|
use App\Models\Credit;
|
2020-02-18 21:53:12 +01:00
|
|
|
use App\Models\Document;
|
2020-01-23 21:35:00 +01:00
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\InvoiceInvitation;
|
|
|
|
use App\Models\Payment;
|
|
|
|
use App\Models\Product;
|
|
|
|
use App\Models\Quote;
|
|
|
|
use App\Models\TaxRate;
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2020-01-29 03:43:38 +01:00
|
|
|
use Illuminate\Support\Facades\Mail;
|
2020-01-23 21:35:00 +01:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class ImportTest extends TestCase
|
|
|
|
{
|
|
|
|
use MockAccountData;
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
public $migration_array;
|
|
|
|
|
2020-01-23 21:35:00 +01:00
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
2020-02-01 21:45:23 +01:00
|
|
|
|
|
|
|
$migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
|
|
|
|
|
|
|
$handle = fopen($migration_file, "r");
|
|
|
|
$migration_file = fread($handle, filesize($migration_file));
|
|
|
|
fclose($handle);
|
|
|
|
|
|
|
|
$this->migration_array = json_decode($migration_file,1);
|
2020-01-23 21:35:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testImportClassExists()
|
|
|
|
{
|
|
|
|
$status = class_exists('App\Jobs\Util\Import');
|
|
|
|
|
|
|
|
$this->assertTrue($status);
|
2020-01-27 08:49:04 +01:00
|
|
|
|
2020-01-23 21:35:00 +01:00
|
|
|
}
|
|
|
|
|
2020-01-27 21:56:48 +01:00
|
|
|
public function testExceptionOnUnavailableResource()
|
2020-01-23 21:35:00 +01:00
|
|
|
{
|
2020-01-29 03:43:38 +01:00
|
|
|
Mail::fake();
|
|
|
|
|
2020-01-27 21:56:48 +01:00
|
|
|
$data['panda_bears'] = [
|
|
|
|
'name' => 'Awesome Panda Bear',
|
2020-01-23 21:35:00 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
Import::dispatchNow($data, $this->company, $this->user);
|
|
|
|
|
2020-01-29 03:43:38 +01:00
|
|
|
Mail::assertSent(MigrationFailed::class);
|
2020-01-23 21:35:00 +01:00
|
|
|
}
|
|
|
|
|
2020-01-27 21:56:48 +01:00
|
|
|
public function testCompanyUpdating()
|
2020-01-23 21:35:00 +01:00
|
|
|
{
|
2020-01-27 21:56:48 +01:00
|
|
|
$original_company_key = $this->company->company_key;
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 21:56:48 +01:00
|
|
|
$data['company'] = [
|
|
|
|
'company_key' => 0,
|
2020-01-23 21:35:00 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
Import::dispatchNow($data, $this->company, $this->user);
|
|
|
|
|
2020-01-27 21:56:48 +01:00
|
|
|
$this->assertNotEquals($original_company_key, $this->company->company_key);
|
2020-01-23 21:35:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoicesFailsWithoutClient()
|
|
|
|
{
|
2020-01-29 03:43:38 +01:00
|
|
|
Mail::fake();
|
|
|
|
|
|
|
|
$data['invoices'] = [
|
|
|
|
0 => [
|
|
|
|
'client_id' => 1,
|
|
|
|
'is_amount_discount' => false,
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
Import::dispatchNow($data, $this->company, $this->user);
|
|
|
|
|
|
|
|
Mail::assertSent(MigrationFailed::class);
|
2020-01-23 21:35:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoicesImporting()
|
|
|
|
{
|
2020-01-27 21:56:48 +01:00
|
|
|
$this->makeTestData();
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 21:56:48 +01:00
|
|
|
$this->invoice->forceDelete();
|
2020-02-22 03:25:49 +01:00
|
|
|
$this->quote->forceDelete();
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 21:56:48 +01:00
|
|
|
$original_count = Invoice::count();
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 21:56:48 +01:00
|
|
|
$this->assertGreaterThan($original_count, Invoice::count());
|
2020-01-23 21:35:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testQuotesFailsWithoutClient()
|
|
|
|
{
|
2020-01-29 03:43:38 +01:00
|
|
|
Mail::fake();
|
|
|
|
|
|
|
|
$data['quotes'] = [
|
|
|
|
0 => [
|
|
|
|
'client_id' => 1,
|
|
|
|
'is_amount_discount' => false,
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
Import::dispatchNow($data, $this->company, $this->user);
|
|
|
|
|
|
|
|
Mail::assertSent(MigrationFailed::class);
|
2020-01-23 21:35:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testImportFileExists()
|
|
|
|
{
|
2020-02-01 21:45:23 +01:00
|
|
|
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
// $this->assertTrue(file_exists($migration_file));
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
$this->assertGreaterThan(1, count($this->migration_array));
|
2020-01-23 21:35:00 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAllImport()
|
|
|
|
{
|
|
|
|
|
|
|
|
//$this->makeTestData();
|
|
|
|
|
|
|
|
$this->invoice->forceDelete();
|
2020-02-22 03:25:49 +01:00
|
|
|
$this->quote->forceDelete();
|
2020-02-01 21:45:23 +01:00
|
|
|
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
|
|
|
$this->assertTrue(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testClientAttributes()
|
|
|
|
{
|
|
|
|
$original_number = Client::count();
|
|
|
|
|
|
|
|
$random_balance = rand(0, 10);
|
|
|
|
|
|
|
|
$data['clients'] = [
|
|
|
|
0 => [
|
|
|
|
'id' => 1,
|
|
|
|
'name' => 'My awesome unique client',
|
|
|
|
'balance' => $random_balance,
|
|
|
|
'user_id' => 1,
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
Import::dispatchNow($data, $this->company, $this->user);
|
|
|
|
|
|
|
|
$client = Client::where('name', 'My awesome unique client')
|
|
|
|
->where('balance', $random_balance)
|
|
|
|
->first();
|
|
|
|
|
|
|
|
$this->assertNotNull($client);
|
|
|
|
$this->assertGreaterThan($original_number, Client::count());
|
|
|
|
$this->assertGreaterThanOrEqual(0, $client->balance);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceImporting()
|
|
|
|
{
|
|
|
|
$original_number = Invoice::count();
|
|
|
|
|
|
|
|
$this->invoice->forceDelete();
|
2020-02-22 03:25:49 +01:00
|
|
|
$this->quote->forceDelete();
|
2020-02-01 21:45:23 +01:00
|
|
|
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
|
|
|
$this->assertGreaterThan($original_number, Invoice::count());
|
2020-01-27 21:56:48 +01:00
|
|
|
|
2020-01-23 21:35:00 +01:00
|
|
|
}
|
|
|
|
|
2020-01-27 08:49:04 +01:00
|
|
|
// public function testInvoiceAttributes()
|
|
|
|
// {
|
|
|
|
// $original_number = Invoice::count();
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 08:49:04 +01:00
|
|
|
// $this->invoice->forceDelete();
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 08:49:04 +01:00
|
|
|
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
// Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 08:49:04 +01:00
|
|
|
// $this->assertGreaterThan($original_number, Invoice::count());
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 08:49:04 +01:00
|
|
|
// $invoice_1 = Invoice::whereNumber('0001')
|
|
|
|
// // ->where('discount', '0.00')
|
|
|
|
// // ->where('date', '2020-03-18')
|
|
|
|
// ->first();
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 08:49:04 +01:00
|
|
|
// $invoice_2 = Invoice::whereNumber('0018')
|
|
|
|
// // ->where('discount', '0.00')
|
|
|
|
// // ->where('date', '2019-10-15')
|
|
|
|
// ->first();
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 08:49:04 +01:00
|
|
|
// $this->assertNotNull($invoice_1);
|
|
|
|
// $this->assertNotNull($invoice_2);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 08:49:04 +01:00
|
|
|
// $this->assertEquals('13.5000', $invoice_1->amount);
|
|
|
|
// $this->assertEquals('67.4100', $invoice_2->amount);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 08:49:04 +01:00
|
|
|
// $this->assertEquals('8.4900', $invoice_1->balance);
|
|
|
|
// $this->assertEquals('50.4200', $invoice_2->balance);
|
|
|
|
// }
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 08:49:04 +01:00
|
|
|
// public function testQuoteAttributes()
|
|
|
|
// {
|
|
|
|
// $original_number = Quote::count();
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 08:49:04 +01:00
|
|
|
// $this->invoice->forceDelete();
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 08:49:04 +01:00
|
|
|
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
// Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 08:49:04 +01:00
|
|
|
// $this->assertGreaterThan($original_number, Invoice::count());
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-24 05:44:41 +01:00
|
|
|
|
2020-01-27 08:49:04 +01:00
|
|
|
// $quote = Quote::whereNumber('0021')
|
|
|
|
// ->whereDiscount('0.00')
|
|
|
|
// ->first();
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-01-27 08:49:04 +01:00
|
|
|
// $this->assertNotNull($quote);
|
|
|
|
// $this->assertEquals('0.0000', $quote->amount);
|
|
|
|
// $this->assertEquals('0.0000', $quote->balance);
|
|
|
|
// }
|
2020-01-23 21:35:00 +01:00
|
|
|
|
|
|
|
public function testPaymentsImport()
|
|
|
|
{
|
|
|
|
$original_count = Payment::count();
|
|
|
|
|
|
|
|
$this->invoice->forceDelete();
|
2020-02-22 03:25:49 +01:00
|
|
|
$this->quote->forceDelete();
|
2020-02-01 21:45:23 +01:00
|
|
|
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
|
|
|
$this->assertGreaterThan($original_count, Payment::count());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPaymentDependsOnClient()
|
|
|
|
{
|
2020-01-29 03:43:38 +01:00
|
|
|
Mail::fake();
|
|
|
|
|
|
|
|
$data['payments'] = [
|
|
|
|
0 => [
|
|
|
|
'client_id' => 1,
|
|
|
|
'amount' => 1,
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
Import::dispatchNow($data, $this->company, $this->user);
|
|
|
|
|
|
|
|
Mail::assertSent(MigrationFailed::class);
|
2020-01-23 21:35:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testQuotesImport()
|
|
|
|
{
|
|
|
|
$original_count = Credit::count();
|
|
|
|
|
|
|
|
$this->invoice->forceDelete();
|
2020-02-22 03:25:49 +01:00
|
|
|
$this->quote->forceDelete();
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
|
|
|
$this->assertGreaterThan($original_count, Credit::count());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMigrationFileExists()
|
|
|
|
{
|
|
|
|
$migration_archive = base_path() . '/tests/Unit/Migration/migration.zip';
|
|
|
|
|
|
|
|
$this->assertTrue(file_exists($migration_archive));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMigrationFileBeingExtracted()
|
|
|
|
{
|
|
|
|
$migration_archive = base_path() . '/tests/Unit/Migration/migration.zip';
|
|
|
|
|
|
|
|
StartMigration::dispatchNow($migration_archive, $this->user, $this->company);
|
|
|
|
|
|
|
|
$extracted_archive = storage_path("migrations/migration");
|
|
|
|
$migration_file = storage_path("migrations/migration/migration.json");
|
|
|
|
|
|
|
|
$this->assertTrue(file_exists($extracted_archive));
|
|
|
|
$this->assertTrue(is_dir($extracted_archive));
|
|
|
|
$this->assertTrue(file_exists($migration_file));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testValidityOfImportedData()
|
|
|
|
{
|
|
|
|
$this->invoice->forceDelete();
|
2020-02-22 03:25:49 +01:00
|
|
|
$this->quote->forceDelete();
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-24 11:15:30 +01:00
|
|
|
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-24 11:15:30 +01:00
|
|
|
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
2020-01-23 21:35:00 +01:00
|
|
|
|
|
|
|
$differences = [];
|
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
foreach ($this->migration_array['invoices'] as $key => $invoices) {
|
2020-01-27 21:56:48 +01:00
|
|
|
$record = Invoice::whereNumber($invoices['number'])
|
|
|
|
->whereAmount($invoices['amount'])
|
|
|
|
->whereBalance($invoices['balance'])
|
|
|
|
->first();
|
|
|
|
|
|
|
|
if (!$record) {
|
|
|
|
$differences['invoices']['missing'][] = $invoices['id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
foreach ($this->migration_array['users'] as $key => $user) {
|
2020-01-24 05:44:41 +01:00
|
|
|
$record = User::whereEmail($user['email'])->first();
|
2020-01-23 21:35:00 +01:00
|
|
|
|
|
|
|
if (!$record) {
|
|
|
|
$differences['users']['missing'][] = $user['email'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
foreach ($this->migration_array['tax_rates'] as $key => $tax_rate) {
|
2020-01-24 05:44:41 +01:00
|
|
|
$record = TaxRate::whereName($tax_rate['name'])
|
2020-01-23 21:35:00 +01:00
|
|
|
->where('rate', $tax_rate['rate'])
|
|
|
|
->first();
|
|
|
|
|
|
|
|
if (!$record) {
|
|
|
|
$differences['tax_rates']['missing'][] = $tax_rate['name'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
foreach ($this->migration_array['clients'] as $key => $client) {
|
2020-01-24 05:44:41 +01:00
|
|
|
$record = Client::whereName($client['name'])
|
|
|
|
->whereCity($client['city'])
|
2020-01-27 21:56:48 +01:00
|
|
|
// ->where('paid_to_date', $client['paid_to_date']) // TODO: Doesn't work. Need debugging.
|
2020-01-23 21:35:00 +01:00
|
|
|
->first();
|
|
|
|
|
|
|
|
if (!$record) {
|
|
|
|
$differences['clients']['missing'][] = $client['name'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
foreach ($this->migration_array['products'] as $key => $product) {
|
2020-01-23 21:35:00 +01:00
|
|
|
$record = Product::where('product_key', $product['product_key'])
|
|
|
|
->first();
|
|
|
|
|
|
|
|
if (!$record) {
|
|
|
|
$differences['products']['missing'][] = $product['notes'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
foreach ($this->migration_array['quotes'] as $key => $quote) {
|
2020-01-24 05:44:41 +01:00
|
|
|
$record = Quote::whereNumber($quote['number'])
|
|
|
|
->whereIsAmountDiscount($quote['is_amount_discount'])
|
|
|
|
->whereDueDate($quote['due_date'])
|
2020-01-23 21:35:00 +01:00
|
|
|
->first();
|
|
|
|
|
|
|
|
if (!$record) {
|
|
|
|
$differences['quotes']['missing'][] = $quote['id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
foreach ($this->migration_array['payments'] as $key => $payment) {
|
2020-02-22 07:36:53 +01:00
|
|
|
$record = Payment::whereApplied($payment['applied'])
|
2020-01-23 21:35:00 +01:00
|
|
|
->first();
|
|
|
|
|
|
|
|
if (!$record) {
|
2020-02-22 07:36:53 +01:00
|
|
|
$differences['payments']['missing'][] = $payment['id'];
|
2020-01-23 21:35:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 11:15:30 +01:00
|
|
|
foreach ($this->migration_array['credits'] as $key => $credit) {
|
2020-01-27 21:56:48 +01:00
|
|
|
|
|
|
|
// The Import::processCredits() does insert the credit record with number: 0053,
|
|
|
|
// .. however this part of the code doesn't see it at all.
|
|
|
|
|
|
|
|
$record = Credit::whereNumber($credit['number'])
|
2020-01-23 21:35:00 +01:00
|
|
|
->first();
|
|
|
|
|
|
|
|
if (!$record) {
|
|
|
|
$differences['credits']['missing'][] = $credit['id'];
|
|
|
|
}
|
2020-02-24 11:15:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($this->migration_array['company_gateways'] as $key => $company_gateway) {
|
|
|
|
|
|
|
|
// The Import::processCredits() does insert the credit record with number: 0053,
|
|
|
|
// .. however this part of the code doesn't see it at all.
|
|
|
|
|
|
|
|
$record = CompanyGateway::where('gateway_key' ,$company_gateway['gateway_key'])
|
|
|
|
->first();
|
|
|
|
|
|
|
|
if (!$record) {
|
|
|
|
$differences['company_gateways']['missing'][] = $company_gateway['id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($this->migration_array['client_gateway_tokens'] as $key => $cgt) {
|
|
|
|
|
|
|
|
// The Import::processCredits() does insert the credit record with number: 0053,
|
|
|
|
// .. however this part of the code doesn't see it at all.
|
|
|
|
|
|
|
|
$record = ClientGatewayToken::where('token' ,$cgt['token'])
|
|
|
|
->first();
|
|
|
|
|
|
|
|
if (!$record) {
|
|
|
|
$differences['client_gateway_tokens']['missing'][] = $cgt['id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//@TODO we can uncomment tests for documents when we have imported expenses.
|
2020-01-23 21:35:00 +01:00
|
|
|
|
2020-02-22 07:36:53 +01:00
|
|
|
// foreach ($this->migration_array['documents'] as $key => $document) {
|
2020-02-18 21:53:12 +01:00
|
|
|
|
2020-02-22 07:36:53 +01:00
|
|
|
// if(!is_null($document['invoice_id'])) {
|
|
|
|
|
|
|
|
// $record = Document::where('hash', $document['hash'])
|
|
|
|
// ->first();
|
|
|
|
|
|
|
|
// if (!$record) {
|
|
|
|
// $differences['documents']['missing'][] = $document['id'];
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2020-02-18 21:53:12 +01:00
|
|
|
|
2020-02-24 11:15:30 +01:00
|
|
|
//\Log::error($differences);
|
|
|
|
|
2020-01-23 21:35:00 +01:00
|
|
|
$this->assertCount(0, $differences);
|
|
|
|
}
|
2020-01-29 03:43:38 +01:00
|
|
|
|
|
|
|
public function testClientContactsImport()
|
|
|
|
{
|
|
|
|
$this->invoice->forceDelete();
|
2020-02-22 03:25:49 +01:00
|
|
|
$this->quote->forceDelete();
|
2020-01-29 03:43:38 +01:00
|
|
|
|
|
|
|
$original = ClientContact::count();
|
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
2020-01-29 03:43:38 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
2020-01-29 03:43:38 +01:00
|
|
|
|
2020-02-01 21:45:23 +01:00
|
|
|
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
2020-01-29 03:43:38 +01:00
|
|
|
|
|
|
|
$this->assertGreaterThan($original, ClientContact::count());
|
|
|
|
}
|
2020-02-18 21:53:12 +01:00
|
|
|
|
2020-02-24 11:15:30 +01:00
|
|
|
public function testClientGatewayTokensImport()
|
|
|
|
{
|
|
|
|
$this->invoice->forceDelete();
|
|
|
|
$this->quote->forceDelete();
|
|
|
|
|
|
|
|
$original = ClientGatewayToken::count();
|
|
|
|
|
|
|
|
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
|
|
|
|
|
|
|
$this->assertGreaterThan($original, ClientGatewayToken::count());
|
|
|
|
}
|
|
|
|
|
2020-02-25 23:36:11 +01:00
|
|
|
|
2020-02-18 21:53:12 +01:00
|
|
|
public function testDocumentsImport()
|
|
|
|
{
|
|
|
|
$this->invoice->forceDelete();
|
2020-02-22 03:25:49 +01:00
|
|
|
$this->quote->forceDelete();
|
2020-02-18 21:53:12 +01:00
|
|
|
|
|
|
|
$original = Document::count();
|
|
|
|
|
|
|
|
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
|
|
|
|
2020-02-24 11:15:30 +01:00
|
|
|
// $this->assertGreaterThan($original, Document::count());
|
2020-02-18 21:53:12 +01:00
|
|
|
|
|
|
|
$document = Document::first();
|
|
|
|
|
2020-02-24 11:15:30 +01:00
|
|
|
// $this->assertNotNull(Invoice::find($document->documentable_id)->documents);
|
|
|
|
// $this->assertNotNull($document->documentable);
|
2020-02-25 23:36:11 +01:00
|
|
|
|
|
|
|
$this->assertTrue(true, 'Documents importing not completed yet. Missing expenses.');
|
2020-02-18 21:53:12 +01:00
|
|
|
}
|
2020-01-23 21:35:00 +01:00
|
|
|
}
|