1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Fixes for test refactoring

This commit is contained in:
David Bomba 2023-10-26 15:46:26 +11:00
parent da27d5bdb4
commit af1f809cfb
9 changed files with 324 additions and 181 deletions

View File

@ -71,8 +71,6 @@ class PaymentExport extends BaseExport
return ['identifier' => $key, 'display_value' => $headerdisplay[$value]];
})->toArray();
nlog($header);
$report = $query->cursor()
->map(function ($resource) {
$row = $this->buildRow($resource);

View File

@ -61,14 +61,17 @@ class ARSummaryReportController extends BaseController
*/
public function __invoke(GenericReportRequest $request)
{
/** @var \App\Models\User $user */
$user = auth()->user();
if ($request->has('send_email') && $request->get('send_email')) {
SendToAdmin::dispatch(auth()->user()->company(), $request->all(), ARSummaryReport::class, $this->filename);
SendToAdmin::dispatch($user->company(), $request->all(), ARSummaryReport::class, $this->filename);
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
$export = new ARSummaryReport(auth()->user()->company(), $request->all());
$export = new ARSummaryReport($user->company(), $request->all());
$csv = $export->run();

View File

@ -71,28 +71,12 @@ class CreditReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), CreditExport::class, $hash);
PreviewReport::dispatch($user->company(), $request->all(), CreditExport::class, $hash);
return response()->json(['message' => $hash], 200);
return response()->json(['message' => $hash], 200);
}
$export = new CreditExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -72,28 +72,12 @@ class DocumentReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), DocumentExport::class, $hash);
PreviewReport::dispatch($user->company(), $request->all(), DocumentExport::class, $hash);
return response()->json(['message' => $hash], 200);
return response()->json(['message' => $hash], 200);
}
$export = new DocumentExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -73,28 +73,12 @@ class ExpenseReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
// expect a list of visible fields, or use the default
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), ExpenseExport::class, $hash);
PreviewReport::dispatch($user->company(), $request->all(), ExpenseExport::class, $hash);
return response()->json(['message' => $hash], 200);
return response()->json(['message' => $hash], 200);
}
$export = new ExpenseExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -72,26 +72,11 @@ class InvoiceItemReportController extends BaseController
return response()->json(['message' => 'working...'], 200);
}
if($request->has('output') && $request->input('output') == 'json') {
$hash = \Illuminate\Support\Str::uuid();
$hash = \Illuminate\Support\Str::uuid();
PreviewReport::dispatch($user->company(), $request->all(), InvoiceItemExport::class, $hash);
PreviewReport::dispatch($user->company(), $request->all(), InvoiceItemExport::class, $hash);
return response()->json(['message' => $hash], 200);
return response()->json(['message' => $hash], 200);
}
$export = new InvoiceItemExport($user->company(), $request->all());
$csv = $export->run();
$headers = [
'Content-Disposition' => 'attachment',
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($csv) {
echo $csv;
}, $this->filename, $headers);
}
}

View File

@ -39,7 +39,7 @@ class PreviewReport implements ShouldQueue
/** @var \App\Export\CSV\CreditExport $export */
$export = new $this->report_class($this->company, $this->request);
if($this->request['output'] == 'json' ?? false)
if(isset($this->request['output']) && $this->request['output'] == 'json')
$report = $export->returnJson();
else
$report = $export->run();

View File

@ -89,6 +89,7 @@ use App\Http\Controllers\Auth\PasswordTimeoutController;
use App\Http\Controllers\PreviewPurchaseOrderController;
use App\Http\Controllers\Reports\ClientReportController;
use App\Http\Controllers\Reports\CreditReportController;
use App\Http\Controllers\Reports\ReportExportController;
use App\Http\Controllers\Reports\VendorReportController;
use App\Http\Controllers\Reports\ExpenseReportController;
use App\Http\Controllers\Reports\InvoiceReportController;
@ -322,7 +323,7 @@ Route::group(['middleware' => ['throttle:api', 'api_db', 'token_auth', 'locale']
Route::post('reports/tax_summary_report', TaxSummaryReportController::class);
Route::post('reports/user_sales_report', UserSalesReportController::class);
Route::post('reports/preview/{hash}', ReportPreviewController::class);
Route::post('exports/preview/{hash}', ReportPreviewController::class);
Route::post('exports/preview/{hash}', ReportExportController::class);
Route::post('templates/preview/{hash}', TemplatePreviewController::class);
Route::post('search', SearchController::class);

View File

@ -11,25 +11,26 @@
namespace Tests\Feature\Export;
use Tests\TestCase;
use App\Models\User;
use App\Models\Client;
use App\Models\Credit;
use League\Csv\Reader;
use App\Models\Account;
use App\Models\Company;
use App\Models\Expense;
use App\Models\Invoice;
use App\Models\CompanyToken;
use App\Models\ClientContact;
use App\Export\CSV\TaskExport;
use App\Utils\Traits\MakesHash;
use App\Export\CSV\VendorExport;
use App\Export\CSV\ProductExport;
use App\DataMapper\CompanySettings;
use App\Export\CSV\PaymentExport;
use App\Export\CSV\ProductExport;
use App\Export\CSV\TaskExport;
use App\Export\CSV\VendorExport;
use App\Factory\CompanyUserFactory;
use App\Models\Account;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\Company;
use App\Models\CompanyToken;
use App\Models\Credit;
use App\Models\Expense;
use App\Models\Invoice;
use App\Models\User;
use App\Utils\Traits\MakesHash;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Support\Facades\Http;
use League\Csv\Reader;
use Tests\TestCase;
/**
* @test
@ -113,7 +114,7 @@ class ReportCsvGenerationTest extends TestCase
"contact.custom_value4",
];
private $all_payment_report_keys = [
private $all_payment_report_keys = [
'payment.date',
'payment.amount',
'payment.refunded',
@ -275,9 +276,19 @@ class ReportCsvGenerationTest extends TestCase
}
private function poll($hash)
{
$response = Http::retry(20, 1000, throw: false)
->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post(config('ninja.app_url')."/api/v1/exports/preview/{$hash}");
return $response;
}
public function testVendorCsvGeneration()
{
$vendor =
\App\Models\Vendor::factory()->create(
[
@ -292,14 +303,13 @@ class ReportCsvGenerationTest extends TestCase
'private_notes' => 'private_notes',
'public_notes' => 'public_notes',
'website' => 'website',
'number' => '1234',
'number' => '1234',
]
);
$data = [
'date_range' => 'all',
'report_keys' => [],
// 'report_keys' => ["vendor.name","purchase_order.number","purchase_order.amount", "item.quantity", "item.cost", "item.line_total", "item.discount", "item.notes", "item.product_key", "item.custom_value1", "item.tax_name1", "item.tax_rate1",],
'send_email' => false,
];
@ -308,7 +318,15 @@ class ReportCsvGenerationTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/vendors', $data);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('Vendor 1', $this->getFirstValueByColumn($csv, 'Vendor Name'));
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Vendor Number'));
@ -334,8 +352,7 @@ class ReportCsvGenerationTest extends TestCase
$data = $export->returnJson();
$this->assertNotNull($data);
// nlog($data);
// $this->assertEquals(0, $this->traverseJson($data, 'columns.0.identifier'));
$this->assertEquals('Vendor Name', $this->traverseJson($data, 'columns.9.display_value'));
$this->assertEquals('vendor', $this->traverseJson($data, '0.0.entity'));
$this->assertEquals('address1', $this->traverseJson($data, '0.0.id'));
@ -345,7 +362,7 @@ class ReportCsvGenerationTest extends TestCase
$this->assertEquals('address1', $this->traverseJson($data, '0.0.display_value'));
}
public function testVendorCustomColumnCsvGeneration()
public function testVendorCustomColumnCsvGeneration()
{
\App\Models\Vendor::query()->cursor()->each(function ($t) {
@ -366,7 +383,7 @@ class ReportCsvGenerationTest extends TestCase
'private_notes' => 'private_notes',
'public_notes' => 'public_notes',
'website' => 'website',
'number' => '1234',
'number' => '1234',
]
);
@ -381,7 +398,16 @@ class ReportCsvGenerationTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/vendors', $data);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('Vendor 1', $this->getFirstValueByColumn($csv, 'Vendor Name'));
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Vendor Number'));
@ -405,7 +431,7 @@ class ReportCsvGenerationTest extends TestCase
}
public function testTaskCustomColumnsCsvGeneration()
public function testTaskCustomColumnsCsvGeneration()
{
$invoice = \App\Models\Invoice::factory()->create([
@ -463,7 +489,16 @@ class ReportCsvGenerationTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/tasks', $data);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals(3600, $this->getFirstValueByColumn($csv, 'Task Duration'));
$this->assertEquals('test1', $this->getFirstValueByColumn($csv, 'Task Description'));
@ -515,12 +550,19 @@ class ReportCsvGenerationTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/tasks', $data);
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
}
public function testTasksCsvGeneration()
{
@ -553,7 +595,15 @@ class ReportCsvGenerationTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/tasks', $data);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals(3600, $this->getFirstValueByColumn($csv, 'Task Duration'));
$this->assertEquals('test', $this->getFirstValueByColumn($csv, 'Task Description'));
@ -592,8 +642,17 @@ class ReportCsvGenerationTest extends TestCase
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/products', $data);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('product_key', $this->getFirstValueByColumn($csv, 'Product'));
$this->assertEquals('notes', $this->getFirstValueByColumn($csv, 'Notes'));
@ -602,7 +661,7 @@ class ReportCsvGenerationTest extends TestCase
$this->assertEquals('Custom 1', $this->getFirstValueByColumn($csv, 'Custom Value 1'));
$this->assertEquals('Custom 2', $this->getFirstValueByColumn($csv, 'Custom Value 2'));
$this->assertEquals('Custom 3', $this->getFirstValueByColumn($csv, 'Custom Value 3'));
$this->assertEquals('Custom 4', $this->getFirstValueByColumn($csv, 'Custom Value 4'));
$this->assertEquals('Custom 4', $this->getFirstValueByColumn($csv, 'Custom Value 4'));
$export = new ProductExport($this->company, $data);
$data = $export->returnJson();
@ -664,8 +723,17 @@ class ReportCsvGenerationTest extends TestCase
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/payments', $data);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals(100, $this->getFirstValueByColumn($csv, 'Payment Amount'));
$this->assertEquals(now()->addSeconds($this->company->timezone()->utc_offset)->format('Y-m-d'), $this->getFirstValueByColumn($csv, 'Payment Date'));
@ -712,7 +780,7 @@ class ReportCsvGenerationTest extends TestCase
$data = [
'date_range' => 'all',
'report_keys' => array_merge(["payment.amount","payment.date"],$this->all_invoice_report_keys),
'report_keys' => array_merge(["payment.amount","payment.date"], $this->all_invoice_report_keys),
'send_email' => false,
];
@ -721,6 +789,17 @@ class ReportCsvGenerationTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/payments', $data);
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
}
@ -746,8 +825,17 @@ class ReportCsvGenerationTest extends TestCase
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/payments', $data);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals(500, $this->getFirstValueByColumn($csv, 'Payment Amount'));
$this->assertEquals(0, $this->getFirstValueByColumn($csv, 'Payment Applied'));
@ -771,9 +859,17 @@ class ReportCsvGenerationTest extends TestCase
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/clients', $data);
$csv = $response->streamedContent();
// nlog($csv);
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$reader = Reader::createFromString($csv);
$reader->setHeaderOffset(0);
@ -802,8 +898,17 @@ class ReportCsvGenerationTest extends TestCase
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/clients', $data);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('bob', $this->getFirstValueByColumn($csv, 'Name'));
$this->assertEquals(100, $this->getFirstValueByColumn($csv, 'Balance'));
@ -848,8 +953,6 @@ class ReportCsvGenerationTest extends TestCase
$arr = $response->json();
// nlog($arr['message']);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
@ -857,16 +960,6 @@ class ReportCsvGenerationTest extends TestCase
$response->assertStatus(409);
// sleep(1);
// $response = $this->withHeaders([
// 'X-API-SECRET' => config('ninja.api_secret'),
// 'X-API-TOKEN' => $this->token,
// ])->postJson('/api/v1/reports/preview/'.$arr['message']);
// $response->assertStatus(200);
// nlog($response->json());
}
@ -899,7 +992,11 @@ class ReportCsvGenerationTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/credits', $data);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('bob', $this->getFirstValueByColumn($csv, 'Client Name'));
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Credit Credit Number'));
@ -917,6 +1014,11 @@ class ReportCsvGenerationTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/credits', $data)->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
}
public function testInvoiceCustomColumnsCsvGeneration()
@ -947,29 +1049,29 @@ class ReportCsvGenerationTest extends TestCase
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/invoices', $data);
$csv = $response->streamedContent();
// nlog($csv);
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('bob', $this->getFirstValueByColumn($csv, 'Client Name'));
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Invoice Invoice Number'));
$this->assertEquals('Unpaid', $this->getFirstValueByColumn($csv, 'Payment Amount'));
$this->assertEquals('', $this->getFirstValueByColumn($csv, 'Payment Date'));
$data = [
'date_range' => 'all',
'report_keys' => $this->all_client_report_keys,
'send_email' => false,
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/invoices', $data)->assertStatus(200);
$data = [
'date_range' => 'all',
'report_keys' => $this->all_payment_report_keys,
@ -981,7 +1083,6 @@ class ReportCsvGenerationTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/invoices', $data)->assertStatus(200);
}
public function testRecurringInvoiceCustomColumnsCsvGeneration()
@ -1013,14 +1114,17 @@ class ReportCsvGenerationTest extends TestCase
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/recurring_invoices', $data);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('bob', $this->getFirstValueByColumn($csv, 'Client Name'));
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Recurring Invoice Invoice Number'));
$this->assertEquals('Daily', $this->getFirstValueByColumn($csv, 'Recurring Invoice How Often'));
$data = [
'date_range' => 'all',
'report_keys' => $this->all_client_report_keys,
@ -1066,7 +1170,15 @@ class ReportCsvGenerationTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/recurring_invoices', $data);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Recurring Invoice Invoice Number'));
$this->assertEquals('Daily', $this->getFirstValueByColumn($csv, 'Recurring Invoice How Often'));
@ -1121,9 +1233,15 @@ class ReportCsvGenerationTest extends TestCase
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/invoice_items', $data);
$csv = $response->streamedContent();
// nlog($csv);//
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('bob', $this->getFirstValueByColumn($csv, 'Client Name'));
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Invoice Invoice Number'));
$this->assertEquals('Unpaid', $this->getFirstValueByColumn($csv, 'Payment Amount'));
@ -1215,7 +1333,16 @@ class ReportCsvGenerationTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/quote_items', $data);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('bob', $this->getFirstValueByColumn($csv, 'Client Name'));
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Quote Number'));
@ -1283,9 +1410,17 @@ class ReportCsvGenerationTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/purchase_orders', $data);
$response->assertStatus(200);
$csv = $response->streamedContent();
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('100', $this->getFirstValueByColumn($csv, 'Amount'));
$this->assertEquals('50', $this->getFirstValueByColumn($csv, 'Balance'));
@ -1355,7 +1490,16 @@ class ReportCsvGenerationTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/purchase_order_items', $data);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('Vendor 1', $this->getFirstValueByColumn($csv, 'Vendor Name'));
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Purchase Order Number'));
@ -1400,7 +1544,16 @@ class ReportCsvGenerationTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/quotes', $data);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('bob', $this->getFirstValueByColumn($csv, 'Client Name'));
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Quote Number'));
@ -1442,7 +1595,7 @@ class ReportCsvGenerationTest extends TestCase
'terms' => 'Terms',
]);
$invoice->service()->markPaid()->save();
$invoice->service()->markPaid()->save();
$data = [
'date_range' => 'all',
@ -1455,7 +1608,16 @@ class ReportCsvGenerationTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/invoices', $data);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('bob', $this->getFirstValueByColumn($csv, 'Client Name'));
$this->assertEquals('12345', $this->getFirstValueByColumn($csv, 'Invoice Invoice Number'));
@ -1478,8 +1640,17 @@ class ReportCsvGenerationTest extends TestCase
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/contacts', $data);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$reader = Reader::createFromString($csv);
$reader->setHeaderOffset(0);
@ -1549,7 +1720,16 @@ class ReportCsvGenerationTest extends TestCase
$response->assertStatus(200);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('100', $this->getFirstValueByColumn($csv, 'Credit Amount'));
$this->assertEquals('50', $this->getFirstValueByColumn($csv, 'Credit Balance'));
@ -1634,7 +1814,16 @@ class ReportCsvGenerationTest extends TestCase
$response->assertStatus(200);
$csv = $response->streamedContent();
$response->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('100', $this->getFirstValueByColumn($csv, 'Invoice Amount'));
$this->assertEquals('50', $this->getFirstValueByColumn($csv, 'Invoice Balance'));
@ -1709,7 +1898,14 @@ class ReportCsvGenerationTest extends TestCase
$response->assertStatus(200);
$csv = $response->streamedContent();
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('100', $this->getFirstValueByColumn($csv, 'Recurring Invoice Amount'));
$this->assertEquals('50', $this->getFirstValueByColumn($csv, 'Recurring Invoice Balance'));
@ -1785,9 +1981,13 @@ class ReportCsvGenerationTest extends TestCase
$response->assertStatus(200);
$csv = $response->streamedContent();
//nlog($csv);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('100', $this->getFirstValueByColumn($csv, 'Quote Amount'));
$this->assertEquals('50', $this->getFirstValueByColumn($csv, 'Quote Balance'));
@ -1824,7 +2024,7 @@ class ReportCsvGenerationTest extends TestCase
'client_id' => $this->client->id,
'amount' => 100,
'public_notes' => 'Public',
'private_notes' => 'Private',
'private_notes' => 'Private',
]);
$data = [
@ -1838,42 +2038,43 @@ class ReportCsvGenerationTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/expenses', $data);
$response->assertStatus(200);
$csv = $response->streamedContent();
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('100', $this->getFirstValueByColumn($csv, 'Expense Amount'));
$this->assertEquals('Public', $this->getFirstValueByColumn($csv, 'Expense Public Notes'));
$this->assertEquals('Private', $this->getFirstValueByColumn($csv, 'Expense Private Notes'));
$this->assertEquals($this->user->present()->name(), $this->getFirstValueByColumn($csv, 'Expense User'));
$data = [
'date_range' => 'all',
'report_keys' => $this->all_client_report_keys,
'send_email' => false,
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/reports/expenses', $data)->assertStatus(200);
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
}
public function testExpenseCustomColumnsCsvGeneration()
{
$vendor =
$vendor =
\App\Models\Vendor::factory()->create(
[
'user_id' => $this->user->id,
'company_id' => $this->company->id,
'name' => 'Vendor 1',
]
);
Expense::factory()->create([
@ -1883,8 +2084,8 @@ class ReportCsvGenerationTest extends TestCase
'vendor_id' => $vendor->id,
'amount' => 100,
'public_notes' => 'Public',
'private_notes' => 'Private',
'currency_id' => 1,
'private_notes' => 'Private',
'currency_id' => 1,
]);
$data = [
@ -1900,7 +2101,10 @@ class ReportCsvGenerationTest extends TestCase
$response->assertStatus(200);
$csv = $response->streamedContent();
$arr = $response->json();
$hash = $arr['message'];
$response = $this->poll($hash);
$csv = $response->body();
$this->assertEquals('bob', $this->getFirstValueByColumn($csv, 'Client Name'));
$this->assertEquals('Vendor 1', $this->getFirstValueByColumn($csv, 'Vendor Name'));
@ -1910,4 +2114,4 @@ class ReportCsvGenerationTest extends TestCase
}
}
}